ProductCopy.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\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->param('mer_id');
  44. $mer_id = $this->request->merId();
  45. if ($mer_id){
  46. $where['mer_id'] = $this->request->merId();
  47. }
  48. $where['type'] = $this->request->param('type','copy');
  49. return app('json')->success($this->repository->getList($where,$page, $limit));
  50. }
  51. /**
  52. * TODO
  53. * @return mixed
  54. * @author Qinii
  55. * @day 2020-08-07
  56. */
  57. public function count()
  58. {
  59. $count = $this->request->merchant()->copy_product_num;
  60. return app('json')->success(['count' => $count]);
  61. }
  62. /**
  63. * TODO 复制商品
  64. * @return mixed
  65. * @author Qinii
  66. * @day 2020-08-06
  67. */
  68. public function get()
  69. {
  70. $status = systemConfig('copy_product_status');
  71. if($status == 0) return app('json')->fail('请前往平台后台-设置-第三方接口-开启采集');
  72. $num = app()->make(MerchantRepository::class)->getCopyNum($this->request->merId());
  73. if($num <= 0) return app('json')->fail('复制商品次数已用完');
  74. $url = $this->request->param('url');
  75. if (!$url) return app('json')->fail('请输入采集链接');
  76. $res = $this->repository->getProduct($url,$this->request->merId());
  77. return app('json')->success($res);
  78. }
  79. }