Goods.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\shopapi\controller;
  13. use app\model\express\ExpressTemplate as ExpressTemplateModel;
  14. use app\model\goods\Goods as GoodsModel;
  15. use app\model\goods\GoodsAttribute as GoodsAttributeModel;
  16. use app\model\goods\GoodsBrowse;
  17. use app\model\goods\GoodsCategory as GoodsCategoryModel;
  18. use app\model\goods\GoodsCollect;
  19. use app\model\goods\GoodsEvaluate as GoodsEvaluateModel;
  20. use app\model\web\Config as ConfigModel;
  21. /**
  22. * 实物商品
  23. * Class Goods
  24. * @package app\shop\controller
  25. */
  26. class Goods extends BaseApi
  27. {
  28. public function __construct()
  29. {
  30. //执行父类构造函数
  31. parent::__construct();
  32. $token = $this->checkToken();
  33. if ($token[ 'code' ] < 0) {
  34. echo $this->response($token);
  35. exit;
  36. }
  37. }
  38. /**
  39. * 商品条件
  40. * @return false|string
  41. */
  42. public function condition()
  43. {
  44. $data = [];
  45. // 营销活动
  46. $goods_promotion_type = event('GoodsPromotionType');
  47. $data[ 'goods_promotion_type' ] = $goods_promotion_type;
  48. return $this->response($this->success($data));
  49. }
  50. /**
  51. * 商品列表
  52. * @return mixed
  53. */
  54. public function lists()
  55. {
  56. $goods_model = new GoodsModel();
  57. $page_index = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  58. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  59. $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : '';
  60. $goods_state = isset($this->params[ 'goods_state' ]) ? $this->params[ 'goods_state' ] : '';
  61. $start_sale = isset($this->params[ 'start_sale' ]) ? $this->params[ 'start_sale' ] : 0;
  62. $end_sale = isset($this->params[ 'end_sale' ]) ? $this->params[ 'end_sale' ] : 0;
  63. $start_price = isset($this->params[ 'start_price' ]) ? $this->params[ 'start_price' ] : 0;
  64. $end_price = isset($this->params[ 'end_price' ]) ? $this->params[ 'end_price' ] : 0;
  65. $goods_shop_category_ids = isset($this->params[ 'goods_shop_category_ids' ]) ? $this->params[ 'goods_shop_category_ids' ] : '';
  66. $goods_class = isset($this->params[ 'goods_class' ]) ? $this->params[ 'goods_class' ] : '';
  67. $order = isset($this->params[ 'order' ]) ? $this->params[ 'order' ] : 'create_time';
  68. $sort = isset($this->params[ 'sort' ]) ? $this->params[ 'sort' ] : 'desc';
  69. $promotion_type = isset($this->params[ 'promotion_type' ]) ? $this->params[ 'promotion_type' ] : '';
  70. $stockalarm = $this->params[ 'stockalarm' ] ?? 0;
  71. $order_by = $order . ' ' . $sort;
  72. $condition = [ [ 'is_delete', '=', 0 ], [ 'site_id', '=', $this->site_id ] ];
  73. if (!empty($search_text)) {
  74. $condition[] = [ 'goods_name', 'like', '%' . $search_text . '%' ];
  75. }
  76. if ($goods_class !== "") {
  77. $condition[] = [ 'goods_class', '=', $goods_class ];
  78. }
  79. // 上架状态
  80. if ($goods_state !== '') {
  81. $condition[] = [ 'goods_state', '=', $goods_state ];
  82. }
  83. //参与活动
  84. if (!empty($promotion_type)) {
  85. $condition[] = [ 'promotion_addon', 'like', "%{$promotion_type}%" ];
  86. }
  87. // 查询库存预警的商品
  88. if ($stockalarm) {
  89. $stock_alarm = $goods_model->getGoodsStockAlarm($this->site_id);
  90. if (!empty($stock_alarm[ 'data' ])) $condition[] = [ 'goods_id', 'in', $stock_alarm[ 'data' ] ];
  91. else return $this->response($this->success([ 'page_count' => 1, 'count' => 0, 'list' => [] ]));
  92. }
  93. if (!empty($start_sale)) $condition[] = [ 'sale_num', '>=', $start_sale ];
  94. if (!empty($end_sale)) $condition[] = [ 'sale_num', '<=', $end_sale ];
  95. if (!empty($start_price)) $condition[] = [ 'price', '>=', $start_price ];
  96. if (!empty($end_price)) $condition[] = [ 'price', '<=', $end_price ];
  97. if (!empty($goods_shop_category_ids)) $condition[] = [ 'goods_shop_category_ids', 'like', [ $goods_shop_category_ids, '%' . $goods_shop_category_ids . ',%', '%' . $goods_shop_category_ids, '%,' . $goods_shop_category_ids . ',%' ], 'or' ];
  98. $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size, $order_by);
  99. if (!empty($res[ 'data' ][ 'list' ])) {
  100. $goods_promotion_type = event('GoodsPromotionType');
  101. foreach ($res[ 'data' ][ 'list' ] as $k => $v) {
  102. if (!empty($v[ 'promotion_addon' ])) {
  103. $v[ 'promotion_addon' ] = json_decode($v[ 'promotion_addon' ], true);
  104. foreach ($v[ 'promotion_addon' ] as $ck => $cv) {
  105. foreach ($goods_promotion_type as $gk => $gv) {
  106. if ($gv[ 'type' ] == $ck) {
  107. $res[ 'data' ][ 'list' ][ $k ][ 'promotion_addon_list' ][] = $gv;
  108. break;
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. return $this->response($res);
  116. }
  117. /**
  118. * 添加商品
  119. * @return mixed
  120. */
  121. public function addGoods()
  122. {
  123. $data = [
  124. 'goods_name' => isset($this->params[ 'goods_name' ]) ? $this->params[ 'goods_name' ] : '',// 商品名称,
  125. 'goods_attr_class' => isset($this->params[ 'goods_attr_class' ]) ? $this->params[ 'goods_attr_class' ] : '',// 商品类型id,
  126. 'goods_attr_name' => isset($this->params[ 'goods_attr_name' ]) ? $this->params[ 'goods_attr_name' ] : '',// 商品类型名称,
  127. 'site_id' => $this->site_id,
  128. 'category_id' => $this->params[ 'category_id' ] ?? '',
  129. 'category_json' => $this->params[ 'category_json' ] ?? '',
  130. 'goods_image' => isset($this->params[ 'goods_image' ]) ? $this->params[ 'goods_image' ] : '',// 商品主图路径
  131. 'goods_content' => isset($this->params[ 'goods_content' ]) ? $this->params[ 'goods_content' ] : '',// 商品详情
  132. 'goods_state' => isset($this->params[ 'goods_state' ]) ? $this->params[ 'goods_state' ] : '',// 商品状态(1.正常0下架)
  133. 'price' => isset($this->params[ 'price' ]) ? $this->params[ 'price' ] : 0,// 商品价格(取第一个sku)
  134. 'market_price' => isset($this->params[ 'market_price' ]) ? $this->params[ 'market_price' ] : '',// 市场价格(取第一个sku)
  135. 'cost_price' => isset($this->params[ 'cost_price' ]) ? $this->params[ 'cost_price' ] : 0,// 成本价(取第一个sku)
  136. 'sku_no' => isset($this->params[ 'sku_no' ]) ? $this->params[ 'sku_no' ] : '',// 商品sku编码
  137. 'weight' => isset($this->params[ 'weight' ]) ? $this->params[ 'weight' ] : '',// 重量
  138. 'volume' => isset($this->params[ 'volume' ]) ? $this->params[ 'volume' ] : '',// 体积
  139. 'goods_stock' => isset($this->params[ 'goods_stock' ]) ? $this->params[ 'goods_stock' ] : 0,// 商品库存(总和)
  140. 'goods_stock_alarm' => isset($this->params[ 'goods_stock_alarm' ]) ? $this->params[ 'goods_stock_alarm' ] : 0,// 库存预警
  141. 'is_free_shipping' => isset($this->params[ 'is_free_shipping' ]) ? $this->params[ 'is_free_shipping' ] : 1,// 是否免邮
  142. 'shipping_template' => isset($this->params[ 'shipping_template' ]) ? $this->params[ 'shipping_template' ] : 0,// 指定运费模板
  143. 'goods_spec_format' => isset($this->params[ 'goods_spec_format' ]) ? $this->params[ 'goods_spec_format' ] : '',// 商品规格格式
  144. 'goods_attr_format' => isset($this->params[ 'goods_attr_format' ]) ? $this->params[ 'goods_attr_format' ] : '',// 商品参数格式
  145. 'introduction' => isset($this->params[ 'introduction' ]) ? $this->params[ 'introduction' ] : '',// 促销语
  146. 'keywords' => isset($this->params[ 'keywords' ]) ? $this->params[ 'keywords' ] : '',// 关键词
  147. 'unit' => isset($this->params[ 'unit' ]) ? $this->params[ 'unit' ] : '',// 单位
  148. 'sort' => isset($this->params[ 'sort' ]) ? $this->params[ 'sort' ] : 0,// 排序,
  149. 'video_url' => isset($this->params[ 'video_url' ]) ? $this->params[ 'video_url' ] : '',// 视频
  150. 'goods_sku_data' => isset($this->params[ 'goods_sku_data' ]) ? $this->params[ 'goods_sku_data' ] : '',// SKU商品数据
  151. 'label_id' => isset($this->params[ 'label_id' ]) ? $this->params[ 'label_id' ] : '',// 商品分组id
  152. 'max_buy' => isset($this->params[ 'max_buy' ]) ? $this->params[ 'max_buy' ] : '',// 限购
  153. 'min_buy' => isset($this->params[ 'min_buy' ]) ? $this->params[ 'min_buy' ] : '',// 起售
  154. 'timer_on' => isset($this->params[ 'timer_on' ]) ? strtotime($this->params[ 'timer_on' ]) : 0,//定时上架
  155. 'timer_off' => isset($this->params[ 'timer_off' ]) ? strtotime($this->params[ 'timer_off' ]) : 0,//定时下架
  156. 'site_name' => $this->shop_info[ 'site_name' ],//店铺名
  157. 'virtual_sale' => $this->params[ 'virtual_sale' ] ?? 0,// 虚拟销量
  158. 'is_consume_discount' => $this->params[ 'is_consume_discount' ] ?? 0, //是否参与会员折扣
  159. 'goods_service_ids' => $this->params[ 'goods_service_ids' ] ?? '',// 商品服务id集合
  160. 'recommend_way' => $this->params[ 'recommend_way' ] ?? 0, // 推荐方式,1:新品,2:精品,3;推荐
  161. 'is_limit' => $this->params[ 'is_limit' ] ?? 0,// 商品是否限购,
  162. 'limit_type' => $this->params[ 'limit_type' ] ?? 1, // 商品限购类型,
  163. 'sale_show' => $this->params[ 'sale_show' ] ?? 0,
  164. 'stock_show' => $this->params[ 'stock_show' ] ?? 0,
  165. 'market_price_show' => $this->params[ 'market_price_show' ] ?? 0,
  166. 'barrage_show' => $this->params[ 'barrage_show' ] ?? 0,
  167. 'brand_id' => $this->params[ 'brand_id' ] ?? 0,
  168. 'support_trade_type' => $this->params[ 'support_trade_type' ] ?? '',
  169. 'form_id' => $this->params['goods_form'] ?? 0
  170. ];
  171. $goods_model = new GoodsModel();
  172. $res = $goods_model->addGoods($data);
  173. return $this->response($res);
  174. }
  175. /**
  176. * 编辑商品
  177. * @return mixed
  178. */
  179. public function editGoods()
  180. {
  181. $goods_model = new GoodsModel();
  182. $data = [
  183. 'goods_id' => isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0,// 商品id
  184. 'goods_name' => isset($this->params[ 'goods_name' ]) ? $this->params[ 'goods_name' ] : '',// 商品名称,
  185. 'goods_attr_class' => isset($this->params[ 'goods_attr_class' ]) ? $this->params[ 'goods_attr_class' ] : '',// 商品类型id,
  186. 'goods_attr_name' => isset($this->params[ 'goods_attr_name' ]) ? $this->params[ 'goods_attr_name' ] : '',// 商品类型名称,
  187. 'site_id' => $this->site_id,
  188. 'category_id' => $this->params[ 'category_id' ] ?? '',
  189. 'category_json' => $this->params[ 'category_json' ] ?? '',
  190. 'goods_image' => isset($this->params[ 'goods_image' ]) ? $this->params[ 'goods_image' ] : '',// 商品主图路径
  191. 'goods_content' => isset($this->params[ 'goods_content' ]) ? $this->params[ 'goods_content' ] : '',// 商品详情
  192. 'goods_state' => isset($this->params[ 'goods_state' ]) ? $this->params[ 'goods_state' ] : '',// 商品状态(1.正常0下架)
  193. 'price' => isset($this->params[ 'price' ]) ? $this->params[ 'price' ] : 0,// 商品价格(取第一个sku)
  194. 'market_price' => isset($this->params[ 'market_price' ]) ? $this->params[ 'market_price' ] : 0,// 市场价格(取第一个sku)
  195. 'cost_price' => isset($this->params[ 'cost_price' ]) ? $this->params[ 'cost_price' ] : 0,// 成本价(取第一个sku)
  196. 'sku_no' => isset($this->params[ 'sku_no' ]) ? $this->params[ 'sku_no' ] : '',// 商品sku编码
  197. 'weight' => isset($this->params[ 'weight' ]) ? $this->params[ 'weight' ] : '',// 重量
  198. 'volume' => isset($this->params[ 'volume' ]) ? $this->params[ 'volume' ] : '',// 体积
  199. 'goods_stock' => isset($this->params[ 'goods_stock' ]) ? $this->params[ 'goods_stock' ] : 0,// 商品库存(总和)
  200. 'goods_stock_alarm' => isset($this->params[ 'goods_stock_alarm' ]) ? $this->params[ 'goods_stock_alarm' ] : 0,// 库存预警
  201. 'is_free_shipping' => isset($this->params[ 'is_free_shipping' ]) ? $this->params[ 'is_free_shipping' ] : 1,// 是否免邮
  202. 'shipping_template' => isset($this->params[ 'shipping_template' ]) ? $this->params[ 'shipping_template' ] : 0,// 指定运费模板
  203. 'goods_spec_format' => isset($this->params[ 'goods_spec_format' ]) ? $this->params[ 'goods_spec_format' ] : '',// 商品规格格式
  204. 'goods_attr_format' => isset($this->params[ 'goods_attr_format' ]) ? $this->params[ 'goods_attr_format' ] : '',// 商品参数格式
  205. 'introduction' => isset($this->params[ 'introduction' ]) ? $this->params[ 'introduction' ] : '',// 促销语
  206. 'keywords' => isset($this->params[ 'keywords' ]) ? $this->params[ 'keywords' ] : '',// 关键词
  207. 'unit' => isset($this->params[ 'unit' ]) ? $this->params[ 'unit' ] : '',// 单位
  208. 'sort' => isset($this->params[ 'sort' ]) ? $this->params[ 'sort' ] : 0,// 排序,
  209. 'video_url' => isset($this->params[ 'video_url' ]) ? $this->params[ 'video_url' ] : '',// 视频
  210. 'goods_sku_data' => isset($this->params[ 'goods_sku_data' ]) ? $this->params[ 'goods_sku_data' ] : '',// SKU商品数据
  211. 'label_id' => isset($this->params[ 'label_id' ]) ? $this->params[ 'label_id' ] : '',// 商品分组id
  212. 'max_buy' => isset($this->params[ 'max_buy' ]) ? $this->params[ 'max_buy' ] : 0,// 限购
  213. 'min_buy' => isset($this->params[ 'min_buy' ]) ? $this->params[ 'min_buy' ] : 0,// 起售
  214. 'timer_on' => isset($this->params[ 'timer_on' ]) ? strtotime($this->params[ 'timer_on' ]) : 0,//定时上架
  215. 'timer_off' => isset($this->params[ 'timer_off' ]) ? strtotime($this->params[ 'timer_off' ]) : 0,//定时下架
  216. 'spec_type_status' => isset($this->params[ 'spec_type_status' ]) ? $this->params[ 'spec_type_status' ] : 0,
  217. 'site_name' => $this->shop_info[ 'site_name' ],
  218. 'virtual_sale' => $this->params[ 'virtual_sale' ] ?? 0,// 虚拟销量
  219. 'is_consume_discount' => $this->params[ 'is_consume_discount' ] ?? 0, //是否参与会员折扣
  220. 'goods_service_ids' => $this->params[ 'goods_service_ids' ] ?? '',// 商品服务id集合
  221. 'recommend_way' => $this->params[ 'recommend_way' ] ?? 0, // 推荐方式,1:新品,2:精品,3;推荐
  222. 'is_limit' => $this->params[ 'is_limit' ] ?? 0,// 商品是否限购,
  223. 'limit_type' => $this->params[ 'limit_type' ] ?? 1, // 商品限购类型,
  224. 'sale_show' => $this->params[ 'sale_show' ] ?? 0,
  225. 'stock_show' => $this->params[ 'stock_show' ] ?? 0,
  226. 'market_price_show' => $this->params[ 'market_price_show' ] ?? 0,
  227. 'barrage_show' => $this->params[ 'barrage_show' ] ?? 0,
  228. 'brand_id' => $this->params[ 'brand_id' ] ?? 0,
  229. 'support_trade_type' => $this->params[ 'support_trade_type' ] ?? '',
  230. 'form_id' => $this->params['goods_form'] ?? 0
  231. ];
  232. $res = $goods_model->editGoods($data);
  233. return $this->response($res);
  234. }
  235. /**
  236. * 获取编辑商品所需数据
  237. * @return false|string
  238. */
  239. public function editGetGoodsInfo()
  240. {
  241. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  242. $goods_model = new GoodsModel();
  243. $goods_info = $goods_model->editGetGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ];
  244. $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,weight,volume,sku_image,sku_images,goods_spec_format,spec_name,stock_alarm,is_default,verify_num", '')[ 'data' ];
  245. $goods_info[ 'goods_sku_data' ] = $goods_sku_list;
  246. if (!empty($goods_info[ 'shipping_template' ])) {
  247. //获取运费模板
  248. $express_template_model = new ExpressTemplateModel();
  249. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ], [ 'template_id', '=', $goods_info[ 'shipping_template' ] ] ], 'template_name')[ 'data' ];
  250. if (!empty($express_template_list)) {
  251. $goods_info[ 'template_name' ] = $express_template_list[ 0 ][ 'template_name' ];
  252. }
  253. }
  254. return $this->response($this->success($goods_info));
  255. }
  256. /**
  257. * 删除商品
  258. */
  259. public function deleteGoods()
  260. {
  261. $goods_ids = isset($this->params[ 'goods_ids' ]) ? $this->params[ 'goods_ids' ] : 0;
  262. $goods_model = new GoodsModel();
  263. $res = $goods_model->modifyIsDelete($goods_ids, 1, $this->site_id);
  264. return $this->response($res);
  265. }
  266. /**
  267. * 商品回收站
  268. */
  269. public function recycle()
  270. {
  271. $page_index = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  272. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  273. $search_keys = isset($this->params[ 'search_keys' ]) ? $this->params[ 'search_keys' ] : '';
  274. $condition = [ [ 'is_delete', '=', 1 ], [ 'site_id', "=", $this->site_id ] ];
  275. if (!empty($search_keys)) {
  276. $condition[] = [ 'goods_name', 'like', '%' . $search_keys . '%' ];
  277. }
  278. $goods_model = new GoodsModel();
  279. $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size);
  280. return $this->response($res);
  281. }
  282. /**
  283. * 商品回收站商品删除
  284. */
  285. public function deleteRecycleGoods()
  286. {
  287. $goods_ids = isset($this->params[ 'goods_ids' ]) ? $this->params[ 'goods_ids' ] : 0;
  288. $goods_model = new GoodsModel();
  289. $res = $goods_model->deleteRecycleGoods($goods_ids, $this->site_id);
  290. return $this->response($res);
  291. }
  292. /**
  293. * 商品回收站商品恢复
  294. */
  295. public function recoveryRecycle()
  296. {
  297. $goods_ids = isset($this->params[ 'goods_ids' ]) ? $this->params[ 'goods_ids' ] : 0;
  298. $goods_model = new GoodsModel();
  299. $res = $goods_model->modifyIsDelete($goods_ids, 0, $this->site_id);
  300. return $this->response($res);
  301. }
  302. /**
  303. * 商品下架
  304. */
  305. public function offGoods()
  306. {
  307. $goods_ids = isset($this->params[ 'goods_ids' ]) ? $this->params[ 'goods_ids' ] : 0;
  308. $goods_state = isset($this->params[ 'goods_state' ]) ? $this->params[ 'goods_state' ] : 0;
  309. $goods_model = new GoodsModel();
  310. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  311. return $this->response($res);
  312. }
  313. /**
  314. * 商品上架
  315. */
  316. public function onGoods()
  317. {
  318. $goods_ids = isset($this->params[ 'goods_ids' ]) ? $this->params[ 'goods_ids' ] : 0;
  319. $goods_state = isset($this->params[ 'goods_state' ]) ? $this->params[ 'goods_state' ] : 0;
  320. $goods_model = new GoodsModel();
  321. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  322. return $this->response($res);
  323. }
  324. /**
  325. * 编辑商品库存
  326. * @return false|string
  327. */
  328. public function editGoodsStock()
  329. {
  330. $sku_list = isset($this->params[ 'sku_list' ]) ? $this->params[ 'sku_list' ] : '';
  331. $res = $this->error();
  332. if (!empty($sku_list)) {
  333. $sku_list = json_decode($sku_list, true);
  334. $model = new GoodsModel;
  335. $res = $model->editGoodsStock($sku_list, $this->site_id);
  336. }
  337. return $this->response($res);
  338. }
  339. /**
  340. * 获取商品分类列表
  341. * @return false|string
  342. */
  343. public function getCategoryList()
  344. {
  345. $category_id = isset($this->params[ 'category_id' ]) ? $this->params[ 'category_id' ] : 0;
  346. $goods_category_model = new GoodsCategoryModel();
  347. $condition = [
  348. [ 'pid', '=', $category_id ]
  349. ];
  350. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  351. return $this->response($goods_category_list);
  352. }
  353. /**
  354. * 获取商品分类列表
  355. * @return false|string
  356. */
  357. public function getCategoryTree()
  358. {
  359. $goods_category_model = new GoodsCategoryModel();
  360. $condition = [
  361. [ 'site_id', '=', $this->site_id ]
  362. ];
  363. $goods_category_list = $goods_category_model->getCategoryTree($condition, 'category_id,category_name,level,commission_rate,sort,pid');
  364. return $this->response($goods_category_list);
  365. }
  366. /**
  367. * 获取商品规格列表
  368. */
  369. public function getSpecList()
  370. {
  371. $attr_id = isset($this->params[ 'attr_id' ]) ? $this->params[ 'attr_id' ] : '';//排除已存在的规格项
  372. $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : '';
  373. $condition = [ [ 'is_spec', '=', 1 ], [ 'site_id', 'in', ( "0,$this->site_id" ) ] ];
  374. if (!empty($attr_id)) {
  375. $condition[] = [ 'attr_id', 'not in', $attr_id ];
  376. }
  377. if (!empty($search_text)) {
  378. $condition[] = [ 'attr_name', 'like', '%' . $search_text . '%' ];
  379. }
  380. $goods_attr_model = new GoodsAttributeModel();
  381. $spec_list = $goods_attr_model->getSpecList($condition, 'attr_id,attr_name,attr_class_name', 'attr_id desc', 50);
  382. return $this->response($spec_list);
  383. }
  384. /**
  385. * 获取商品规格值列表
  386. */
  387. public function getSpecValueList()
  388. {
  389. $attr_id = isset($this->params[ 'attr_id' ]) ? $this->params[ 'attr_id' ] : 0;
  390. $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : '';
  391. $condition = [];
  392. if (!empty($attr_id)) {
  393. $condition[] = [ 'attr_id', '=', $attr_id ];
  394. }
  395. if (!empty($search_text)) {
  396. $condition[] = [ 'attr_value_name', 'like', '%' . $search_text . '%' ];
  397. }
  398. $goods_attr_model = new GoodsAttributeModel();
  399. $spec_list = $goods_attr_model->getSpecValueList($condition, 'attr_value_id,attr_value_name');
  400. return $this->response($spec_list);
  401. }
  402. /**
  403. * 获取商品参数列表
  404. */
  405. public function getAttributeList()
  406. {
  407. $goods_attr_model = new GoodsAttributeModel();
  408. $attr_class_id = isset($this->params[ 'attr_class_id' ]) ? $this->params[ 'attr_class_id' ] : 0;// 商品类型id
  409. $attribute_list = $goods_attr_model->getAttributeList([ [ 'attr_class_id', '=', $attr_class_id ], [ 'is_spec', '=', 0 ], [ 'site_id', 'in', ( "0,$this->site_id" ) ] ], 'attr_id,attr_name,attr_class_id,attr_class_name,attr_type,attr_value_format');
  410. if (!empty($attribute_list[ 'data' ])) {
  411. foreach ($attribute_list[ 'data' ] as $k => $v) {
  412. if (!empty($v[ 'attr_value_format' ])) {
  413. $attribute_list[ 'data' ][ $k ][ 'attr_value_format' ] = json_decode($v[ 'attr_value_format' ], true);
  414. }
  415. }
  416. }
  417. return $this->response($attribute_list);
  418. }
  419. /**
  420. * 获取SKU商品列表
  421. */
  422. public function getGoodsSkuList()
  423. {
  424. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  425. $goods_model = new GoodsModel();
  426. $res = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,sku_name,price,market_price,cost_price,stock,weight,volume,sku_no,sale_num,sku_image,spec_name,goods_id');
  427. return $this->response($res);
  428. }
  429. /**
  430. * 获取SKU商品出入库列表
  431. */
  432. public function getOutputList()
  433. {
  434. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  435. $goods_model = new GoodsModel();
  436. $res = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,sku_name,price,market_price,cost_price,stock', 'is_default desc,price asc');
  437. return $this->response($res);
  438. }
  439. /***********************************************************商品评价**************************************************/
  440. /**
  441. * 商品评价
  442. */
  443. public function evaluate()
  444. {
  445. $goods_evaluate = new GoodsEvaluateModel();
  446. $page_index = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  447. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  448. $explain_type = isset($this->params[ 'explain_type' ]) ? $this->params[ 'explain_type' ] : ''; //1好评2中评3差评
  449. $is_show = isset($this->params[ 'is_show' ]) ? $this->params[ 'is_show' ] : ''; //1显示 0隐藏
  450. $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : ''; //搜索值
  451. $search_type = isset($this->params[ 'search_type' ]) ? $this->params[ 'search_type' ] : ''; //搜索类型
  452. $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';
  453. $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';
  454. $is_image = isset($this->params[ 'is_image' ]) ? $this->params[ 'is_image' ] : 0;//是否有图 1 有图 2 仅文字
  455. $is_reply = isset($this->params[ 'is_reply' ]) ? $this->params[ 'is_reply' ] : 0;//是否回复 1 已回复 2 未回复
  456. $condition = [
  457. [ "site_id", "=", $this->site_id ]
  458. ];
  459. $condition[] = [ 'is_audit', '=', 1 ];
  460. //评分类型
  461. if ($explain_type != "") {
  462. $condition[] = [ "explain_type", "=", $explain_type ];
  463. }
  464. if ($is_show != "") {
  465. $condition[] = [ "is_show", "=", $is_show ];
  466. }
  467. //评论内容
  468. if ($is_image > 0) {
  469. if ($is_image == 1) {
  470. $condition[] = [ "images", "<>", '' ];
  471. } else if ($is_image == 2) {
  472. $condition[] = [ "images", "=", '' ];
  473. }
  474. }
  475. //全部回复
  476. if ($is_reply > 0) {
  477. if ($is_reply == 1) {
  478. $condition[] = [ "explain_first", "<>", '' ];
  479. } else if ($is_reply == 2) {
  480. $condition[] = [ "explain_first", "=", '' ];
  481. }
  482. }
  483. if (!empty($search_text)) {
  484. if (!empty($search_type)) {
  485. $condition[] = [ $search_type, 'like', '%' . $search_text . '%' ];
  486. } else {
  487. $condition[] = [ 'sku_name', 'like', '%' . $search_text . '%' ];
  488. }
  489. }
  490. if (!empty($start_time) && empty($end_time)) {
  491. $condition[] = [ "create_time", ">=", date_to_time($start_time) ];
  492. } elseif (empty($start_time) && !empty($end_time)) {
  493. $condition[] = [ "create_time", "<=", date_to_time($end_time) ];
  494. } elseif (!empty($start_time) && !empty($end_time)) {
  495. $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  496. }
  497. $list = $goods_evaluate->getEvaluatePageList($condition, $page_index, $page_size, "create_time desc");
  498. return $this->response($list);
  499. }
  500. /**
  501. * 商品评价删除
  502. */
  503. public function deleteEvaluate()
  504. {
  505. $goods_evaluate = new GoodsEvaluateModel();
  506. $evaluate_id = isset($this->params[ 'evaluate_id' ]) ? $this->params[ 'evaluate_id' ] : 0;
  507. $res = $goods_evaluate->deleteEvaluate($evaluate_id);
  508. return $this->response($res);
  509. }
  510. /**
  511. * 商品推广
  512. * return
  513. */
  514. public function goodsUrl()
  515. {
  516. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : '';
  517. $goods_model = new GoodsModel();
  518. $goods_sku_info = $goods_model->getGoodsSkuInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_name')[ 'data' ];
  519. $res = $goods_model->qrcode($goods_id, $goods_sku_info[ 'goods_name' ], $this->site_id);
  520. return $this->response($res);
  521. }
  522. /**
  523. * 商品预览
  524. * return
  525. */
  526. public function goodsPreview()
  527. {
  528. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : '';
  529. $goods_model = new GoodsModel();
  530. $goods_sku_info = $goods_model->getGoodsSkuInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_name')[ 'data' ];
  531. $res = $goods_model->qrcode($goods_sku_info[ 'sku_id' ], $goods_sku_info[ 'goods_name' ], $this->site_id);
  532. return $this->response($res);
  533. }
  534. /**
  535. * 商品评价回复
  536. */
  537. public function evaluateApply()
  538. {
  539. $goods_evaluate = new GoodsEvaluateModel();
  540. $evaluate_id = isset($this->params[ 'evaluate_id' ]) ? $this->params[ 'evaluate_id' ] : 0;
  541. $explain = isset($this->params[ 'explain' ]) ? $this->params[ 'explain' ] : 0;
  542. $is_first_explain = isset($this->params[ 'is_first_explain' ]) ? $this->params[ 'is_first_explain' ] : 0;// 是否第一次回复
  543. $data = [
  544. 'evaluate_id' => $evaluate_id
  545. ];
  546. if ($is_first_explain == 0) {
  547. $data[ 'explain_first' ] = $explain;
  548. } elseif ($is_first_explain == 1) {
  549. $data[ 'again_explain' ] = $explain;
  550. }
  551. $res = $goods_evaluate->evaluateApply($data);
  552. return $this->response($res);
  553. }
  554. /**
  555. * 商品评价回复
  556. */
  557. public function deleteContent()
  558. {
  559. $goods_evaluate = new GoodsEvaluateModel();
  560. $evaluate_id = isset($this->params[ 'evaluate_id' ]) ? $this->params[ 'evaluate_id' ] : 0;
  561. $is_first_explain = isset($this->params[ 'is_first' ]) ? $this->params[ 'is_first' ] : 0;// 0 第一次回复,1 追评回复
  562. $data = [];
  563. if ($is_first_explain == 0) {
  564. $data[ 'explain_first' ] = '';
  565. } elseif ($is_first_explain == 1) {
  566. $data[ 'again_explain' ] = '';
  567. }
  568. $condition = [
  569. [ 'evaluate_id', '=', $evaluate_id ],
  570. [ 'site_id', '=', $this->site_id ],
  571. ];
  572. $res = $goods_evaluate->editEvaluate($data, $condition);
  573. return $this->response($res);
  574. }
  575. /**
  576. * 商品复制
  577. */
  578. public function copyGoods()
  579. {
  580. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  581. $goods_model = new GoodsModel();
  582. $result = $goods_model->copyGoods($goods_id, $this->site_id);
  583. return $this->response($result);
  584. }
  585. /**
  586. * 会员商品收藏
  587. */
  588. public function memberGoodsCollect()
  589. {
  590. $goods_collect_model = new GoodsCollect();
  591. $member_id = isset($this->params[ 'member_id' ]) ? $this->params[ 'member_id' ] : 0;
  592. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  593. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  594. $condition = [];
  595. $condition[] = [ 'gc.site_id', '=', $this->site_id ];
  596. $condition[] = [ 'gc.member_id', '=', $member_id ];
  597. $order = 'gc.create_time desc';
  598. $field = 'gc.collect_id, gc.member_id, gc.goods_id, gc.sku_id,gc.sku_name, gc.sku_price, gc.sku_image,g.goods_name,g.is_free_shipping,sku.promotion_type,sku.discount_price,g.sale_num,g.price,g.market_price,g.is_virtual,sku.*';
  599. $res = $goods_collect_model->getCollectPageList($condition, $page, $page_size, $order, $field);
  600. return $this->response($res);
  601. }
  602. /**
  603. * 会员浏览记录
  604. */
  605. public function memberGoodsBrowse()
  606. {
  607. $member_id = isset($this->params[ 'member_id' ]) ? $this->params[ 'member_id' ] : 0;
  608. $goods_browse_model = new GoodsBrowse();
  609. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  610. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  611. $search = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
  612. $condition = [];
  613. $condition[] = [ 'gb.site_id', '=', $this->site_id ];
  614. $condition[] = [ 'gb.member_id', '=', $member_id ];
  615. if (!empty($search))
  616. $condition[] = [ 'gs.sku_name', 'like', '%' . $search . '%' ];
  617. $order = 'browse_time desc';
  618. $field = 'gb.*,gs.sku_name,gs.sku_image,gs.price,gs.goods_state,gs.stock,gs.click_num';
  619. $alias = 'gb';
  620. $join = [
  621. [ 'goods_sku gs', 'gs.sku_id = gb.sku_id', 'left' ]
  622. ];
  623. $res = $goods_browse_model->getBrowsePageList($condition, $page, $page_size, $order, $field, $alias, $join);
  624. return $this->response($res);
  625. }
  626. /**
  627. * 商品浏览记录
  628. */
  629. public function goodsBrowse()
  630. {
  631. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : '';
  632. $goods_browse_model = new GoodsBrowse();
  633. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  634. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  635. $search = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
  636. $condition = [];
  637. $condition[] = [ 'gb.site_id', '=', $this->site_id ];
  638. if ($goods_id > 0) {
  639. $condition[] = [ 'gb.goods_id', '=', $goods_id ];
  640. }
  641. if (!empty($search))
  642. $condition[] = [ 'gs.sku_name', 'like', '%' . $search . '%' ];
  643. $order = 'browse_time desc';
  644. $field = 'gb.*,gs.sku_name,gs.sku_image,gs.price,gs.goods_state,gs.stock,gs.click_num,m.nickname,m.headimg';
  645. $alias = 'gb';
  646. $join = [
  647. [ 'goods_sku gs', 'gs.sku_id = gb.sku_id', 'left' ],
  648. [ 'member m', 'm.member_id = gb.member_id', 'left' ]
  649. ];
  650. $res = $goods_browse_model->getBrowsePageList($condition, $page, $page_size, $order, $field, $alias, $join);
  651. return $this->response($res);
  652. }
  653. /**
  654. * 获取商品参数
  655. * @return false|string
  656. */
  657. public function getAttrClassList()
  658. {
  659. $goods_attr_model = new GoodsAttributeModel();
  660. $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', 'in', ( "0,$this->site_id" ) ] ], 'class_id,class_name');
  661. return $this->response($attr_class_list);
  662. }
  663. /**
  664. * 获取商品设置参数
  665. * @return false|string
  666. */
  667. public function config()
  668. {
  669. $data = [];
  670. $config_model = new ConfigModel();
  671. $goods_sort_confog = $config_model->getGoodsSort($this->site_id, $this->app_module);
  672. $default_search_words = $config_model->getDefaultSearchWords($this->site_id, $this->app_module);
  673. $hot_search_words = $config_model->getHotSearchWords($this->site_id, $this->app_module);
  674. $hot_search_words = $hot_search_words[ 'data' ][ 'value' ];
  675. $words_array = [];
  676. if (!empty($hot_search_words[ 'words' ])) {
  677. $words_array = explode(',', $hot_search_words[ 'words' ]);
  678. }
  679. $hot_search_words[ 'words_array' ] = $words_array;
  680. $data[ "hot_words" ] = $hot_search_words;
  681. $data[ "default_words" ] = $default_search_words[ 'data' ][ 'value' ];
  682. $data[ "goods_sort_confog" ] = $goods_sort_confog[ 'data' ][ 'value' ];
  683. return $this->response($this->success($data));
  684. }
  685. /**
  686. * 编辑商品设置
  687. * @return false|string
  688. */
  689. public function setConfig()
  690. {
  691. $config_model = new ConfigModel();
  692. $hot_serch_words = isset($this->params[ 'hot_words' ]) ? $this->params[ 'hot_words' ] : [];
  693. $default_serch_words = isset($this->params[ 'default_words' ]) ? $this->params[ 'default_words' ] : '';
  694. $type = isset($this->params[ 'sort_type' ]) ? $this->params[ 'sort_type' ] : 'asc';
  695. $default_value = isset($this->params[ 'sort_value' ]) ? $this->params[ 'sort_value' ] : '0';
  696. $config_model->setHotSearchWords([ 'words' => implode(',', explode(',', $hot_serch_words)) ], $this->site_id, $this->app_module);
  697. $config_model->setDefaultSearchWords([ 'words' => $default_serch_words ], $this->site_id, $this->app_module);
  698. $config_model->setGoodsSort([ 'type' => trim($type), 'default_value' => trim($default_value) ], $this->site_id, $this->app_module);
  699. return $this->response($this->success());
  700. }
  701. /**
  702. * 核销码
  703. */
  704. public function verify()
  705. {
  706. $goods_id = $this->params['goods_id'] ?? 0;
  707. $virtual_goods_model = new \app\model\goods\VirtualGoods();
  708. $verify_count = $virtual_goods_model->getVirtualGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'count(id) as total_count, sum(verify_use_num) as verify_use_num')[ 'data' ] ?? [];
  709. return $this->response($this->success($verify_count));
  710. }
  711. public function virtualGoodsList()
  712. {
  713. $virtual_goods_model = new \app\model\goods\VirtualGoods();
  714. $goods_id = $this->params['goods_id'] ?? 0;
  715. $search_text = input("search_text", '');
  716. $field = 'gv.*, m.nickname,m.headimg';
  717. $page_index = input('page', 1);
  718. $page_size = input('page_size', PAGE_LIST_ROWS);
  719. $alias = 'gv';
  720. $condition = [
  721. [ "gv.site_id", "=", $this->site_id ],
  722. [ "gv.goods_id", "=", $goods_id ],
  723. ];
  724. if ($search_text) $condition[] = [ 'm.nickname|gv.code', 'like', '%' . $search_text . '%' ];
  725. $order = "gv.id desc";
  726. $join = [
  727. [
  728. 'member m',
  729. 'm.member_id = gv.member_id',
  730. 'left'
  731. ]
  732. ];
  733. $list = $virtual_goods_model->getVirtualGoodsPageList($condition, $page_index, $page_size, $order, $field, $alias, $join);
  734. return $this->response($list);
  735. }
  736. }