ExportExcel.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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\export;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\activity\bargain\StoreBargainServices;
  14. use app\services\activity\combination\StoreCombinationServices;
  15. use app\services\activity\combination\StorePinkServices;
  16. use app\services\activity\seckill\StoreSeckillServices;
  17. use app\services\agent\AgentManageServices;
  18. use app\services\other\export\ExportServices;
  19. use app\services\order\StoreOrderServices;
  20. use app\services\product\product\StoreProductServices;
  21. use app\services\system\store\SystemStoreServices;
  22. use app\services\user\member\MemberCardServices;
  23. use app\services\user\UserBillServices;
  24. use app\services\user\UserRechargeServices;
  25. use app\services\wechat\WechatUserServices;
  26. use think\facade\App;
  27. /**
  28. * 导出excel类
  29. * Class ExportExcel
  30. * @package app\adminapi\controller\v1\export
  31. */
  32. class ExportExcel extends AuthController
  33. {
  34. /**
  35. * @var ExportServices
  36. */
  37. protected $service;
  38. /**
  39. * ExportExcel constructor.
  40. * @param App $app
  41. * @param ExportServices $services
  42. */
  43. public function __construct(App $app, ExportServices $services)
  44. {
  45. parent::__construct($app);
  46. $this->service = $services;
  47. }
  48. public function userList()
  49. {
  50. $where = $this->request->getMore([
  51. ['page', 1],
  52. ['limit', 20],
  53. ['nickname', ''],
  54. ['status', ''],
  55. ['pay_count', ''],
  56. ['is_promoter', ''],
  57. ['order', ''],
  58. ['data', ''],
  59. ['user_type', ''],
  60. ['country', ''],
  61. ['province', ''],
  62. ['city', ''],
  63. ['user_time_type', ''],
  64. ['user_time', ''],
  65. ['sex', ''],
  66. [['level', 0], 0],
  67. [['group_id', 'd'], 0],
  68. ['label_id', ''],
  69. ['now_money', 'normal'],
  70. ['field_key', ''],
  71. ['isMember', ''],
  72. ['ids', []]
  73. ]);
  74. return app('json')->success($this->service->exportUserList($where));
  75. }
  76. /**
  77. * 订单导出
  78. * @return mixed
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\DbException
  81. * @throws \think\db\exception\ModelNotFoundException
  82. */
  83. public function orderList()
  84. {
  85. $where = $this->request->getMore([
  86. ['status', ''],
  87. ['real_name', ''],
  88. ['is_del', ''],
  89. ['data', '', '', 'time'],
  90. ['type', ''],
  91. ['pay_type', ''],
  92. ['order', ''],
  93. ['field_key', ''],
  94. ['ids', []],
  95. ]);
  96. $where['is_system_del'] = 0;
  97. $where['pid'] = 0;
  98. return app('json')->success($this->service->exportOrderList($where));
  99. }
  100. /**
  101. * 发货订单列表导出
  102. * @return mixed
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\DbException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. */
  107. public function orderDeliveryList()
  108. {
  109. return app('json')->success($this->service->exportOrderDeliveryList());
  110. }
  111. /**
  112. * 商品列表导出
  113. * @return mixed
  114. */
  115. public function productList()
  116. {
  117. $where = $this->request->getMore([
  118. ['store_name', ''],
  119. ['cate_id', ''],
  120. ['type', 1],
  121. ['ids', []]
  122. ]);
  123. return app('json')->success($this->service->exportProductList($where));
  124. }
  125. /**
  126. * 砍价商品列表导出
  127. * @return mixed
  128. * @throws \think\db\exception\DataNotFoundException
  129. * @throws \think\db\exception\DbException
  130. * @throws \think\db\exception\ModelNotFoundException
  131. */
  132. public function bargainList()
  133. {
  134. $where = $this->request->getMore([
  135. ['status', ''],
  136. ['store_name', ''],
  137. ]);
  138. $where['is_del'] = 0;
  139. return app('json')->success($this->service->exportBargainList($where));
  140. }
  141. /**
  142. * 拼团商品导出
  143. * @return mixed
  144. */
  145. public function combinationList()
  146. {
  147. $where = $this->request->getMore([
  148. ['is_show', ''],
  149. ['store_name', '']
  150. ]);
  151. $where['is_del'] = 0;
  152. return app('json')->success($this->service->exportCombinationList($where));
  153. }
  154. /**
  155. * 秒杀商品导出
  156. * @return mixed
  157. * @throws \think\db\exception\DataNotFoundException
  158. * @throws \think\db\exception\DbException
  159. * @throws \think\db\exception\ModelNotFoundException
  160. */
  161. public function seckillList()
  162. {
  163. $where = $this->request->getMore([
  164. [['status', 's'], ''],
  165. [['store_name', 's'], '']
  166. ]);
  167. return app('json')->success($this->service->exportSeckillList($where));
  168. }
  169. /**
  170. * 会员卡导出
  171. * @param $id
  172. * @return mixed
  173. * @throws \think\db\exception\DataNotFoundException
  174. * @throws \think\db\exception\DbException
  175. * @throws \think\db\exception\ModelNotFoundException
  176. */
  177. public function memberCardList($id)
  178. {
  179. return app('json')->success($this->service->exportMemberCard($id));
  180. }
  181. /**
  182. * 保存用户资金监控的excel表格
  183. * @param UserBillServices $services
  184. * @return mixed
  185. */
  186. public function userFinance(UserBillServices $services)
  187. {
  188. $where = $this->request->getMore([
  189. ['start_time', ''],
  190. ['end_time', ''],
  191. ['nickname', ''],
  192. ['type', ''],
  193. ]);
  194. $data = $services->getBillList($where, '*', false);
  195. return app('json')->success($this->service->userFinance($data['data'] ?? []));
  196. }
  197. /**
  198. * 用户佣金
  199. * @param UserBillServices $services
  200. * @return mixed
  201. */
  202. public function userCommission(UserBillServices $services)
  203. {
  204. $where = $this->request->getMore([
  205. ['page', 1],
  206. ['limit', 20],
  207. ['nickname', ''],
  208. ['price_max', ''],
  209. ['price_min', ''],
  210. ['excel', '1'],
  211. ['time', ''],
  212. ]);
  213. $data = $services->getCommissionList($where, false);
  214. return app('json')->success($this->service->userCommission($data['list'] ?? []));
  215. }
  216. /**
  217. * 用户积分
  218. * @param UserBillServices $services
  219. * @return mixed
  220. */
  221. public function userPoint(UserBillServices $services)
  222. {
  223. $where = $this->request->getMore([
  224. ['start_time', ''],
  225. ['end_time', ''],
  226. ['nickname', ''],
  227. ['excel', '1'],
  228. ]);
  229. $data = $services->getPointList($where, '*', false);
  230. return app('json')->success($this->service->userPoint($data['list'] ?? []));
  231. }
  232. /**
  233. * 用户充值
  234. * @param UserRechargeServices $services
  235. * @return mixed
  236. */
  237. public function userRecharge(UserRechargeServices $services)
  238. {
  239. $where = $this->request->getMore([
  240. ['data', ''],
  241. ['paid', ''],
  242. ['page', 1],
  243. ['limit', 20],
  244. ['nickname', ''],
  245. ['excel', '1'],
  246. ]);
  247. $data = $services->getRechargeList($where, '*', false);
  248. return app('json')->success($this->service->userRecharge($data['list'] ?? []));
  249. }
  250. /**
  251. * 分销管理 用户推广
  252. * @param AgentManageServices $services
  253. * @return mixed
  254. * @throws \think\db\exception\DataNotFoundException
  255. * @throws \think\db\exception\DbException
  256. * @throws \think\db\exception\ModelNotFoundException
  257. */
  258. public function userAgent(AgentManageServices $services)
  259. {
  260. $where = $this->request->getMore([
  261. ['nickname', ''],
  262. ['data', ''],
  263. ['excel', '1'],
  264. ]);
  265. $data = $services->agentSystemPage($where, false);
  266. return app('json')->success($this->service->userAgent($data['list']));
  267. }
  268. /**
  269. * 微信用户导出(弃用)
  270. * @param WechatUserServices $services
  271. * @return mixed
  272. */
  273. public function wechatUser(WechatUserServices $services)
  274. {
  275. $where = $this->request->getMore([
  276. ['page', 1],
  277. ['limit', 20],
  278. ['nickname', ''],
  279. ['data', ''],
  280. ['tagid_list', ''],
  281. ['groupid', '-1'],
  282. ['sex', ''],
  283. ['export', '1'],
  284. ['subscribe', '']
  285. ]);
  286. $tagidList = explode(',', $where['tagid_list']);
  287. foreach ($tagidList as $k => $v) {
  288. if (!$v) {
  289. unset($tagidList[$k]);
  290. }
  291. }
  292. $tagidList = array_unique($tagidList);
  293. $where['tagid_list'] = implode(',', $tagidList);
  294. $data = $services->exportData($where);
  295. return app('json')->success($this->service->wechatUser($data));
  296. }
  297. /**
  298. * 商铺砍价活动导出
  299. * @param StoreBargainServices $services
  300. * @return mixed
  301. */
  302. public function storeBargain(StoreBargainServices $services)
  303. {
  304. $where = $this->request->getMore([
  305. ['start_status', ''],
  306. ['status', ''],
  307. ['store_name', ''],
  308. ]);
  309. $data = $services->getList($where);
  310. return app('json')->success($this->service->storeBargain($data));
  311. }
  312. /**
  313. * 拼团导出
  314. * @param StoreCombinationServices $services
  315. * @return mixed
  316. */
  317. public function storeCombination(StoreCombinationServices $services)
  318. {
  319. $where = $this->request->getMore([
  320. ['start_status', ''],
  321. ['is_show', ''],
  322. ['store_name', ''],
  323. ]);
  324. $data = $services->getList($where);
  325. /** @var StorePinkServices $storePinkServices */
  326. $storePinkServices = app()->make(StorePinkServices::class);
  327. $countAll = $storePinkServices->getPinkCount([]);
  328. $countTeam = $storePinkServices->getPinkCount(['k_id' => 0, 'status' => 2]);
  329. $countPeople = $storePinkServices->getPinkCount(['k_id' => 0]);
  330. foreach ($data as &$item) {
  331. $item['count_people'] = $countPeople[$item['id']] ?? 0;//拼团数量
  332. $item['count_people_all'] = $countAll[$item['id']] ?? 0;//参与人数
  333. $item['count_people_pink'] = $countTeam[$item['id']] ?? 0;//成团数量
  334. $item['stop_status'] = $item['stop_time'] < time() ? 1 : 0;
  335. if ($item['is_show']) {
  336. if ($item['start_time'] > time())
  337. $item['start_name'] = '未开始';
  338. else if ($item['stop_time'] < time())
  339. $item['start_name'] = '已结束';
  340. else if ($item['stop_time'] > time() && $item['start_time'] < time()) {
  341. $item['start_name'] = '进行中';
  342. }
  343. } else $item['start_name'] = '已结束';
  344. }
  345. return app('json')->success($this->service->storeCombination($data));
  346. }
  347. /**
  348. * 秒杀导出
  349. * @param StoreSeckillServices $services
  350. * @return mixed
  351. */
  352. public function storeSeckill(StoreSeckillServices $services)
  353. {
  354. $where = $this->request->getMore([
  355. ['start_status', ''],
  356. ['status', ''],
  357. ['store_name', '']
  358. ]);
  359. $data = $services->getList($where);
  360. return app('json')->success($this->service->storeSeckill($data));
  361. }
  362. /**
  363. * 商品导出
  364. * @param StoreProductServices $services
  365. * @return mixed
  366. */
  367. public function storeProduct(StoreProductServices $services)
  368. {
  369. $where = $this->request->getMore([
  370. ['store_name', ''],
  371. ['cate_id', ''],
  372. ['type', 1]
  373. ]);
  374. $data = $services->searchList($where, true, false);
  375. return app('json')->success($this->service->storeProduct($data['list'] ?? []));
  376. }
  377. /**
  378. * 订单列表导出
  379. * @param StoreOrderServices $services
  380. * @return mixed
  381. * @throws \think\db\exception\DataNotFoundException
  382. * @throws \think\db\exception\DbException
  383. * @throws \think\db\exception\ModelNotFoundException
  384. */
  385. public function storeOrder(StoreOrderServices $services)
  386. {
  387. $where = $this->request->getMore([
  388. ['status', ''],
  389. ['real_name', ''],
  390. ['data', '', '', 'time']
  391. ]);
  392. $where['pid'] = 0;
  393. $ids = $this->request->get('ids');
  394. if ($ids) {
  395. $idsArr = array_filter(explode(',', $ids));
  396. if ($idsArr) {
  397. $where['id'] = $idsArr;
  398. }
  399. }
  400. $data = $services->getExportList($where);
  401. return app('json')->success($this->service->storeOrder($data));
  402. }
  403. /**
  404. * 获取提货点
  405. * @param SystemStoreServices $services
  406. * @return mixed
  407. * @throws \think\db\exception\DataNotFoundException
  408. * @throws \think\db\exception\DbException
  409. * @throws \think\db\exception\ModelNotFoundException
  410. */
  411. public function storeMerchant(SystemStoreServices $services)
  412. {
  413. $where = $this->request->getMore([
  414. [['keywords', 's'], ''],
  415. [['type', 'd'], 0],
  416. ]);
  417. $data = $services->getExportData($where);
  418. return app('json')->success($this->service->storeMerchant($data));
  419. }
  420. /**
  421. * 会员卡导出
  422. * @param int $id
  423. * @param MemberCardServices $services
  424. * @return mixed
  425. * @throws \think\db\exception\DataNotFoundException
  426. * @throws \think\db\exception\DbException
  427. * @throws \think\db\exception\ModelNotFoundException
  428. */
  429. public function memberCard(int $id, MemberCardServices $services)
  430. {
  431. $data = $services->getExportData(['batch_card_id' => $id]);
  432. return app('json')->success($this->service->memberCard($data));
  433. }
  434. }