StoreBargain.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. ]);
  48. $where['is_del'] = 0;
  49. $list = $this->services->getStoreBargainList($where);
  50. return app('json')->success($list);
  51. }
  52. /**
  53. * 保存砍价商品
  54. * @param $id
  55. * @return mixed
  56. */
  57. public function save($id)
  58. {
  59. $data = $this->request->postMore([
  60. ['title', ''],
  61. ['info', ''],
  62. ['unit_name', ''],
  63. ['section_time', []],
  64. ['image', ''],
  65. ['images', []],
  66. ['bargain_max_price', 0],
  67. ['bargain_min_price', 0],
  68. ['sort', 0],
  69. ['give_integral', 0],
  70. ['is_hot', 0],
  71. ['status', 0],
  72. ['product_id', 0],
  73. ['description', ''],
  74. ['attrs', []],
  75. ['items', []],
  76. ['temp_id', 0],
  77. ['rule', ''],
  78. ['num', 1],
  79. ['copy', 0],
  80. ['bargain_num', 1],
  81. ['people_num', 1],
  82. ['logistics', []],//物流方式
  83. ['freight', 1],//运费设置
  84. ['postage', 0],//邮费
  85. ['custom_form', ''],
  86. ['virtual_type', 0],
  87. ['is_commission', 0],
  88. ]);
  89. $this->validate($data, \app\adminapi\validate\marketing\StoreBargainValidate::class, 'save');
  90. if ($data['section_time']) {
  91. [$start_time, $end_time] = $data['section_time'];
  92. if (strtotime($end_time) < time()) {
  93. return app('json')->fail(400507);
  94. }
  95. }
  96. $bragain = [];
  97. if ($id) {
  98. $bragain = $this->services->get((int)$id);
  99. if (!$bragain) {
  100. return app('json')->fail(100026);
  101. }
  102. }
  103. //限制编辑
  104. if ($data['copy'] == 0 && $bragain) {
  105. if ($bragain['stop_time'] < time()) {
  106. return app('json')->fail(400508);
  107. }
  108. }
  109. if ($data['copy'] == 1) {
  110. $id = 0;
  111. unset($data['copy']);
  112. }
  113. $this->services->saveData($id, $data);
  114. return app('json')->success(100000);
  115. }
  116. /**
  117. * 获取详情
  118. * @param $id
  119. * @return mixed
  120. */
  121. public function read($id)
  122. {
  123. $info = $this->services->getInfo($id);
  124. return app('json')->success(compact('info'));
  125. }
  126. /**
  127. * 删除砍价
  128. * @param $id
  129. * @return mixed
  130. */
  131. public function delete($id)
  132. {
  133. $this->services->update($id, ['is_del' => 1]);
  134. /** @var StoreBargainUserServices $bargainUserService */
  135. $bargainUserService = app()->make(StoreBargainUserServices::class);
  136. $bargainUserService->userBargainStatusFail($id, true);
  137. return app('json')->success(100002);
  138. }
  139. /**
  140. * 修改状态
  141. * @param $id
  142. * @param $status
  143. * @return mixed
  144. */
  145. public function set_status($id, $status)
  146. {
  147. /** @var StoreBargainUserServices $bargainUserService */
  148. $bargainUserService = app()->make(StoreBargainUserServices::class);
  149. $bargainUserService->userBargainStatusFail($id, false);
  150. $this->services->update($id, ['status' => $status]);
  151. return app('json')->success(100001);
  152. }
  153. /**
  154. * 砍价列表
  155. * @return mixed
  156. */
  157. public function bargainList()
  158. {
  159. $where = $this->request->getMore([
  160. ['status', ''],
  161. ['data', '', '', 'time'],
  162. ]);
  163. /** @var StoreBargainUserServices $bargainUserService */
  164. $bargainUserService = app()->make(StoreBargainUserServices::class);
  165. $list = $bargainUserService->bargainUserList($where);
  166. return app('json')->success($list);
  167. }
  168. /**
  169. * 砍价信息
  170. * @param $id
  171. * @return mixed
  172. */
  173. public function bargainListInfo($id)
  174. {
  175. /** @var StoreBargainUserHelpServices $bargainUserHelpService */
  176. $bargainUserHelpService = app()->make(StoreBargainUserHelpServices::class);
  177. $list = $bargainUserHelpService->getHelpList($id);
  178. return app('json')->success(compact('list'));
  179. }
  180. /**
  181. * 砍价统计
  182. * @param $id
  183. * @return mixed
  184. */
  185. public function bargainStatistics($id)
  186. {
  187. $data = $this->services->bargainStatistics($id);
  188. return app('json')->success($data);
  189. }
  190. /**
  191. * 砍价列表
  192. * @param $id
  193. * @return mixed
  194. */
  195. public function bargainStatisticsList($id)
  196. {
  197. $where = $this->request->getMore([
  198. ['real_name', ''],
  199. ]);
  200. $data = $this->services->bargainStatisticsList($id, $where);
  201. return app('json')->success($data);
  202. }
  203. /**
  204. * 砍价订单
  205. * @param $id
  206. * @return mixed
  207. */
  208. public function bargainStatisticsOrder($id)
  209. {
  210. $where = $this->request->getMore([
  211. ['real_name', ''],
  212. ['status', '']
  213. ]);
  214. return app('json')->success($this->services->bargainStatisticsOrder($id, $where));
  215. }
  216. }