Product.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\out;
  12. use app\Request;
  13. use app\services\product\category\StoreProductCategoryServices;
  14. use app\services\out\StoreProductServices;
  15. /**
  16. * 商品类
  17. * Class StoreProductController
  18. * @package app\api\controller\store
  19. */
  20. class Product
  21. {
  22. /**
  23. * 商品services
  24. * @var StoreProductServices
  25. */
  26. protected $services;
  27. public function __construct(StoreProductServices $services)
  28. {
  29. $this->services = $services;
  30. }
  31. /**
  32. * 商品详情
  33. * @param Request $request
  34. * @return mixed
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function detail(Request $request)
  40. {
  41. $spu = $request->getMore([
  42. ['spu', 0]
  43. ], true);
  44. $data = $this->services->productDetail($request, $spu);
  45. return app('json')->successful($data);
  46. }
  47. /**
  48. * 修改状态
  49. * @param Request $request
  50. * @return mixed
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function set_show(Request $request)
  56. {
  57. [$spu, $is_show] = $request->getMore([
  58. ['spu', 0],
  59. ['is_show', 0]
  60. ], true);
  61. $this->services->setShow($request, $spu, $is_show);
  62. return app('json')->success($is_show == 1 ? '上架成功' : '下架成功');
  63. }
  64. /**
  65. * 获取分类
  66. * @param StoreProductCategoryServices $services
  67. * @return mixed
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function category(StoreProductCategoryServices $services)
  73. {
  74. $data = $services->getOutList();
  75. return app('json')->success($data);
  76. }
  77. /**
  78. * 批量修改库存
  79. * @param Request $request
  80. * @param string $spu
  81. * @return
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\DbException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. */
  86. public function set_stock(Request $request, $spu = '')
  87. {
  88. [$data] = $request->postMore([
  89. ['data', []],
  90. ], true);
  91. if (!$spu || !$data) return $this->fail('参数错误');
  92. $res = $this->services->setStock((array)$data, (string)$spu);
  93. return app('json')->success('修改成功');
  94. }
  95. }