Goods.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\shopcomponent\shop\controller;
  11. use addon\shopcomponent\model\Category;
  12. use addon\shopcomponent\model\Weapp;
  13. use app\model\system\Cron;
  14. use app\shop\controller\BaseShop;
  15. use addon\shopcomponent\model\Goods as GoodsModel;
  16. use addon\shopcomponent\model\Category as CategoryModel;
  17. /**
  18. * 商品
  19. */
  20. class Goods extends BaseShop
  21. {
  22. public function lists()
  23. {
  24. if (request()->isAjax()) {
  25. $goods = new GoodsModel();
  26. $page = input('page', 1);
  27. $page_size = input('page_size', PAGE_LIST_ROWS);
  28. $condition = [
  29. 'sg.site_id' => $this->site_id
  30. ];
  31. $data = $goods->getGoodsPageList($condition, '*', 'id desc', $page, $page_size);
  32. return $data;
  33. } else {
  34. $category = ( new Category() )->getCategoryByParent(1);
  35. $this->assign('first_cat', $category[ 'data' ]);
  36. $check_res = ( new Weapp($this->site_id) )->checkRegister();
  37. $this->assign('checkres', $check_res);
  38. $this->forthMenu();
  39. return $this->fetch("goods/index");
  40. }
  41. }
  42. public function sync()
  43. {
  44. $start = input('start', 0);
  45. $res = ( new GoodsModel() )->syncGoods($start, 100, $this->site_id);
  46. return $res;
  47. }
  48. /**
  49. * 小程序添加商品
  50. */
  51. public function add()
  52. {
  53. if (request()->isAjax()) {
  54. $param = input();
  55. if (empty($param)) $this->error('必要参数必填');
  56. $data = [
  57. 'site_id' => $this->site_id,
  58. 'goods_ids' => $param[ 'goods_ids' ],
  59. 'third_cat_id' => $param[ 'third_cat_id' ],
  60. ];
  61. $goods_model = new GoodsModel();
  62. return $goods_model->addGoods($data);
  63. }
  64. }
  65. /**
  66. * 小程序修改商品分类
  67. */
  68. public function edit()
  69. {
  70. if (request()->isAjax()) {
  71. $param = input();
  72. if (empty($param)) $this->error('必要参数必填');
  73. $data = [
  74. 'site_id' => $this->site_id,
  75. 'goods_id' => $param[ 'goods_id' ],
  76. 'third_cat_id' => $param[ 'third_cat_id' ],
  77. ];
  78. $goods_model = new GoodsModel();
  79. return $goods_model->updateGoods($data);
  80. }
  81. }
  82. /**
  83. * 检验分类是否已上传资质
  84. */
  85. public function check()
  86. {
  87. if (request()->isAjax()) {
  88. $param = input();
  89. if (empty($param)) $this->error('必要参数必填');
  90. $data = [
  91. 'site_id' => $this->site_id,
  92. 'third_cat_id' => $param[ 'third_cat_id' ],
  93. ];
  94. $cat_model = new CategoryModel();
  95. return $cat_model->isQualifications($data);
  96. }
  97. }
  98. /**
  99. * 小程序删除商品
  100. */
  101. public function delete()
  102. {
  103. if (request()->isAjax()) {
  104. $goods_model = new GoodsModel();
  105. return $goods_model->deleteGoods(input('out_product_ids', ''), $this->site_id);
  106. }
  107. }
  108. /**
  109. * 商品上架
  110. */
  111. public function listing()
  112. {
  113. if (request()->isAjax()) {
  114. $goods_model = new GoodsModel();
  115. $out_product_ids = input('out_product_ids', '');
  116. return $goods_model->goodsListing($out_product_ids, $this->site_id);
  117. }
  118. }
  119. /**
  120. * 商品下架
  121. */
  122. public function dellisting()
  123. {
  124. if (request()->isAjax()) {
  125. $goods_model = new GoodsModel();
  126. $out_product_ids = input('out_product_ids', '');
  127. return $goods_model->goodsDelisting($out_product_ids, $this->site_id);
  128. }
  129. }
  130. /**
  131. * 视频号接入
  132. * @return mixed
  133. */
  134. public function access()
  135. {
  136. $weapp = new Weapp($this->site_id);
  137. if (request()->isAjax()) {
  138. $res = $weapp->apply();
  139. if ($res[ 'code' ] == 0) {
  140. ( new Cron() )->addCron(1, 0, "同步微信类目", "SyncWxCategory", time(), $this->site_id);
  141. }
  142. return $res;
  143. }
  144. $checkres = $weapp->checkRegister();
  145. $this->assign('checkres', $checkres);
  146. $this->forthMenu();
  147. return $this->fetch("goods/access");
  148. }
  149. /**
  150. * 完成接入任务
  151. */
  152. public function finishAccess()
  153. {
  154. if (request()->isAjax()) {
  155. $item = input('item', '');
  156. $weapp = new Weapp($this->site_id);
  157. $res = $weapp->finishAccessInfo($item);
  158. return $res;
  159. }
  160. }
  161. /**
  162. * 获取订单测试数据
  163. */
  164. public function getOrderPayInfo()
  165. {
  166. if (request()->isAjax()) {
  167. $goods_model = new GoodsModel();
  168. $res = $goods_model->getOrderPayInfo($this->site_id);
  169. return $res;
  170. }
  171. }
  172. }