StoreProductPresell.php 4.1 KB

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