ExportExcel.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\supplier\export;
  12. use app\controller\supplier\AuthController;
  13. use app\services\other\export\ExportServices;
  14. use app\services\order\StoreOrderServices;
  15. use app\services\other\ExpressServices;
  16. use app\services\other\queue\QueueAuxiliaryServices;
  17. use app\services\other\queue\QueueServices;
  18. use app\services\supplier\finance\SupplierFlowingWaterServices;
  19. use think\facade\App;
  20. /**
  21. * 导出excel类
  22. * Class ExportExcel
  23. * @package app\controller\supplier\export
  24. */
  25. class ExportExcel extends AuthController
  26. {
  27. /**
  28. * @var ExportServices
  29. */
  30. protected $service;
  31. /**
  32. * ExportExcel constructor.
  33. * @param App $app
  34. * @param ExportServices $services
  35. */
  36. public function __construct(App $app, ExportServices $services)
  37. {
  38. parent::__construct($app);
  39. $this->service = $services;
  40. }
  41. /**
  42. * 订单列表导出
  43. * @param StoreOrderServices $services
  44. * @return mixed
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function storeOrder(StoreOrderServices $services)
  50. {
  51. $where_tmp = $this->request->getMore([
  52. ['status', ''],
  53. ['real_name', ''],
  54. ['data', '', '', 'time'],
  55. ['type', ''],
  56. ['ids', '']
  57. ]);
  58. $type = $where_tmp['type'];
  59. $with = [];
  60. if ($where_tmp['ids']) {
  61. $where['id'] = explode(',', $where_tmp['ids']);
  62. }
  63. if ($type) {
  64. $where['status'] = 1;
  65. $where['paid'] = 1;
  66. $where['is_del'] = 0;
  67. $where['is_system_del'] = 0;
  68. $with = ['pink', 'refund' => function ($query) {
  69. $query->whereIn('refund_type', [1, 2, 4, 5])->where('is_cancel', 0)->where('is_del', 0)->field('id,store_order_id');
  70. }];
  71. }
  72. if (!$where_tmp['ids'] && !$type) {
  73. unset($where_tmp['ids']);
  74. unset($where_tmp['type']);
  75. $where = $where_tmp;
  76. }
  77. if (!$where_tmp['real_name'] && !in_array($where_tmp['status'], [-1, -2, -3])) {
  78. $where['pid'] = 0;
  79. }
  80. $where['is_system_del'] = 0;
  81. $where['supplier_id'] = $this->supplierId;
  82. $data = $services->getExportList($where, $with, $this->service->limit);
  83. return $this->success($this->service->storeOrder($data, $type));
  84. }
  85. /**
  86. * 导出批量任务发货的记录
  87. * @param int $id
  88. * @return mixed
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\DbException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. */
  93. public function batchOrderDelivery($id, $queueType, $cacheType)
  94. {
  95. /** @var QueueAuxiliaryServices $auxiliaryService */
  96. $auxiliaryService = app()->make(QueueAuxiliaryServices::class);
  97. /** @var QueueServices $queueService */
  98. $queueService = app()->make(QueueServices::class);
  99. $queueInfo = $queueService->getQueueOne(['id' => $id]);
  100. if (!$queueInfo) return $this->fail("数据不存在");
  101. $queueValue = json_decode($queueInfo['queue_in_value'], true);
  102. if (!$queueValue || !isset($queueValue['cacheType'])) return $this->fail("数据参数缺失");
  103. $data = $auxiliaryService->getExportData(['binding_id' => $id, 'type' => $cacheType], $this->service->limit);
  104. return $this->success($this->service->batchOrderDelivery($data, $queueType));
  105. }
  106. /**
  107. * 物流公司表导出
  108. * @return mixed
  109. */
  110. public function expressList()
  111. {
  112. /** @var ExpressServices $expressService */
  113. $expressService = app()->make(ExpressServices::class);
  114. $data = $expressService->apiExpressList();
  115. return $this->success($this->service->expressList($data));
  116. }
  117. /**
  118. * 供应商账单下载
  119. * @param SupplierFlowingWaterServices $services
  120. * @return mixed
  121. */
  122. public function financeRecord(SupplierFlowingWaterServices $services)
  123. {
  124. [$ids] = $this->request->getMore([
  125. ['ids', '']
  126. ], true);
  127. $where['id'] = $ids ? explode(',', $ids) : [];
  128. $where['is_del'] = 0;
  129. $where['supplier_id'] = $this->supplierId;
  130. $data = $services->getList($where);
  131. return $this->success($this->service->SupplierFinanceRecord($data['list'] ?? []));
  132. }
  133. }