Service.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\cardservice\shop\controller;
  11. use addon\cardservice\model\ServiceGoods;
  12. use addon\form\model\Form;
  13. use app\model\goods\Goods as GoodsModel;
  14. use app\model\goods\GoodsBrand as GoodsBrandModel;
  15. use app\model\goods\GoodsService as GoodsServiceModel;
  16. use app\model\store\Store as StoreModel;
  17. use app\model\web\Config as ConfigModel;
  18. use app\shop\controller\BaseShop;
  19. /**
  20. * 虚拟商品
  21. * Class Virtualgoods
  22. * @package app\shop\controller
  23. */
  24. class Service extends BaseShop
  25. {
  26. protected $replace = [
  27. 'ADDON_CARDSERVICE_CSS' => __ROOT__ . '/addon/cardservice/shop/view/public/css',
  28. 'ADDON_CARDSERVICE_JS' => __ROOT__ . '/addon/cardservice/shop/view/public/js',
  29. 'ADDON_CARDSERVICE_IMG' => __ROOT__ . '/addon/cardservice/shop/view/public/img',
  30. ];
  31. /**
  32. * 添加商品
  33. * @return mixed
  34. */
  35. public function addGoods()
  36. {
  37. if (request()->isAjax()) {
  38. $category_id = input("category_id", 0);// 分类id
  39. $category_json = json_encode($category_id);//分类字符串
  40. $category_id = ',' . implode(',', $category_id) . ',';
  41. $data = [
  42. 'goods_name' => input("goods_name", ""),// 商品名称,
  43. 'goods_attr_class' => input("goods_attr_class", ""),// 商品类型id,
  44. 'goods_attr_name' => input("goods_attr_name", ""),// 商品类型名称,
  45. 'is_limit' => input("is_limit", "0"),// 商品是否限购,
  46. 'limit_type' => input("limit_type", "1"),// 商品限购类型,
  47. 'site_id' => $this->site_id,
  48. 'category_id' => $category_id,
  49. 'category_json' => $category_json,
  50. 'goods_image' => input("goods_image", ""),// 商品主图路径
  51. 'goods_content' => input("goods_content", ""),// 商品详情
  52. 'goods_state' => input("goods_state", ""),// 商品状态(1.正常0下架)
  53. 'price' => input("price", 0),// 商品价格(取第一个sku)
  54. 'market_price' => input("market_price", 0),// 市场价格(取第一个sku)
  55. 'cost_price' => input("cost_price", 0),// 成本价(取第一个sku)
  56. 'sku_no' => input("sku_no", ""),// 商品sku编码
  57. 'weight' => input("weight", ""),// 重量
  58. 'volume' => input("volume", ""),// 体积
  59. 'goods_stock' => input("goods_stock", 0),// 商品库存(总和)
  60. 'goods_stock_alarm' => input("goods_stock_alarm", 0),// 库存预警
  61. 'goods_spec_format' => input("goods_spec_format", ""),// 商品规格格式
  62. 'goods_attr_format' => input("goods_attr_format", ""),// 商品参数格式
  63. 'introduction' => input("introduction", ""),// 促销语
  64. 'keywords' => input("keywords", ""),// 关键词
  65. 'unit' => input("unit", ""),// 单位
  66. 'sort' => input("sort", 0),// 排序,
  67. 'video_url' => input("video_url", ""),// 视频
  68. 'goods_sku_data' => input("goods_sku_data", ""),// SKU商品数据
  69. 'goods_service_ids' => input("goods_service_ids", ''),// 商品服务id集合
  70. 'label_id' => input("label_id", ''),// 商品分组id
  71. 'brand_id' => input("brand_id", 0),//品牌id
  72. 'virtual_sale' => input("virtual_sale", 0),// 虚拟销量
  73. 'max_buy' => input("max_buy", 0),// 限购
  74. 'min_buy' => input("min_buy", 0),// 起售
  75. 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
  76. 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
  77. 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
  78. 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
  79. 'qr_id' => input('qr_id', 0),// 社群二维码id
  80. 'template_id' => input('template_id', 0), // 商品海报id
  81. 'sale_show' => input('sale_show', 0),//
  82. 'stock_show' => input('stock_show', 0),//
  83. 'market_price_show' => input('market_price_show', 0),//
  84. 'barrage_show' => input('barrage_show', 0),//
  85. 'form_id' => input('form_id', 0),
  86. 'sale_channel' => input('sale_channel', 'all'),
  87. 'sale_store' => input('sale_store', 'all'),
  88. 'is_unify_price' => input('is_unify_price', '1'),
  89. 'verify_validity_type' => input("verify_validity_type", 0),// 服务有效期类型
  90. ];
  91. if ($data[ 'verify_validity_type' ] == 1) {
  92. $data[ 'virtual_indate' ] = input("virtual_indate", 0);
  93. } else if ($data[ 'verify_validity_type' ] == 2) {
  94. $data[ 'virtual_indate' ] = strtotime(input("virtual_time", ''));
  95. }
  96. $service_goods_model = new ServiceGoods();
  97. $res = $service_goods_model->addGoods($data);
  98. return $res;
  99. } else {
  100. // 商品服务
  101. $goods_service_model = new GoodsServiceModel();
  102. $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
  103. $this->assign("service_list", $service_list);
  104. // 商品品牌
  105. $goods_brand_model = new GoodsBrandModel();
  106. $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], 'brand_id,brand_name', 'sort asc')[ 'data' ];
  107. $this->assign("brand_list", $brand_list);
  108. //商品默认排序值
  109. $config_model = new ConfigModel();
  110. $sort_config = $config_model->getGoodsSort($this->site_id);
  111. $sort_config = $sort_config[ 'data' ][ 'value' ];
  112. $this->assign("sort_config", $sort_config);
  113. //获取商品海报
  114. $poster_list = event('PosterTemplate', [ 'site_id' => $this->site_id ], true);
  115. if (!empty($poster_list)) {
  116. $poster_list = $poster_list[ 'data' ];
  117. }
  118. $this->assign('poster_list', $poster_list);
  119. $this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
  120. $form_is_exit = addon_is_exit('form', $this->site_id);
  121. if ($form_is_exit) {
  122. $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
  123. $this->assign('form_list', $form_list);
  124. }
  125. $this->assign('form_is_exit', $form_is_exit);
  126. $this->assign('all_goodsclass', event('GoodsClass'));
  127. $this->assign('goods_class', ( new ServiceGoods() )->getGoodsClass());
  128. $this->assign('store_is_exit', addon_is_exit('store', $this->site_id));
  129. return $this->fetch("service/add_goods", [], $this->replace);
  130. }
  131. }
  132. /**
  133. * 编辑商品
  134. * @return mixed
  135. */
  136. public function editGoods()
  137. {
  138. $service_goods_model = new ServiceGoods();
  139. if (request()->isAjax()) {
  140. $category_id = input("category_id", 0);// 分类id
  141. $category_json = json_encode($category_id);//分类字符串
  142. $category_id = ',' . implode(',', $category_id) . ',';
  143. $data = [
  144. 'goods_id' => input("goods_id", 0),// 商品id
  145. 'goods_name' => input("goods_name", ""),// 商品名称,
  146. 'goods_attr_class' => input("goods_attr_class", ""),// 商品类型id,
  147. 'goods_attr_name' => input("goods_attr_name", ""),// 商品类型名称,
  148. 'is_limit' => input("is_limit", "0"),// 商品是否限购,
  149. 'limit_type' => input("limit_type", "1"),// 商品限购类型,
  150. 'site_id' => $this->site_id,
  151. 'category_id' => $category_id,
  152. 'category_json' => $category_json,
  153. 'goods_image' => input("goods_image", ""),// 商品主图路径
  154. 'goods_content' => input("goods_content", ""),// 商品详情
  155. 'goods_state' => input("goods_state", ""),// 商品状态(1.正常0下架)
  156. 'price' => input("price", 0),// 商品价格(取第一个sku)
  157. 'market_price' => input("market_price", 0),// 市场价格(取第一个sku)
  158. 'cost_price' => input("cost_price", 0),// 成本价(取第一个sku)
  159. 'sku_no' => input("sku_no", ""),// 商品sku编码
  160. 'weight' => input("weight", ""),// 重量
  161. 'volume' => input("volume", ""),// 体积
  162. 'goods_stock' => input("goods_stock", 0),// 商品库存(总和)
  163. 'goods_stock_alarm' => input("goods_stock_alarm", 0),// 库存预警
  164. 'goods_spec_format' => input("goods_spec_format", ""),// 商品规格格式
  165. 'goods_attr_format' => input("goods_attr_format", ""),// 商品参数格式
  166. 'introduction' => input("introduction", ""),// 促销语
  167. 'keywords' => input("keywords", ""),// 关键词
  168. 'unit' => input("unit", ""),// 单位
  169. 'sort' => input("sort", 0),// 排序,
  170. 'video_url' => input("video_url", ""),// 视频
  171. 'goods_sku_data' => input("goods_sku_data", ""),// SKU商品数据
  172. 'goods_service_ids' => input("goods_service_ids", ''),// 商品服务id集合
  173. 'label_id' => input("label_id", ''),// 商品分组id
  174. 'brand_id' => input("brand_id", 0),//品牌id
  175. 'virtual_sale' => input("virtual_sale", 0),// 虚拟销量
  176. 'max_buy' => input("max_buy", 0),// 限购
  177. 'min_buy' => input("min_buy", 0),// 起售
  178. 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
  179. 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
  180. 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
  181. 'spec_type_status' => input('spec_type_status', 0),
  182. 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
  183. 'qr_id' => input('qr_id', 0),// 社群二维码id
  184. 'template_id' => input('template_id', 0), // 商品海报id
  185. 'sale_show' => input('sale_show', 0),//
  186. 'stock_show' => input('stock_show', 0),//
  187. 'market_price_show' => input('market_price_show', 0),//
  188. 'barrage_show' => input('barrage_show', 0),//
  189. 'form_id' => input('form_id', 0),
  190. 'sale_channel' => input('sale_channel', 'all'),
  191. 'sale_store' => input('sale_store', 'all'),
  192. 'is_unify_price' => input('is_unify_price', '1'),
  193. 'verify_validity_type' => input("verify_validity_type", 0)
  194. ];
  195. if ($data[ 'verify_validity_type' ] == 1) {
  196. $data[ 'virtual_indate' ] = input("virtual_indate", 0);
  197. } else if ($data[ 'verify_validity_type' ] == 2) {
  198. $data[ 'virtual_indate' ] = strtotime(input("virtual_time", ''));
  199. }
  200. $res = $service_goods_model->editGoods($data);
  201. return $res;
  202. } else {
  203. $goods_model = new GoodsModel();
  204. $goods_id = input("goods_id", 0);
  205. $goods_info = $service_goods_model->getGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], '*')[ 'data' ];
  206. if (empty($goods_info)) $this->error('未获取到商品信息');
  207. $goods_info[ 'service_category' ] = array_values(array_filter(explode(',', $goods_info[ 'service_category' ])));
  208. $goods_sku_list = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], "sku_id,sku_name,sku_no,sku_spec_format,price,market_price,cost_price,stock,virtual_indate,sku_image,sku_images,goods_spec_format,spec_name,stock_alarm,is_default,service_length", '')[ 'data' ];
  209. $goods_info[ 'sku_list' ] = $goods_sku_list;
  210. $this->assign("goods_info", $goods_info);
  211. // 商品服务
  212. $goods_service_model = new GoodsServiceModel();
  213. $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
  214. $this->assign("service_list", $service_list);
  215. // 商品品牌
  216. $goods_brand_model = new GoodsBrandModel();
  217. $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], 'brand_id,brand_name', 'sort asc')[ 'data' ];
  218. $this->assign("brand_list", $brand_list);
  219. //获取商品海报
  220. $poster_list = event('PosterTemplate', [ 'site_id' => $this->site_id ], true);
  221. if (!empty($poster_list)) {
  222. $poster_list = $poster_list[ 'data' ];
  223. }
  224. $this->assign('poster_list', $poster_list);
  225. $form_is_exit = addon_is_exit('form', $this->site_id);
  226. if ($form_is_exit) {
  227. $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
  228. $this->assign('form_list', $form_list);
  229. }
  230. $this->assign('form_is_exit', $form_is_exit);
  231. $store_is_exit = addon_is_exit('store', $this->site_id);
  232. if ($store_is_exit && $goods_info[ 'sale_store' ] != 'all') {
  233. $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ], [ 'store_id', 'in', $goods_info[ 'sale_store' ] ] ], 'store_id,store_name,status,address,full_address,is_frozen');
  234. $this->assign('store_list', $store_list[ 'data' ]);
  235. }
  236. $this->assign('store_is_exit', $store_is_exit);
  237. return $this->fetch("service/edit_goods", [], $this->replace);
  238. }
  239. }
  240. }