ExportExcel.php 18 KB

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