ExportExcel.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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. $data = $services->getExportList($where, $with, $this->service->limit);
  331. return $this->success($this->service->storeOrder($data, $type));
  332. }
  333. /**
  334. * 获取提货点
  335. * @return mixed
  336. */
  337. public function storeMerchant(SystemStoreServices $services)
  338. {
  339. $where = $this->request->getMore([
  340. [['keywords', 's'], ''],
  341. [['type', 'd'], 0],
  342. ]);
  343. $data = $services->getExportData($where);
  344. return $this->success($this->service->storeMerchant($data));
  345. }
  346. /**
  347. * 会员卡导出
  348. * @param int $id
  349. * @param MemberCardServices $services
  350. * @return mixed
  351. * @throws \think\db\exception\DataNotFoundException
  352. * @throws \think\db\exception\DbException
  353. * @throws \think\db\exception\ModelNotFoundException
  354. */
  355. public function memberCard(int $id, MemberCardServices $services)
  356. {
  357. $data = $services->getExportData(['batch_card_id' => $id], $this->service->limit);
  358. return $this->success($this->service->memberCard($data));
  359. }
  360. /**
  361. * 导出批量任务发货的记录
  362. * @param int $id
  363. * @return mixed
  364. * @throws \think\db\exception\DataNotFoundException
  365. * @throws \think\db\exception\DbException
  366. * @throws \think\db\exception\ModelNotFoundException
  367. */
  368. public function batchOrderDelivery($id, $queueType, $cacheType)
  369. {
  370. /** @var QueueAuxiliaryServices $auxiliaryService */
  371. $auxiliaryService = app()->make(QueueAuxiliaryServices::class);
  372. /** @var QueueServices $queueService */
  373. $queueService = app()->make(QueueServices::class);
  374. $queueInfo = $queueService->getQueueOne(['id' => $id]);
  375. if (!$queueInfo) $this->fail("数据不存在");
  376. $queueValue = json_decode($queueInfo['queue_in_value'], true);
  377. if (!$queueValue || !isset($queueValue['cacheType'])) $this->fail("数据参数缺失");
  378. $data = $auxiliaryService->getExportData(['binding_id' => $id, 'type' => $cacheType], $this->service->limit);
  379. return $this->success($this->service->batchOrderDelivery($data, $queueType));
  380. }
  381. /**
  382. * 物流公司表导出
  383. * @return mixed
  384. */
  385. public function expressList()
  386. {
  387. /** @var ExpressServices $expressService */
  388. $expressService = app()->make(ExpressServices::class);
  389. $data = $expressService->apiExpressList();
  390. return $this->success($this->service->expressList($data));
  391. }
  392. /**
  393. * 导出积分兑换订单
  394. * @param StoreIntegralOrderServices $services
  395. * @return mixed
  396. * @throws \think\db\exception\DataNotFoundException
  397. * @throws \think\db\exception\DbException
  398. * @throws \think\db\exception\ModelNotFoundException
  399. */
  400. public function storeIntegralOrder(StoreIntegralOrderServices $services)
  401. {
  402. $where = $this->request->getMore([
  403. ['status', ''],
  404. ['real_name', ''],
  405. ['data', '', '', 'time'],
  406. ['order', ''],
  407. ['field_key', ''],
  408. ['product_id', '']
  409. ]);
  410. $where['is_system_del'] = 0;
  411. $data = $services->getExportList($where, $this->service->limit);
  412. return $this->success($this->service->storeIntegralOrder($data));
  413. }
  414. /**
  415. * 门店账单下载
  416. * @param StoreFinanceFlowServices $services
  417. * @return mixed
  418. */
  419. public function financeRecord(StoreFinanceFlowServices $services)
  420. {
  421. [$ids] = $this->request->getMore([
  422. ['ids', ''],
  423. ['store_id', 0]
  424. ], true);
  425. $where['id'] = $ids ? explode(',', $ids) : [];
  426. $where['is_del'] = 0;
  427. $data = $services->getList($where);
  428. return $this->success($this->service->financeRecord($data['list'] ?? []));
  429. }
  430. /**
  431. * 门店流水导出
  432. * @param StoreFinanceFlowServices $services
  433. * @return mixed
  434. */
  435. public function flowExport(StoreFinanceFlowServices $services)
  436. {
  437. $where = $this->request->getMore([
  438. ['store_id', 0],
  439. ['keyword', ''],
  440. ['data', '', '', 'time'],
  441. ]);
  442. $where['is_del'] = 0;
  443. $where['trade_type'] = 1;
  444. $where['no_type'] = 2;
  445. $data = $services->getList($where);
  446. return $this->success($this->service->financeRecord($data['list'] ?? [], '门店流水导出'));
  447. }
  448. /**
  449. * 供应商资金流水导出
  450. * @param SupplierFlowingWaterServices $services
  451. * @return mixed
  452. */
  453. public function waterExport(SupplierFlowingWaterServices $services)
  454. {
  455. $where = $this->request->getMore([
  456. ['supplier_id', 0],
  457. ['keyword', ''],
  458. ['data', '', '', 'time'],
  459. ]);
  460. $where['is_del'] = 0;
  461. $data = $services->getList($where);
  462. return $this->success($this->service->SupplierFinanceRecord($data['list'] ?? [], '供应商资金流水导出'));
  463. }
  464. /**
  465. * 供应商账单下载
  466. * @param SupplierFlowingWaterServices $services
  467. * @return mixed
  468. */
  469. public function waterRecord(SupplierFlowingWaterServices $services)
  470. {
  471. [$ids] = $this->request->getMore([
  472. ['ids', ''],
  473. ['supplier_id', 0]
  474. ], true);
  475. $where['id'] = $ids ? explode(',', $ids) : [];
  476. $where['is_del'] = 0;
  477. $data = $services->getList($where);
  478. return $this->success($this->service->SupplierFinanceRecord($data['list'] ?? []));
  479. }
  480. /**
  481. * 发票导出
  482. * @param StoreOrderInvoiceServices $services
  483. * @return mixed
  484. */
  485. public function invoiceExport(StoreOrderInvoiceServices $services)
  486. {
  487. $where = $this->request->getMore([
  488. ['status', 0],
  489. ['real_name', ''],
  490. ['header_type', ''],
  491. ['type', ''],
  492. ['data', '', '', 'time'],
  493. ['field_key', ''],
  494. ]);
  495. $data = $services->getList($where);
  496. return $this->success($this->service->invoiceRecord($data['list'] ?? []));
  497. }
  498. /**
  499. * 系统表单收集数据导出
  500. * @param SystemFormDataServices $systemFormDataServices
  501. * @param $id
  502. * @return mixed
  503. * @throws \think\db\exception\DataNotFoundException
  504. * @throws \think\db\exception\DbException
  505. * @throws \think\db\exception\ModelNotFoundException'
  506. */
  507. public function systemFormDataExport(SystemFormDataServices $systemFormDataServices, $id)
  508. {
  509. $where = $this->request->postMore([
  510. ['data', '', '', 'time']
  511. ]);
  512. $data = $systemFormDataServices->getFormDataList((int)$id, $where);
  513. return $this->success($this->service->systemFormData($data['list'] ?? []));
  514. }
  515. }