StoreBargain.php 6.5 KB

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