ProductCopy.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\controller\merchant\store\product;
  3. use app\common\repositories\store\product\ProductRepository;
  4. use app\common\repositories\system\merchant\MerchantRepository;
  5. use app\validate\merchant\StoreProductValidate as validate;
  6. use think\App;
  7. use ln\basic\BaseController;
  8. use app\common\repositories\store\product\ProductCopyRepository as repository;
  9. class ProductCopy extends BaseController
  10. {
  11. /**
  12. * @var repository
  13. */
  14. protected $repository;
  15. /**
  16. * ProductCopy constructor.
  17. * @param App $app
  18. * @param repository $repository
  19. */
  20. public function __construct(App $app ,repository $repository)
  21. {
  22. $this->repository = $repository;
  23. parent::__construct($app);
  24. }
  25. /**
  26. * TODO 列表
  27. * @return mixed
  28. * @author Qinii
  29. * @day 2020-08-14
  30. */
  31. public function lst()
  32. {
  33. [$page, $limit] = $this->getPage();
  34. $where['mer_id'] = $this->request->param('mer_id');
  35. $mer_id = $this->request->merId();
  36. if ($mer_id){
  37. $where['mer_id'] = $this->request->merId();
  38. }
  39. $where['type'] = $this->request->param('type','copy');
  40. return app('json')->success($this->repository->getList($where,$page, $limit));
  41. }
  42. /**
  43. * TODO
  44. * @return mixed
  45. * @author Qinii
  46. * @day 2020-08-07
  47. */
  48. public function count()
  49. {
  50. $count = $this->request->merchant()->copy_product_num;
  51. return app('json')->success(['count' => $count]);
  52. }
  53. /**
  54. * TODO 复制商品
  55. * @return mixed
  56. * @author Qinii
  57. * @day 2020-08-06
  58. */
  59. public function get()
  60. {
  61. if(!systemConfig('copy_product_status')) return app('json')->fail('复制商品功能未开启');
  62. $num = app()->make(MerchantRepository::class)->getCopyNum($this->request->merId());
  63. if($num <= 0) return app('json')->fail('复制商品次数已用完');
  64. $data = $this->request->params(['type','id','shopid','url']);
  65. if(systemConfig('copy_product_status') == 2){
  66. $res = $this->repository->crmebCopyProduct($data,$this->request->merId());
  67. } else {
  68. $res = $this->repository->copyProduct($data,$this->request->merId());
  69. }
  70. return app('json')->success($res);
  71. }
  72. public function save(validate $validate,ProductRepository $productRepository)
  73. {
  74. $merchant = $this->request->merchant();
  75. $data = $this->checkParams($validate);
  76. $data['mer_id'] = $this->request->merId();
  77. $productRepository->check($data,$this->request->merId());
  78. $data['status'] = $this->request->merchant()->is_audit ? 0 : 1;
  79. $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1;
  80. $this->repository->create($data,0);
  81. return app('json')->success('添加成功');
  82. }
  83. public function checkParams(validate $validate)
  84. {
  85. $params = [
  86. "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "brand_id","guarantee_template_id","once_count",
  87. "cate_id", "mer_cate_id", "unit_name", "sort" , "is_show", "is_good",'is_gift_bag',
  88. "video_link", "temp_id", "content", "spec_type","extension_type", "attr", "attrValue",['give_coupon_ids',[]]
  89. ];
  90. $data = $this->request->params($params);
  91. $validate->check($data);
  92. return $data;
  93. }
  94. }