StoreCombination.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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\combination;
  12. use app\controller\admin\AuthController;
  13. use app\services\activity\combination\StoreCombinationServices;
  14. use app\services\activity\combination\StorePinkServices;
  15. use think\facade\App;
  16. /**
  17. * 拼团管理
  18. * Class StoreCombination
  19. * @package app\controller\admin\v1\marketing\combination
  20. */
  21. class StoreCombination extends AuthController
  22. {
  23. /**
  24. * StoreCombination constructor.
  25. * @param App $app
  26. * @param StoreCombinationServices $services
  27. */
  28. public function __construct(App $app, StoreCombinationServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * 拼团列表
  35. * @return mixed
  36. */
  37. public function index()
  38. {
  39. $where = $this->request->getMore([
  40. ['start_status', ''],
  41. ['is_show', ''],
  42. ['store_name', '']
  43. ]);
  44. $where['is_del'] = 0;
  45. $list = $this->services->systemPage($where);
  46. return $this->success($list);
  47. }
  48. /**
  49. * 拼团统计
  50. * @return mixed
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. */
  55. public function statistics()
  56. {
  57. /** @var StorePinkServices $storePinkServices */
  58. $storePinkServices = app()->make(StorePinkServices::class);
  59. $info = $storePinkServices->getStatistics();
  60. return $this->success($info);
  61. }
  62. /**
  63. * 拼团统计
  64. * @param $id
  65. * @return mixed
  66. */
  67. public function combinationStatistics($id)
  68. {
  69. $data = $this->services->combinationStatistics((int)$id);
  70. return app('json')->success($data);
  71. }
  72. /**
  73. * 活动参与人
  74. * @param $id
  75. * @return mixed
  76. */
  77. public function combinationStatisticsList($id)
  78. {
  79. /** @var StorePinkServices $storePinkServices */
  80. $storePinkServices = app()->make(StorePinkServices::class);
  81. $list = $storePinkServices->systemPage(['cid' => $id]);
  82. return app('json')->success($list);
  83. }
  84. /**
  85. * 拼团订单
  86. * @param $id
  87. * @return mixed
  88. */
  89. public function combinationStatisticsOrder($id)
  90. {
  91. $where = $this->request->getMore([
  92. ['real_name', ''],
  93. ['status', '']
  94. ]);
  95. return app('json')->success($this->services->combinationStatisticsOrder((int)$id, $where));
  96. }
  97. /**
  98. * 详情
  99. * @param $id
  100. * @return mixed
  101. */
  102. public function read($id)
  103. {
  104. $info = $info = $this->services->getInfo((int)$id);
  105. return $this->success(compact('info'));
  106. }
  107. /**
  108. * 保存新建的资源
  109. * @param int $id
  110. */
  111. public function save($id = 0)
  112. {
  113. $data = $this->request->postMore([
  114. [['product_id', 'd'], 0],
  115. [['title', 's'], ''],
  116. [['info', 's'], ''],
  117. [['unit_name', 's'], ''],
  118. ['images', []],
  119. ['section_time', []],
  120. [['is_host', 'd'], 0],
  121. [['is_show', 'd'], 0],
  122. [['num', 'd'], 0],
  123. [['temp_id', 'd'], 0],
  124. [['effective_time', 'd'], 0],
  125. [['people', 'd'], 0],
  126. [['description', 's'], ''],
  127. ['attrs', []],
  128. ['items', []],
  129. ['num', 1],
  130. ['once_num', 1],
  131. ['sort', 0],
  132. ['copy', 0],
  133. ['virtual', 100],
  134. ['is_support_refund', 1],//是否支持退款
  135. ['delivery_type', []],//物流方式
  136. ['freight', 1],//运费设置
  137. ['postage', 0],//邮费
  138. ['custom_form', ''],//自定义表单
  139. ['system_form_id', 0],//系统表单ID
  140. ['product_type', 0],//商品类型
  141. ['applicable_type', 1],//适用门店类型
  142. ['applicable_store_id', []],//适用门店IDS
  143. ]);
  144. $this->validate($data, \app\validate\admin\marketing\StoreCombinationValidate::class, 'save');
  145. if ($data['section_time']) {
  146. [$start_time, $end_time] = $data['section_time'];
  147. if (strtotime($end_time) < time()) {
  148. return $this->fail('活动结束时间不能小于当前时间');
  149. }
  150. }
  151. $bragain = [];
  152. if ($id) {
  153. $bragain = $this->services->get((int)$id);
  154. if (!$bragain) {
  155. return $this->fail('数据不存在');
  156. }
  157. }
  158. //限制编辑
  159. if ($data['copy'] == 0 && $bragain) {
  160. if ($bragain['stop_time'] < time()) {
  161. return $this->fail('活动已结束,请重新添加或复制');
  162. }
  163. }
  164. if($data['num'] < $data['once_num']){
  165. return $this->fail('限制单次购买数量不能大于总购买数量');
  166. }
  167. if ($data['copy'] == 1) {
  168. $id = 0;
  169. unset($data['copy']);
  170. }
  171. $this->services->saveData($id, $data);
  172. return $this->success('保存成功');
  173. }
  174. /**
  175. * 删除指定资源
  176. * @param int $id
  177. * @return \think\Response
  178. */
  179. public function delete($id)
  180. {
  181. $this->services->update($id, ['is_del' => 1]);
  182. $this->services->cacheTag()->clear();
  183. return $this->success('删除成功!');
  184. }
  185. /**
  186. * 修改状态
  187. * @param $id
  188. * @param $status
  189. * @return mixed
  190. */
  191. public function set_status($id, $status)
  192. {
  193. $this->services->update($id, ['is_show' => $status]);
  194. $this->services->cacheTag()->clear();
  195. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  196. }
  197. /**
  198. * 拼团列表
  199. * @return mixed
  200. */
  201. public function combine_list()
  202. {
  203. $where = $this->request->getMore([
  204. ['status', ''],
  205. ['data', '', '', 'time'],
  206. ]);
  207. /** @var StorePinkServices $storePinkServices */
  208. $storePinkServices = app()->make(StorePinkServices::class);
  209. $list = $storePinkServices->systemPage($where);
  210. return $this->success($list);
  211. }
  212. /**
  213. * 拼团人列表
  214. * @return mixed
  215. */
  216. public function order_pink($id)
  217. {
  218. /** @var StorePinkServices $storePinkServices */
  219. $storePinkServices = app()->make(StorePinkServices::class);
  220. $list = $storePinkServices->getPinkMember($id);
  221. return $this->success(compact('list'));
  222. }
  223. }