ExportExcel.php 19 KB

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