ProductCopy.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\merchant\store\product;
  12. use app\common\repositories\store\product\ProductRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use app\validate\merchant\StoreProductValidate as validate;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. use app\common\repositories\store\product\ProductCopyRepository as repository;
  18. class ProductCopy extends BaseController
  19. {
  20. /**
  21. * @var repository
  22. */
  23. protected $repository;
  24. /**
  25. * ProductCopy constructor.
  26. * @param App $app
  27. * @param repository $repository
  28. */
  29. public function __construct(App $app ,repository $repository)
  30. {
  31. $this->repository = $repository;
  32. parent::__construct($app);
  33. }
  34. /**
  35. * TODO 列表
  36. * @return mixed
  37. * @author Qinii
  38. * @day 2020-08-14
  39. */
  40. public function lst()
  41. {
  42. [$page, $limit] = $this->getPage();
  43. $where['mer_id'] = $this->request->merId();
  44. return app('json')->success($this->repository->getList($where,$page, $limit));
  45. }
  46. /**
  47. * TODO
  48. * @return mixed
  49. * @author Qinii
  50. * @day 2020-08-07
  51. */
  52. public function count()
  53. {
  54. $count = $this->request->merchant()->copy_product_num;
  55. return app('json')->success(['count' => $count]);
  56. }
  57. /**
  58. * TODO 复制商品
  59. * @return mixed
  60. * @author Qinii
  61. * @day 2020-08-06
  62. */
  63. public function get()
  64. {
  65. if(!systemConfig('copy_product_status')) return app('json')->fail('复制商品功能未开启');
  66. $num = app()->make(MerchantRepository::class)->getCopyNum($this->request->merId());
  67. if($num <= 0) return app('json')->fail('复制商品次数已用完');
  68. $data = $this->request->params(['type','id','shopid','url']);
  69. $res = $this->repository->copyProduct($data,$this->request->merId());
  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",
  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. }