StoreProductAssist.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\ProductAssistRepository as repository;
  13. use app\common\repositories\store\product\SpuRepository;
  14. use app\validate\merchant\StoreProductAdminValidate as validate;
  15. use crmeb\basic\BaseController;
  16. use crmeb\services\SwooleTaskService;
  17. use think\App;
  18. class StoreProductAssist extends BaseController
  19. {
  20. protected $repository;
  21. /**
  22. * Product constructor.
  23. * @param App $app
  24. * @param repository $repository
  25. */
  26. public function __construct(App $app, repository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. }
  31. /**
  32. * TODO 列表
  33. * @return mixed
  34. * @author Qinii
  35. * @day 2020-10-12
  36. */
  37. public function lst()
  38. {
  39. [$page, $limit] = $this->getPage();
  40. $where = $this->request->params(['product_status', 'keyword', 'status', 'type', 'mer_id', 'is_trader', 'us_status', 'star', 'product_assist_id', 'sys_labels']);
  41. $data = $this->repository->getAdminList($where, $page, $limit);
  42. return app('json')->success($data);
  43. }
  44. /**
  45. * TODO 详情
  46. * @param $id
  47. * @return mixed
  48. * @author Qinii
  49. * @day 2020-10-12
  50. */
  51. public function detail($id)
  52. {
  53. $data = $this->repository->detail(null, $id);
  54. return app('json')->success($data);
  55. }
  56. public function switchStatus($id)
  57. {
  58. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  59. if (!$ret = $this->repository->get($id))
  60. return app('json')->fail('数据不存在');
  61. $this->repository->update($id, ['status' => $status]);
  62. app()->make(SpuRepository::class)->changeStatus($id,3);
  63. return app('json')->success('修改成功');
  64. }
  65. /**
  66. * TODO 获取商品
  67. * @param $id
  68. * @return mixed
  69. * @author Qinii
  70. * @day 2020-11-02
  71. */
  72. public function get($id)
  73. {
  74. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  75. return app('json')->fail('数据不存在');
  76. $data = $this->repository->get($id);
  77. return app('json')->success($data);
  78. }
  79. /**
  80. * TODO 编辑商品
  81. * @param $id
  82. * @param validate $validate
  83. * @return mixed
  84. * @author Qinii
  85. * @day 2020-11-02
  86. */
  87. public function update($id, validate $validate)
  88. {
  89. $data = $this->checkParams($validate);
  90. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  91. return app('json')->fail('数据不存在');
  92. $this->repository->updateProduct($id, $data);
  93. return app('json')->success('编辑成功');
  94. }
  95. public function checkParams(validate $validate)
  96. {
  97. $data = $this->request->params(['is_hot', 'is_best', 'is_benefit', 'is_new', 'store_name', 'keyword', 'content', 'rank', 'star']);
  98. $validate->check($data);
  99. return $data;
  100. }
  101. /**
  102. * TODO 审核
  103. * @return \think\response\Json
  104. * @author Qinii
  105. * @day 2022/11/15
  106. */
  107. public function switchAudit()
  108. {
  109. $id = $this->request->param('id');
  110. if (!$ret = $this->repository->get($id))
  111. return app('json')->fail('数据不存在');
  112. $data = $this->request->params(['status', 'refusal']);
  113. if ($data['status'] == -1 && empty($data['refusal']))
  114. return app('json')->fail('请填写拒绝理由');
  115. $this->repository->switchStatus($id,$data);
  116. return app('json')->success('操作成功');
  117. }
  118. public function setLabels($id)
  119. {
  120. $data = $this->request->params(['sys_labels']);
  121. app()->make(SpuRepository::class)->setLabels($id, 3, $data, 0);
  122. return app('json')->success('修改成功');
  123. }
  124. }