ReservationProduct.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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\product;
  12. use think\App;
  13. use app\Request;
  14. use crmeb\basic\BaseController;
  15. use app\validate\merchant\StoreProductValidate;
  16. use app\common\repositories\store\product\NewProductRepository;
  17. use app\common\repositories\store\product\ProductAttrValueRepository;
  18. use app\common\repositories\store\product\ProductReservationRepository;
  19. /**
  20. * Class ReservationProduct
  21. * @package app\controller\merchant\store\product;
  22. * @author Weeks
  23. */
  24. class ReservationProduct extends BaseController
  25. {
  26. protected $validate;
  27. protected $repository;
  28. protected $attrValueRepository;
  29. protected $productReservationRepository;
  30. /**
  31. * Product constructor.
  32. * @param App $app
  33. * @param StoreProductValidate $validate
  34. * @param NewProductRepository $repository
  35. */
  36. public function __construct(
  37. App $app,
  38. StoreProductValidate $validate,
  39. NewProductRepository $repository,
  40. ProductAttrValueRepository $attrValueRepository,
  41. ProductReservationRepository $productReservationRepository
  42. ) {
  43. parent::__construct($app);
  44. $this->validate = $validate;
  45. $this->repository = $repository;
  46. $this->attrValueRepository = $attrValueRepository;
  47. $this->productReservationRepository = $productReservationRepository;
  48. }
  49. public function __destruct()
  50. {
  51. unset($this->validate);
  52. unset($this->repository);
  53. unset($this->attrValueRepository);
  54. unset($this->productReservationRepository);
  55. }
  56. protected function getValidate()
  57. {
  58. return $this->validate;
  59. }
  60. protected function getRepository()
  61. {
  62. return $this->repository;
  63. }
  64. protected function getAttrValueRepository()
  65. {
  66. return $this->attrValueRepository;
  67. }
  68. protected function getProductReservationRepository()
  69. {
  70. return $this->productReservationRepository;
  71. }
  72. /**
  73. * 创建商品
  74. *
  75. * @param Request $request
  76. * @return json
  77. */
  78. public function create(Request $request)
  79. {
  80. $params = $request->params(NewProductRepository::CREATE_PARAMS);
  81. $params['mer_id'] = $request->merId();
  82. $validate = $this->getValidate();
  83. if (!$validate->sceneCreate($params)) {
  84. return app('json')->fail($validate->getError());
  85. }
  86. $repository = $this->getRepository();
  87. $params = $repository->checkParams($params, $request->merId());
  88. $res = $repository->createProduct($params, $request->merchant(), $request->adminInfo());
  89. if (!$res) {
  90. return app('json')->fail('创建失败');
  91. }
  92. return app('json')->success('创建成功', $res);
  93. }
  94. /**
  95. * 编辑商品
  96. *
  97. * @param integer $id
  98. * @param Request $request
  99. * @return json
  100. */
  101. public function edit(int $id, Request $request)
  102. {
  103. $params = $request->params(NewProductRepository::CREATE_PARAMS);
  104. $params['mer_id'] = $request->merId();
  105. $validate = $this->getValidate();
  106. if (!$validate->sceneUpdate($params)) {
  107. return app('json')->fail($validate->getError());
  108. }
  109. $repository = $this->getRepository();
  110. $params = $repository->checkParams($params, $request->merId());
  111. $res = $repository->editProduct($id, $params, $request->merchant(), $request->adminInfo());
  112. if (!$res) {
  113. return app('json')->fail('编辑失败');
  114. }
  115. return app('json')->success('编辑成功', $res);
  116. }
  117. /**
  118. * 删除商品
  119. *
  120. * @param integer $id
  121. * @return json
  122. */
  123. public function delete(int $id) {}
  124. /**
  125. * 商品列表
  126. *
  127. * @param Request $request
  128. * @return json
  129. */
  130. public function list(Request $request) {}
  131. /**
  132. * 商品详情
  133. *
  134. * @param integer $id
  135. * @return json
  136. */
  137. public function detail(int $id)
  138. {
  139. if (!$id) {
  140. return app('json')->fail('缺少参数');
  141. }
  142. return app('json')->success($this->getRepository()->productDetail($id));
  143. }
  144. /**
  145. * 编辑商品信息获取
  146. *
  147. * @param integer $id
  148. * @return void
  149. */
  150. public function editInfo(int $id)
  151. {
  152. if (!$id) {
  153. return app('json')->fail('缺少参数');
  154. }
  155. return app('json')->success($this->getRepository()->editInfo($id));
  156. }
  157. /**
  158. * 批量设置预约商品库存
  159. *
  160. * @param Request $request
  161. * @return json
  162. */
  163. public function batchSetReservationProductStock(int $id, Request $request)
  164. {
  165. $params = $request->params(['stockValue']);
  166. $validate = $this->getValidate();
  167. if (!$validate->sceneBatchProductStock($params)) {
  168. return app('json')->fail($validate->getError());
  169. }
  170. $res = $this->getAttrValueRepository()->batchSetReservationProductStock($id, $params);
  171. if (!$res) {
  172. return app('json')->fail('修改失败');
  173. }
  174. return app('json')->success('修改成功');
  175. }
  176. /**
  177. * 商品日历month
  178. *
  179. * @param integer $id
  180. * @return void
  181. */
  182. public function showMonth($id)
  183. {
  184. $where = $this->request->params([
  185. ['sku_id',''],
  186. ['date',date('Y-m')],
  187. ]);
  188. $data = $this->getProductReservationRepository()->showMonth($id, $where);
  189. return app('json')->success($data);
  190. }
  191. /**
  192. * 商品日历day
  193. *
  194. * @param integer $id
  195. * @return void
  196. */
  197. public function showDay(int $id )
  198. {
  199. $where = $this->request->params([
  200. ['day',date('d')],
  201. ['date',date('Y-m')],
  202. ['sku_id',0]
  203. ]);
  204. $data = $this->getProductReservationRepository()->showDay($id, $where);
  205. return app('json')->success($data);
  206. }
  207. }