ExportExcel.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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\other\export;
  12. use app\controller\admin\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\integral\StoreIntegralOrderServices;
  17. use app\services\activity\seckill\StoreSeckillServices;
  18. use app\services\agent\AgentManageServices;
  19. use app\services\order\StoreOrderInvoiceServices;
  20. use app\services\order\StoreOrderServices;
  21. use app\services\other\export\ExportServices;
  22. use app\services\other\ExpressServices;
  23. use app\services\other\queue\QueueAuxiliaryServices;
  24. use app\services\other\queue\QueueServices;
  25. use app\services\product\product\StoreProductServices;
  26. use app\services\store\finance\StoreFinanceFlowServices;
  27. use app\services\supplier\finance\SupplierFlowingWaterServices;
  28. use app\services\store\SystemStoreServices;
  29. use app\services\system\form\SystemFormDataServices;
  30. use app\services\user\member\MemberCardServices;
  31. use app\services\user\UserBillServices;
  32. use app\services\user\UserBrokerageServices;
  33. use app\services\user\UserExchangeServices;
  34. use app\services\user\UserExtractServices;
  35. use app\services\user\UserMoneyServices;
  36. use app\services\user\UserRechargeServices;
  37. use app\services\wechat\WechatUserServices;
  38. use think\facade\App;
  39. /**
  40. * 导出excel类
  41. * Class ExportExcel
  42. * @package app\controller\admin\v1\export
  43. */
  44. class ExportExcel extends AuthController
  45. {
  46. /**
  47. * @var ExportServices
  48. */
  49. protected $service;
  50. /**
  51. * ExportExcel constructor.
  52. * @param App $app
  53. * @param ExportServices $services
  54. */
  55. public function __construct(App $app, ExportServices $services)
  56. {
  57. parent::__construct($app);
  58. $this->service = $services;
  59. }
  60. /**
  61. * 保存用户资金监控的excel表格
  62. * @param UserMoneyServices $services
  63. * @return mixed
  64. */
  65. public function userFinance(UserMoneyServices $services)
  66. {
  67. $where = $this->request->getMore([
  68. ['start_time', ''],
  69. ['end_time', ''],
  70. ['nickname', ''],
  71. ['type', ''],
  72. ]);
  73. $data = $services->getMoneyList($where, '*', $this->service->limit);
  74. return $this->success($this->service->userFinance($data['data'] ?? []));
  75. }
  76. /**
  77. * 用户佣金
  78. * @param UserBrokerageServices $services
  79. * @return mixed
  80. */
  81. public function userCommission(UserBrokerageServices $services)
  82. {
  83. $where = $this->request->getMore([
  84. ['page', 1],
  85. ['limit', 20],
  86. ['nickname', ''],
  87. ['price_max', ''],
  88. ['price_min', ''],
  89. ['excel', '1'],
  90. ['date', '', '', 'time']
  91. ]);
  92. $data = $services->getCommissionList($where, $this->service->limit);
  93. return $this->success($this->service->userCommission($data['list'] ?? []));
  94. }
  95. /**
  96. * 用户积分
  97. * @param UserBillServices $services
  98. * @return mixed
  99. */
  100. public function userPoint(UserBillServices $services)
  101. {
  102. $where = $this->request->getMore([
  103. ['start_time', ''],
  104. ['end_time', ''],
  105. ['nickname', ''],
  106. ['excel', '1'],
  107. ]);
  108. $data = $services->getPointList($where, '*', $this->service->limit);
  109. return $this->success($this->service->userPoint($data['list'] ?? []));
  110. }
  111. /**
  112. * 用户充值
  113. * @param UserRechargeServices $services
  114. * @return mixed
  115. */
  116. public function userRecharge(UserRechargeServices $services)
  117. {
  118. $where = $this->request->getMore([
  119. ['data', ''],
  120. ['paid', ''],
  121. ['page', 1],
  122. ['limit', 20],
  123. ['nickname', ''],
  124. ['excel', '1'],
  125. ]);
  126. $data = $services->getRechargeList($where, '*', $this->service->limit);
  127. return $this->success($this->service->userRecharge($data['list'] ?? []));
  128. }
  129. /**
  130. * 分销管理 用户推广
  131. * @param AgentManageServices $services
  132. * @return mixed
  133. */
  134. public function userAgent(AgentManageServices $services)
  135. {
  136. $where = $this->request->getMore([
  137. ['nickname', ''],
  138. ['data', ''],
  139. ['excel', '1'],
  140. ]);
  141. $data = $services->agentSystemPage($where, $this->service->limit);
  142. return $this->success($this->service->userAgent($data['list']));
  143. }
  144. /**
  145. * 微信用户导出
  146. * @param WechatUserServices $services
  147. * @return mixed
  148. */
  149. public function wechatUser(WechatUserServices $services)
  150. {
  151. $where = $this->request->getMore([
  152. ['page', 1],
  153. ['limit', 20],
  154. ['nickname', ''],
  155. ['data', ''],
  156. ['tagid_list', ''],
  157. ['groupid', '-1'],
  158. ['sex', ''],
  159. ['export', '1'],
  160. ['subscribe', '']
  161. ]);
  162. $tagidList = explode(',', $where['tagid_list']);
  163. foreach ($tagidList as $k => $v) {
  164. if (!$v) {
  165. unset($tagidList[$k]);
  166. }
  167. }
  168. $tagidList = array_unique($tagidList);
  169. $where['tagid_list'] = implode(',', $tagidList);
  170. $data = $services->exportData($where);
  171. return $this->success($this->service->wechatUser($data));
  172. }
  173. /**
  174. * 商铺砍价活动导出
  175. * @param StoreBargainServices $services
  176. * @return mixed
  177. */
  178. public function storeBargain(StoreBargainServices $services)
  179. {
  180. $where = $this->request->getMore([
  181. ['start_status', ''],
  182. ['status', ''],
  183. ['store_name', ''],
  184. ['page', 0]
  185. ]);
  186. $where['is_del'] = 0;
  187. $page = $where['page'];
  188. unset($where['page']);
  189. $data = $services->getList($where, $page, $this->service->limit);
  190. return $this->success($this->service->storeBargain($data));
  191. }
  192. /**
  193. * 商铺拼团导出
  194. * @param StoreCombinationServices $services
  195. * @return mixed
  196. */
  197. public function storeCombination(StoreCombinationServices $services)
  198. {
  199. $where = $this->request->getMore([
  200. ['start_status', ''],
  201. ['is_show', ''],
  202. ['store_name', ''],
  203. ['page', 0]
  204. ]);
  205. $where['is_del'] = 0;
  206. $page = $where['page'];
  207. unset($where['page']);
  208. $data = $services->getList($where, $page, $this->service->limit);
  209. /** @var StorePinkServices $storePinkServices */
  210. $storePinkServices = app()->make(StorePinkServices::class);
  211. $countAll = $storePinkServices->getPinkCount([]);
  212. $countTeam = $storePinkServices->getPinkCount(['k_id' => 0, 'status' => 2]);
  213. $countPeople = $storePinkServices->getPinkCount(['k_id' => 0]);
  214. foreach ($data as &$item) {
  215. $item['count_people'] = $countPeople[$item['id']] ?? 0;//拼团数量
  216. $item['count_people_all'] = $countAll[$item['id']] ?? 0;//参与人数
  217. $item['count_people_pink'] = $countTeam[$item['id']] ?? 0;//成团数量
  218. }
  219. return $this->success($this->service->storeCombination($data));
  220. }
  221. /**
  222. * 商铺秒杀导出
  223. * @param StoreSeckillServices $services
  224. * @return mixed
  225. */
  226. public function storeSeckill(StoreSeckillServices $services)
  227. {
  228. $where = $this->request->getMore([
  229. ['start_status', ''],
  230. ['status', ''],
  231. ['store_name', ''],
  232. ['page', 0]
  233. ]);
  234. $where['is_del'] = 0;
  235. $page = $where['page'];
  236. unset($where['page']);
  237. $data = $services->getList($where, $page, $this->service->limit);
  238. return $this->success($this->service->storeSeckill($data));
  239. }
  240. /**
  241. * 导出商品卡号、卡密模版
  242. * @return mixed
  243. */
  244. public function storeProductCardTemplate()
  245. {
  246. return $this->success($this->service->storeProductCardTemplate());
  247. }
  248. /**
  249. * 商铺产品导出
  250. * @param StoreProductServices $services
  251. * @return mixed
  252. */
  253. public function storeProduct(StoreProductServices $services)
  254. {
  255. $where_tmp = $this->request->getMore([
  256. ['store_name', ''],
  257. ['cate_id', ''],
  258. ['type', 1, '', 'status'],
  259. ['ids', ''],
  260. ['supplier_id', 0],
  261. ['store_id', 0],
  262. ['store_label_id', ''],
  263. ['brand_id', '']
  264. ]);
  265. if ($where_tmp['ids']) {
  266. $where['id'] = explode(',', $where_tmp['ids']);
  267. } else {
  268. unset($where_tmp['ids']);
  269. $where = $where_tmp;
  270. }
  271. if ($where_tmp['supplier_id']) {
  272. $where['relation_id'] = $where_tmp['supplier_id'];
  273. $where['type'] = 2;
  274. } elseif ($where_tmp['store_id']) {
  275. $where['relation_id'] = $where_tmp['store_id'];
  276. $where['type'] = 1;
  277. } else {
  278. $where['pid'] = 0;
  279. }
  280. $data = $services->searchList($where, true, $this->service->limit);
  281. return $this->success($this->service->storeProduct($data['list'] ?? []));
  282. }
  283. /**
  284. * 订单列表导出
  285. * @param StoreOrderServices $services
  286. * @return mixed
  287. * @throws \think\db\exception\DataNotFoundException
  288. * @throws \think\db\exception\DbException
  289. * @throws \think\db\exception\ModelNotFoundException
  290. */
  291. public function storeOrder(StoreOrderServices $services)
  292. {
  293. $where_tmp = $this->request->getMore([
  294. ['status', ''],
  295. ['real_name', ''],
  296. ['is_del', ''],
  297. ['data', '', '', 'time'],
  298. ['type', ''],
  299. ['export_type', ''],
  300. ['pay_type', ''],
  301. ['plat_type', -1],
  302. ['order', ''],
  303. ['field_key', ''],
  304. ['store_id', ''],
  305. ['supplier_id', ''],
  306. ['ids', '']
  307. ]);
  308. $type = $where_tmp['export_type'];
  309. unset($where_tmp['export_type']);
  310. $with = [];
  311. if ($where_tmp['ids']) {
  312. $where['id'] = explode(',', $where_tmp['ids']);
  313. }
  314. if ($type) {
  315. $where['status'] = 1;
  316. $where['paid'] = 1;
  317. $where['is_del'] = 0;
  318. $where['shipping_type'] = 1;
  319. $where['pid'] = 0;
  320. $with = ['pink', 'refund' => function ($query) {
  321. $query->whereIn('refund_type', [1, 2, 4, 5])->where('is_cancel', 0)->where('is_del', 0)->field('id,store_order_id');
  322. }];
  323. }
  324. if (!$where_tmp['ids'] && !$type) {
  325. unset($where_tmp['ids']);
  326. $where = $where_tmp;
  327. }
  328. $where['is_system_del'] = 0;
  329. $where['plat_type'] = $where_tmp['plat_type'];
  330. $where['store_id'] = $where_tmp['store_id'];
  331. $where['supplier_id'] = $where_tmp['supplier_id'];
  332. if ($where['store_id'] || $where['supplier_id'] || in_array($where['plat_type'], [0, 1, 2])) {
  333. $where['pid'] = 0;
  334. } elseif (!in_array($where['status'], [-1, -2, -3])) {
  335. $where['pid'] = [0, -1];
  336. }
  337. $data = $services->getExportList($where, $with, $this->service->limit);
  338. return $this->success($this->service->storeOrder($data, $type));
  339. }
  340. /**
  341. * 订单列表导出
  342. * @param UserExtractServices $services
  343. * @return mixed
  344. * @throws \think\db\exception\DataNotFoundException
  345. * @throws \think\db\exception\DbException
  346. * @throws \think\db\exception\ModelNotFoundException
  347. */
  348. public function extract(UserExtractServices $services)
  349. {
  350. $where = $this->request->getMore([
  351. ['status', ''],
  352. ['extract_type', ''],
  353. ['nireid', '', '', 'like'],
  354. ['data', '', '', 'time'],
  355. ]);
  356. if (isset($where['extract_type']) && $where['extract_type'] == 'wx') {
  357. $where['extract_type'] = 'weixin';
  358. }
  359. $data = $services->getExportList($where);
  360. return $this->success($this->service->extract($data));
  361. }
  362. /**
  363. * 订单列表导出
  364. * @param UserExtractServices $services
  365. * @return mixed
  366. * @throws \think\db\exception\DataNotFoundException
  367. * @throws \think\db\exception\DbException
  368. * @throws \think\db\exception\ModelNotFoundException
  369. */
  370. public function exchange(UserExchangeServices $services)
  371. {
  372. $where = $this->request->getMore([
  373. ['status', ''],
  374. ['nireid', '', '', 'like'],
  375. ['data', '', '', 'time'],
  376. ]);
  377. $data = $services->getExportList($where);
  378. return $this->success($this->service->exchange($data));
  379. }
  380. /**
  381. * 订单列表导出
  382. * @param UserExtractServices $services
  383. * @return mixed
  384. * @throws \think\db\exception\DataNotFoundException
  385. * @throws \think\db\exception\DbException
  386. * @throws \think\db\exception\ModelNotFoundException
  387. */
  388. public function extractMonthInfo(UserExtractServices $services)
  389. {
  390. $where = $this->request->getMore([
  391. ['month', ''],
  392. ]);
  393. if ($where['month']) {
  394. $time_start = strtotime($where['month'] . '-1');
  395. } else {
  396. $time_start = strtotime(date('Y-m') . '-1');
  397. }
  398. $time_end = strtotime('+1 month', $time_start) - 1;
  399. $data = $services->getExportInfoList($time_start, $time_end);
  400. return $this->success($this->service->extractInfo($data, 1, $where['month']));
  401. }
  402. /**
  403. * 获取提货点
  404. * @return mixed
  405. */
  406. public function storeMerchant(SystemStoreServices $services)
  407. {
  408. $where = $this->request->getMore([
  409. [['keywords', 's'], ''],
  410. [['type', 'd'], 0],
  411. ]);
  412. $data = $services->getExportData($where);
  413. return $this->success($this->service->storeMerchant($data));
  414. }
  415. /**
  416. * 会员卡导出
  417. * @param int $id
  418. * @param MemberCardServices $services
  419. * @return mixed
  420. * @throws \think\db\exception\DataNotFoundException
  421. * @throws \think\db\exception\DbException
  422. * @throws \think\db\exception\ModelNotFoundException
  423. */
  424. public function memberCard(int $id, MemberCardServices $services)
  425. {
  426. $data = $services->getExportData(['batch_card_id' => $id], $this->service->limit);
  427. return $this->success($this->service->memberCard($data));
  428. }
  429. /**
  430. * 导出批量任务发货的记录
  431. * @param int $id
  432. * @return mixed
  433. * @throws \think\db\exception\DataNotFoundException
  434. * @throws \think\db\exception\DbException
  435. * @throws \think\db\exception\ModelNotFoundException
  436. */
  437. public function batchOrderDelivery($id, $queueType, $cacheType)
  438. {
  439. /** @var QueueAuxiliaryServices $auxiliaryService */
  440. $auxiliaryService = app()->make(QueueAuxiliaryServices::class);
  441. /** @var QueueServices $queueService */
  442. $queueService = app()->make(QueueServices::class);
  443. $queueInfo = $queueService->getQueueOne(['id' => $id]);
  444. if (!$queueInfo) $this->fail("数据不存在");
  445. $queueValue = json_decode($queueInfo['queue_in_value'], true);
  446. if (!$queueValue || !isset($queueValue['cacheType'])) $this->fail("数据参数缺失");
  447. $data = $auxiliaryService->getExportData(['binding_id' => $id, 'type' => $cacheType], $this->service->limit);
  448. return $this->success($this->service->batchOrderDelivery($data, $queueType));
  449. }
  450. /**
  451. * 物流公司表导出
  452. * @return mixed
  453. */
  454. public function expressList()
  455. {
  456. /** @var ExpressServices $expressService */
  457. $expressService = app()->make(ExpressServices::class);
  458. $data = $expressService->apiExpressList();
  459. return $this->success($this->service->expressList($data));
  460. }
  461. /**
  462. * 导出积分兑换订单
  463. * @param StoreIntegralOrderServices $services
  464. * @return mixed
  465. * @throws \think\db\exception\DataNotFoundException
  466. * @throws \think\db\exception\DbException
  467. * @throws \think\db\exception\ModelNotFoundException
  468. */
  469. public function storeIntegralOrder(StoreIntegralOrderServices $services)
  470. {
  471. $where = $this->request->getMore([
  472. ['status', ''],
  473. ['real_name', ''],
  474. ['data', '', '', 'time'],
  475. ['order', ''],
  476. ['field_key', ''],
  477. ['product_id', '']
  478. ]);
  479. $where['is_system_del'] = 0;
  480. $data = $services->getExportList($where, $this->service->limit);
  481. return $this->success($this->service->storeIntegralOrder($data));
  482. }
  483. /**
  484. * 门店账单下载
  485. * @param StoreFinanceFlowServices $services
  486. * @return mixed
  487. */
  488. public function financeRecord(StoreFinanceFlowServices $services)
  489. {
  490. [$ids] = $this->request->getMore([
  491. ['ids', ''],
  492. ['store_id', 0]
  493. ], true);
  494. $where['id'] = $ids ? explode(',', $ids) : [];
  495. $where['is_del'] = 0;
  496. $data = $services->getList($where);
  497. return $this->success($this->service->financeRecord($data['list'] ?? []));
  498. }
  499. /**
  500. * 门店流水导出
  501. * @param StoreFinanceFlowServices $services
  502. * @return mixed
  503. */
  504. public function flowExport(StoreFinanceFlowServices $services)
  505. {
  506. $where = $this->request->getMore([
  507. ['store_id', 0],
  508. ['keyword', ''],
  509. ['data', '', '', 'time'],
  510. ]);
  511. $where['is_del'] = 0;
  512. $where['trade_type'] = 1;
  513. $where['no_type'] = 2;
  514. $data = $services->getList($where);
  515. return $this->success($this->service->financeRecord($data['list'] ?? [], '门店流水导出'));
  516. }
  517. /**
  518. * 供应商资金流水导出
  519. * @param SupplierFlowingWaterServices $services
  520. * @return mixed
  521. */
  522. public function waterExport(SupplierFlowingWaterServices $services)
  523. {
  524. $where = $this->request->getMore([
  525. ['supplier_id', 0],
  526. ['keyword', ''],
  527. ['data', '', '', 'time'],
  528. ]);
  529. $where['is_del'] = 0;
  530. $data = $services->getList($where);
  531. return $this->success($this->service->SupplierFinanceRecord($data['list'] ?? [], '供应商资金流水导出'));
  532. }
  533. /**
  534. * 供应商账单下载
  535. * @param SupplierFlowingWaterServices $services
  536. * @return mixed
  537. */
  538. public function waterRecord(SupplierFlowingWaterServices $services)
  539. {
  540. [$ids] = $this->request->getMore([
  541. ['ids', ''],
  542. ['supplier_id', 0]
  543. ], true);
  544. $where['id'] = $ids ? explode(',', $ids) : [];
  545. $where['is_del'] = 0;
  546. $data = $services->getList($where);
  547. return $this->success($this->service->SupplierFinanceRecord($data['list'] ?? []));
  548. }
  549. /**
  550. * 发票导出
  551. * @param StoreOrderInvoiceServices $services
  552. * @return mixed
  553. */
  554. public function invoiceExport(StoreOrderInvoiceServices $services)
  555. {
  556. $where = $this->request->getMore([
  557. ['status', 0],
  558. ['real_name', ''],
  559. ['header_type', ''],
  560. ['type', ''],
  561. ['data', '', '', 'time'],
  562. ['field_key', ''],
  563. ]);
  564. $data = $services->getList($where);
  565. return $this->success($this->service->invoiceRecord($data['list'] ?? []));
  566. }
  567. /**
  568. * 系统表单收集数据导出
  569. * @param SystemFormDataServices $systemFormDataServices
  570. * @param $id
  571. * @return mixed
  572. * @throws \think\db\exception\DataNotFoundException
  573. * @throws \think\db\exception\DbException
  574. * @throws \think\db\exception\ModelNotFoundException'
  575. */
  576. public function systemFormDataExport(SystemFormDataServices $systemFormDataServices, $id)
  577. {
  578. $where = $this->request->postMore([
  579. ['data', '', '', 'time']
  580. ]);
  581. $data = $systemFormDataServices->getFormDataList((int)$id, $where);
  582. return $this->success($this->service->systemFormData($data['list'] ?? []));
  583. }
  584. }