StoreBargain.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\marketing;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\activity\bargain\StoreBargainServices;
  14. use app\services\activity\bargain\StoreBargainUserHelpServices;
  15. use app\services\activity\bargain\StoreBargainUserServices;
  16. use think\facade\App;
  17. /**
  18. * 砍价管理
  19. * Class StoreBargain
  20. * @package app\adminapi\controller\v1\marketing
  21. */
  22. class StoreBargain extends AuthController
  23. {
  24. /**
  25. * StoreBargain constructor.
  26. * @param App $app
  27. * @param StoreBargainServices $services
  28. */
  29. public function __construct(App $app, StoreBargainServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 砍价列表
  36. * @return mixed
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function index()
  42. {
  43. $where = $this->request->getMore([
  44. ['start_status', ''],
  45. ['status', ''],
  46. ['store_name', ''],
  47. ['product_id', 0],
  48. ]);
  49. $where['is_del'] = 0;
  50. $list = $this->services->getStoreBargainList($where);
  51. return app('json')->success($list);
  52. }
  53. /**
  54. * 保存砍价商品
  55. * @param $id
  56. * @return mixed
  57. */
  58. public function save($id)
  59. {
  60. $data = $this->request->postMore([
  61. ['title', ''],
  62. ['info', ''],
  63. ['unit_name', ''],
  64. ['section_time', []],
  65. ['image', ''],
  66. ['images', []],
  67. ['bargain_max_price', 0],
  68. ['bargain_min_price', 0],
  69. ['sort', 0],
  70. ['give_integral', 0],
  71. ['is_hot', 0],
  72. ['status', 0],
  73. ['product_id', 0],
  74. ['description', ''],
  75. ['attrs', []],
  76. ['items', []],
  77. ['temp_id', 0],
  78. ['rule', ''],
  79. ['num', 1],
  80. ['copy', 0],
  81. ['bargain_num', 1],
  82. ['people_num', 1],
  83. ['logistics', []],//物流方式
  84. ['freight', 1],//运费设置
  85. ['postage', 0],//邮费
  86. ['custom_form', ''],
  87. ['virtual_type', 0],
  88. ['is_commission', 0],
  89. ]);
  90. $this->validate($data, \app\adminapi\validate\marketing\StoreBargainValidate::class, 'save');
  91. if ($data['section_time']) {
  92. [$start_time, $end_time] = $data['section_time'];
  93. if (strtotime($end_time) < time()) {
  94. return app('json')->fail(400507);
  95. }
  96. }
  97. $bragain = [];
  98. if ($id) {
  99. $bragain = $this->services->get((int)$id);
  100. if (!$bragain) {
  101. return app('json')->fail(100026);
  102. }
  103. }
  104. //限制编辑
  105. if ($data['copy'] == 0 && $bragain) {
  106. if ($bragain['stop_time'] < time()) {
  107. return app('json')->fail(400508);
  108. }
  109. }
  110. if ($data['copy'] == 1) {
  111. $id = 0;
  112. unset($data['copy']);
  113. }
  114. $this->services->saveData($id, $data);
  115. return app('json')->success(100000);
  116. }
  117. /**
  118. * 获取详情
  119. * @param $id
  120. * @return mixed
  121. */
  122. public function read($id)
  123. {
  124. $info = $this->services->getInfo($id);
  125. return app('json')->success(compact('info'));
  126. }
  127. /**
  128. * 删除砍价
  129. * @param $id
  130. * @return mixed
  131. */
  132. public function delete($id)
  133. {
  134. $this->services->update($id, ['is_del' => 1]);
  135. /** @var StoreBargainUserServices $bargainUserService */
  136. $bargainUserService = app()->make(StoreBargainUserServices::class);
  137. $bargainUserService->userBargainStatusFail($id, true);
  138. return app('json')->success(100002);
  139. }
  140. /**
  141. * 修改状态
  142. * @param $id
  143. * @param $status
  144. * @return mixed
  145. */
  146. public function set_status($id, $status)
  147. {
  148. /** @var StoreBargainUserServices $bargainUserService */
  149. $bargainUserService = app()->make(StoreBargainUserServices::class);
  150. if ($status == 0) {
  151. $bargainUserService->userBargainStatusFail($id, false);
  152. } else {
  153. $info = $this->services->get($id);
  154. if ($info['stop_time'] < time()) {
  155. return app('json')->fail('活动已结束,无法继续上架');
  156. }
  157. }
  158. $this->services->update($id, ['status' => $status]);
  159. return app('json')->success(100001);
  160. }
  161. /**
  162. * 砍价列表
  163. * @return mixed
  164. */
  165. public function bargainList()
  166. {
  167. $where = $this->request->getMore([
  168. ['status', ''],
  169. ['data', '', '', 'time'],
  170. ]);
  171. /** @var StoreBargainUserServices $bargainUserService */
  172. $bargainUserService = app()->make(StoreBargainUserServices::class);
  173. $list = $bargainUserService->bargainUserList($where);
  174. return app('json')->success($list);
  175. }
  176. /**
  177. * 砍价信息
  178. * @param $id
  179. * @return mixed
  180. */
  181. public function bargainListInfo($id)
  182. {
  183. /** @var StoreBargainUserHelpServices $bargainUserHelpService */
  184. $bargainUserHelpService = app()->make(StoreBargainUserHelpServices::class);
  185. $list = $bargainUserHelpService->getHelpList((int)$id);
  186. return app('json')->success(compact('list'));
  187. }
  188. /**
  189. * 砍价统计
  190. * @param $id
  191. * @return mixed
  192. */
  193. public function bargainStatistics($id)
  194. {
  195. $data = $this->services->bargainStatistics($id);
  196. return app('json')->success($data);
  197. }
  198. /**
  199. * 砍价列表
  200. * @param $id
  201. * @return mixed
  202. */
  203. public function bargainStatisticsList($id)
  204. {
  205. $where = $this->request->getMore([
  206. ['real_name', ''],
  207. ]);
  208. $data = $this->services->bargainStatisticsList($id, $where);
  209. return app('json')->success($data);
  210. }
  211. /**
  212. * 砍价订单
  213. * @param $id
  214. * @return mixed
  215. */
  216. public function bargainStatisticsOrder($id)
  217. {
  218. $where = $this->request->getMore([
  219. ['real_name', ''],
  220. ['status', '']
  221. ]);
  222. return app('json')->success($this->services->bargainStatisticsOrder($id, $where));
  223. }
  224. }