StoreBargain.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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\admin\v1\marketing\bargain;
  12. use app\controller\admin\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\controller\admin\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. *
  37. * @return \think\Response
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['start_status', ''],
  43. ['status', ''],
  44. ['store_name', ''],
  45. ]);
  46. $where['is_del'] = 0;
  47. $list = $this->services->getStoreBargainList($where);
  48. return $this->success($list);
  49. }
  50. /**
  51. * 保存新建的资源
  52. *
  53. * @param \think\Request $request
  54. * @return \think\Response
  55. */
  56. public function save($id)
  57. {
  58. $data = $this->request->postMore([
  59. ['title', ''],
  60. ['info', ''],
  61. ['unit_name', ''],
  62. ['section_time', []],
  63. ['images', []],
  64. ['bargain_max_price', 0],
  65. ['bargain_min_price', 0],
  66. ['sort', 0],
  67. ['give_integral', 0],
  68. ['is_hot', 0],
  69. ['status', 0],
  70. ['product_id', 0],
  71. ['description', ''],
  72. ['attrs', []],
  73. ['items', []],
  74. ['temp_id', 0],
  75. ['rule', ''],
  76. ['num', 1],
  77. ['copy', 0],
  78. ['bargain_num', 1],
  79. ['people_num', 1],
  80. ['is_support_refund', 1],//是否支持退款
  81. ['delivery_type', []],//物流方式
  82. ['freight', 1],//运费设置
  83. ['postage', 0],//邮费
  84. ['custom_form', ''],//自定义表单
  85. ['system_form_id', 0],//系统表单ID
  86. ['product_type', 0],//商品类型
  87. ['applicable_type', 1],//适用门店类型
  88. ['applicable_store_id', []],//适用门店IDS
  89. ]);
  90. $this->validate($data, \app\validate\admin\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 $this->fail('活动结束时间不能小于当前时间');
  95. }
  96. }
  97. $bragain = [];
  98. if ($id) {
  99. $bragain = $this->services->get((int)$id);
  100. if (!$bragain) {
  101. return $this->fail('数据不存在');
  102. }
  103. }
  104. //限制编辑
  105. if ($data['copy'] == 0 && $bragain) {
  106. if ($bragain['stop_time'] < time()) {
  107. return $this->fail('活动已结束,请重新添加或复制');
  108. }
  109. }
  110. if ($data['copy'] == 1) {
  111. $id = 0;
  112. unset($data['copy']);
  113. }
  114. $this->services->saveData($id, $data);
  115. return $this->success('保存成功');
  116. }
  117. /**
  118. * 显示指定的资源
  119. *
  120. * @param int $id
  121. * @return \think\Response
  122. */
  123. public function read($id)
  124. {
  125. $info = $this->services->getInfo($id);
  126. return $this->success(compact('info'));
  127. }
  128. /**
  129. * 删除指定资源
  130. *
  131. * @param int $id
  132. * @return \think\Response
  133. */
  134. public function delete($id)
  135. {
  136. $this->services->update($id, ['is_del' => 1]);
  137. $this->services->cacheTag()->clear();
  138. return $this->success('删除成功!');
  139. }
  140. /**
  141. * 修改状态
  142. * @param $id
  143. * @param $status
  144. * @return mixed
  145. */
  146. public function set_status($id, $status)
  147. {
  148. $this->services->update($id, ['status' => $status]);
  149. $this->services->cacheTag()->clear();
  150. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  151. }
  152. /**
  153. * 砍价列表
  154. * @return mixed
  155. */
  156. public function bargainList()
  157. {
  158. $where = $this->request->getMore([
  159. ['status', ''],
  160. ['data', '', '', 'time'],
  161. ]);
  162. /** @var StoreBargainUserServices $bargainUserService */
  163. $bargainUserService = app()->make(StoreBargainUserServices::class);
  164. $list = $bargainUserService->bargainUserList($where);
  165. return $this->success($list);
  166. }
  167. /**
  168. * 砍价信息
  169. * @param $id
  170. * @return mixed
  171. */
  172. public function bargainListInfo($id)
  173. {
  174. /** @var StoreBargainUserHelpServices $bargainUserHelpService */
  175. $bargainUserHelpService = app()->make(StoreBargainUserHelpServices::class);
  176. $list = $bargainUserHelpService->getHelpList($id);
  177. return $this->success(compact('list'));
  178. }
  179. /**
  180. * 砍价统计
  181. * @param $id
  182. * @return mixed
  183. */
  184. public function bargainStatistics($id)
  185. {
  186. $data = $this->services->bargainStatistics((int)$id);
  187. return app('json')->success($data);
  188. }
  189. /**
  190. * 砍价统计列表
  191. * @param $id
  192. * @return mixed
  193. */
  194. public function bargainStatisticsList($id)
  195. {
  196. $where = $this->request->getMore([
  197. ['real_name', ''],
  198. ]);
  199. $data = $this->services->bargainStatisticsList((int)$id, $where);
  200. return app('json')->success($data);
  201. }
  202. /**
  203. * 砍价统计订单
  204. * @param $id
  205. * @return mixed
  206. */
  207. public function bargainStatisticsOrder($id)
  208. {
  209. $where = $this->request->getMore([
  210. ['real_name', ''],
  211. ['status', '']
  212. ]);
  213. return app('json')->success($this->services->bargainStatisticsOrder((int)$id, $where));
  214. }
  215. }