Product.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\behalfcustomerorder;
  12. use think\App;
  13. use crmeb\basic\BaseController;
  14. use app\common\repositories\store\product\ProductRepository;
  15. use app\common\repositories\store\StoreCategoryRepository;
  16. class Product extends BaseController
  17. {
  18. protected $productRepository;
  19. protected $storeCategoryRepository;
  20. public function __construct(App $app, ProductRepository $productRepository, StoreCategoryRepository $storeCategoryRepository)
  21. {
  22. parent::__construct($app);
  23. $this->productRepository = $productRepository;
  24. $this->storeCategoryRepository = $storeCategoryRepository;
  25. }
  26. public function __destruct()
  27. {
  28. unset($this->productRepository);
  29. unset($this->storeCategoryRepository);
  30. }
  31. /**
  32. * 获取商品分类
  33. *
  34. * @return void
  35. */
  36. public function category()
  37. {
  38. $merId = $this->request->merId();
  39. return app('json')->success($this->storeCategoryRepository->getCategoryByMerId($merId));
  40. }
  41. /**
  42. * 获取商品列表
  43. *
  44. * @return void
  45. */
  46. public function list()
  47. {
  48. // 获取分页参数
  49. [$page, $limit] = $this->getPage();
  50. // 获取查询参数
  51. $merId = $this->request->merId();
  52. $type = $this->request->param('type', 1);
  53. $where = $this->request->params(['search', 'mer_cate_id']);
  54. $where = array_merge($where, $this->productRepository->switchType($type, $this->request->merId(), 0));
  55. return app('json')->success($this->productRepository->getBehalfProductList($merId, $where, $page, $limit));
  56. }
  57. /**
  58. * 获取商品详情
  59. *
  60. * @param [type] $id
  61. * @return void
  62. */
  63. public function detail($id)
  64. {
  65. if (!$id) {
  66. return app('json')->fail('参数错误');
  67. }
  68. $merId = $this->request->merId();
  69. return app('json')->success($this->productRepository->getBehalfCustomerOrderDetail($merId, $id));
  70. }
  71. }