StoreProduct.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\store;
  12. use app\common\repositories\store\product\ProductAttrValueRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use app\validate\merchant\StoreProductValidate;
  15. use crmeb\jobs\ChangeSpuStatusJob;
  16. use crmeb\jobs\CheckProductExtensionJob;
  17. use think\App;
  18. use crmeb\basic\BaseController;
  19. use app\validate\merchant\StoreProductAdminValidate as validate;
  20. use app\common\repositories\store\product\ProductRepository as repository;
  21. use think\facade\Queue;
  22. class StoreProduct extends BaseController
  23. {
  24. /**
  25. * @var repository
  26. */
  27. protected $repository;
  28. /**
  29. * StoreProduct constructor.
  30. * @param App $app
  31. * @param repository $repository
  32. */
  33. public function __construct(App $app, repository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. }
  38. /**
  39. * @Author:Qinii
  40. * @Date: 2020/5/18
  41. * @return mixed
  42. */
  43. public function lst()
  44. {
  45. [$page, $limit] = $this->getPage();
  46. $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid','store_name','is_trader','us_status','product_id','star']);
  47. $mer_id = $this->request->param('mer_id','');
  48. $merId = $mer_id ? $mer_id : null;
  49. $where['is_gift_bag'] = 0;
  50. $_where = $this->repository->switchType($where['type'], null,0);
  51. unset($_where['star']);
  52. $where = array_merge($where, $_where);
  53. return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit));
  54. }
  55. /**
  56. * @Author:Qinii
  57. * @Date: 2020/5/18
  58. * @return mixed
  59. */
  60. public function bagList()
  61. {
  62. [$page, $limit] = $this->getPage();
  63. $where = $this->request->params(['cate_id','keyword',['type',1],'mer_cate_id' ,'is_trader','us_status']);
  64. $merId = $this->request->param('mer_id') ? $this->request->param('mer_id') : null;
  65. $res = $this->repository->switchType($where['type'],$merId,10);
  66. $where = array_merge($where,$res);
  67. return app('json')->success($this->repository->getAdminList($merId,$where, $page, $limit));
  68. }
  69. /**
  70. * @Author:Qinii
  71. * @Date: 2020/5/18
  72. * @return mixed
  73. */
  74. public function getStatusFilter()
  75. {
  76. return app('json')->success($this->repository->getFilter(null,'商品',0));
  77. }
  78. /**
  79. * TODO 礼包表头
  80. * @Author:Qinii
  81. * @Date: 2020/5/18
  82. * @return mixed
  83. */
  84. public function getBagStatusFilter()
  85. {
  86. return app('json')->success($this->repository->getFilter(null,'礼包',10));
  87. }
  88. /**
  89. * @Author:Qinii
  90. * @Date: 2020/5/18
  91. * @param $id
  92. * @return mixed
  93. */
  94. public function detail($id)
  95. {
  96. if(!$this->repository->merExists(null,$id))
  97. return app('json')->fail('数据不存在');
  98. return app('json')->success($this->repository->getAdminOneProduct($id,null));
  99. }
  100. /**
  101. * @Author:Qinii
  102. * @Date: 2020/5/11
  103. * @param $id
  104. * @param validate $validate
  105. * @return mixed
  106. */
  107. public function update($id,validate $validate)
  108. {
  109. $data = $this->checkParams($validate);
  110. $this->repository->adminUpdate($id,$data);
  111. return app('json')->success('编辑成功');
  112. }
  113. /**
  114. * @Author:Qinii
  115. * @Date: 2020/5/18
  116. * @param int $id
  117. * @return mixed
  118. */
  119. public function switchStatus()
  120. {
  121. $id = $this->request->param('id');
  122. $data = $this->request->params(['status','refusal']);
  123. if($data['status'] == -1 && empty($data['refusal']))
  124. return app('json')->fail('请填写拒绝理由');
  125. if(!is_array($id)) $id = [$id];
  126. $this->repository->switchStatus($id,$data);
  127. return app('json')->success('操作成功');
  128. }
  129. /**
  130. * TODO 是否隐藏
  131. * @param $id
  132. * @return mixed
  133. * @author Qinii
  134. * @day 2020-07-17
  135. */
  136. public function changeUsed($id)
  137. {
  138. if(!$this->repository->merExists(null,$id))
  139. return app('json')->fail('数据不存在');
  140. $status = $this->request->param('status',0) == 1 ? 1 : 0;
  141. $status = ['is_used' => $status];
  142. $this->repository->update($id,$status);
  143. queue(ChangeSpuStatusJob::class,['id' => $id,'product_type' => 0]);
  144. return app('json')->success('修改成功');
  145. }
  146. /**
  147. * @Author:Qinii
  148. * @Date: 2020/5/11
  149. * @param validate $validate
  150. * @return array
  151. */
  152. public function checkParams(validate $validate)
  153. {
  154. $data = $this->request->params(['is_hot','is_best','is_benefit','is_new','store_name','content','rank','star']);
  155. $validate->check($data);
  156. return $data;
  157. }
  158. /**
  159. * TODO
  160. * @author Qinii
  161. * @day 2020-06-24
  162. */
  163. public function checkProduct()
  164. {
  165. Queue::push(CheckProductExtensionJob::class,[]);
  166. return app('json')->success('后台已开始检测');
  167. }
  168. public function lists()
  169. {
  170. $make = app()->make(MerchantRepository::class);
  171. $data = $make->selectWhere(['status' => 1,'mer_state' => 1,'is_del' => 0],'mer_id,mer_name');
  172. return app('json')->success($data);
  173. }
  174. /**
  175. * 增加虚拟销量表单
  176. * @Author:Qinii
  177. * @Date: 2020/10/9
  178. * @param $id
  179. * @return mixed
  180. */
  181. public function addFictiForm($id)
  182. {
  183. if(!$this->repository->merExists(null,$id))
  184. return app('json')->fail('数据不存在');
  185. return app('json')->success(formToData($this->repository->fictiForm($id)));
  186. }
  187. /**
  188. * 修改虚拟销量
  189. * @Author:Qinii
  190. * @Date: 2020/10/9
  191. * @param $id
  192. * @return mixed
  193. *
  194. */
  195. public function addFicti($id)
  196. {
  197. $data = $this->request->params(['type','ficti']);
  198. if(!in_array($data['type'],[1,2])) return app('json')->fail('类型错误');
  199. if(!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('虚拟销量必须大于0');
  200. $res = $this->repository->getWhere(['product_id' => $id],'ficti,sales');
  201. if(!$res) return app('json')->fail('数据不存在');
  202. if($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('虚拟销量不足');
  203. $ficti = ($data['type'] == 1) ? $data['ficti'] : '-' . $data['ficti'];
  204. $data = [
  205. 'ficti' => $res['ficti'] + $ficti,
  206. 'sales' => $res['sales'] + $ficti
  207. ];
  208. $this->repository->update($id,$data);
  209. return app('json')->success('修改成功');
  210. }
  211. /**
  212. * TODO
  213. * @param $id
  214. * @return \think\response\Json
  215. * @author Qinii
  216. * @day 3/17/21
  217. */
  218. public function updateSort($id)
  219. {
  220. $sort = $this->request->param('sort');
  221. $this->repository->updateSort($id,null,['rank' => $sort]);
  222. return app('json')->success('修改成功');
  223. }
  224. }