ExportExcel.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\export;
  12. use app\adminapi\controller\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\seckill\StoreSeckillServices;
  17. use app\services\agent\AgentManageServices;
  18. use app\services\other\export\ExportServices;
  19. use app\services\order\StoreOrderServices;
  20. use app\services\product\product\StoreProductServices;
  21. use app\services\system\store\SystemStoreServices;
  22. use app\services\user\member\MemberCardServices;
  23. use app\services\user\member\SecurityCodeRecordServices;
  24. use app\services\user\UserBillServices;
  25. use app\services\user\UserRechargeServices;
  26. use app\services\wechat\WechatUserServices;
  27. use think\facade\App;
  28. /**
  29. * 导出excel类
  30. * Class ExportExcel
  31. * @package app\adminapi\controller\v1\export
  32. */
  33. class ExportExcel extends AuthController
  34. {
  35. /**
  36. * @var ExportServices
  37. */
  38. protected $service;
  39. /**
  40. * ExportExcel constructor.
  41. * @param App $app
  42. * @param ExportServices $services
  43. */
  44. public function __construct(App $app, ExportServices $services)
  45. {
  46. parent::__construct($app);
  47. $this->service = $services;
  48. }
  49. public function userList()
  50. {
  51. $where = $this->request->getMore([
  52. ['page', 1],
  53. ['limit', 20],
  54. ['nickname', ''],
  55. ['status', ''],
  56. ['pay_count', ''],
  57. ['is_promoter', ''],
  58. ['order', ''],
  59. ['data', ''],
  60. ['user_type', ''],
  61. ['country', ''],
  62. ['province', ''],
  63. ['city', ''],
  64. ['city_name', ''],
  65. ['user_time_type', ''],
  66. ['user_time', ''],
  67. ['sex', ''],
  68. [['level', 0], 0],
  69. [['group_id', 'd'], 0],
  70. ['label_id', ''],
  71. ['now_money', 'normal'],
  72. ['field_key', ''],
  73. ['isMember', ''],
  74. ['ids', []]
  75. ]);
  76. return app('json')->success($this->service->exportUserList($where));
  77. }
  78. /**
  79. * 订单导出
  80. * @return mixed
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\DbException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. */
  85. public function orderList()
  86. {
  87. $where = $this->request->getMore([
  88. ['status', ''],
  89. ['real_name', ''],
  90. ['is_del', ''],
  91. ['data', '', '', 'time'],
  92. ['type', ''],
  93. ['pay_type', ''],
  94. ['order', ''],
  95. ['field_key', ''],
  96. ['ids', []],
  97. ]);
  98. $where['is_system_del'] = 0;
  99. $where['pid'] = 0;
  100. return app('json')->success($this->service->exportOrderList($where));
  101. }
  102. /**
  103. * 防伪码导出
  104. * @return mixed
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\DbException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. */
  109. public function codeList()
  110. {
  111. $where = $this->request->getMore([
  112. ['category_id', ""],
  113. ['security_code', ""],
  114. ['scan_uid', ""],
  115. ['status', ""]
  116. ]);
  117. return app('json')->success($this->service->exportCodeList($where));
  118. }
  119. /**
  120. * 发货订单列表导出
  121. * @return mixed
  122. * @throws \think\db\exception\DataNotFoundException
  123. * @throws \think\db\exception\DbException
  124. * @throws \think\db\exception\ModelNotFoundException
  125. */
  126. public function orderDeliveryList()
  127. {
  128. return app('json')->success($this->service->exportOrderDeliveryList());
  129. }
  130. /**
  131. * 商品列表导出
  132. * @return mixed
  133. */
  134. public function productList()
  135. {
  136. $where = $this->request->getMore([
  137. ['store_name', ''],
  138. ['cate_id', ''],
  139. ['type', 1],
  140. ['ids', []]
  141. ]);
  142. return app('json')->success($this->service->exportProductList($where));
  143. }
  144. /**
  145. * 砍价商品列表导出
  146. * @return mixed
  147. * @throws \think\db\exception\DataNotFoundException
  148. * @throws \think\db\exception\DbException
  149. * @throws \think\db\exception\ModelNotFoundException
  150. */
  151. public function bargainList()
  152. {
  153. $where = $this->request->getMore([
  154. ['status', ''],
  155. ['store_name', ''],
  156. ]);
  157. $where['is_del'] = 0;
  158. return app('json')->success($this->service->exportBargainList($where));
  159. }
  160. /**
  161. * 拼团商品导出
  162. * @return mixed
  163. */
  164. public function combinationList()
  165. {
  166. $where = $this->request->getMore([
  167. ['is_show', ''],
  168. ['store_name', '']
  169. ]);
  170. $where['is_del'] = 0;
  171. return app('json')->success($this->service->exportCombinationList($where));
  172. }
  173. /**
  174. * 秒杀商品导出
  175. * @return mixed
  176. * @throws \think\db\exception\DataNotFoundException
  177. * @throws \think\db\exception\DbException
  178. * @throws \think\db\exception\ModelNotFoundException
  179. */
  180. public function seckillList()
  181. {
  182. $where = $this->request->getMore([
  183. [['status', 's'], ''],
  184. [['store_name', 's'], '']
  185. ]);
  186. return app('json')->success($this->service->exportSeckillList($where));
  187. }
  188. /**
  189. * 会员卡导出
  190. * @param $id
  191. * @return mixed
  192. * @throws \think\db\exception\DataNotFoundException
  193. * @throws \think\db\exception\DbException
  194. * @throws \think\db\exception\ModelNotFoundException
  195. */
  196. public function memberCardList($id)
  197. {
  198. return app('json')->success($this->service->exportMemberCard($id));
  199. }
  200. /**
  201. * 保存用户资金监控的excel表格
  202. * @param UserBillServices $services
  203. * @return mixed
  204. */
  205. public function userFinance(UserBillServices $services)
  206. {
  207. $where = $this->request->getMore([
  208. ['start_time', ''],
  209. ['end_time', ''],
  210. ['nickname', ''],
  211. ['type', ''],
  212. ]);
  213. $data = $services->getBillList($where, '*', false);
  214. return app('json')->success($this->service->userFinance($data['data'] ?? []));
  215. }
  216. /**
  217. * 用户佣金
  218. * @param UserBillServices $services
  219. * @return mixed
  220. */
  221. public function userCommission(UserBillServices $services)
  222. {
  223. $where = $this->request->getMore([
  224. ['page', 1],
  225. ['limit', 20],
  226. ['nickname', ''],
  227. ['price_max', ''],
  228. ['price_min', ''],
  229. ['excel', '1'],
  230. ['time', ''],
  231. ]);
  232. $data = $services->getCommissionList($where, false);
  233. return app('json')->success($this->service->userCommission($data['list'] ?? []));
  234. }
  235. /**
  236. * 用户积分
  237. * @param UserBillServices $services
  238. * @return mixed
  239. */
  240. public function userPoint(UserBillServices $services)
  241. {
  242. $where = $this->request->getMore([
  243. ['start_time', ''],
  244. ['end_time', ''],
  245. ['nickname', ''],
  246. ['excel', '1'],
  247. ]);
  248. $data = $services->getPointList($where, '*', false);
  249. return app('json')->success($this->service->userPoint($data['list'] ?? []));
  250. }
  251. /**
  252. * 用户充值
  253. * @param UserRechargeServices $services
  254. * @return mixed
  255. */
  256. public function userRecharge(UserRechargeServices $services)
  257. {
  258. $where = $this->request->getMore([
  259. ['data', ''],
  260. ['paid', ''],
  261. ['page', 1],
  262. ['limit', 20],
  263. ['nickname', ''],
  264. ['excel', '1'],
  265. ]);
  266. $data = $services->getRechargeList($where, '*', false);
  267. return app('json')->success($this->service->userRecharge($data['list'] ?? []));
  268. }
  269. /**
  270. * 分销管理 用户推广
  271. * @param AgentManageServices $services
  272. * @return mixed
  273. * @throws \think\db\exception\DataNotFoundException
  274. * @throws \think\db\exception\DbException
  275. * @throws \think\db\exception\ModelNotFoundException
  276. */
  277. public function userAgent(AgentManageServices $services)
  278. {
  279. $where = $this->request->getMore([
  280. ['nickname', ''],
  281. ['data', ''],
  282. ['excel', '1'],
  283. ]);
  284. $data = $services->agentSystemPage($where, false);
  285. return app('json')->success($this->service->userAgent($data['list']));
  286. }
  287. /**
  288. * 微信用户导出(弃用)
  289. * @param WechatUserServices $services
  290. * @return mixed
  291. */
  292. public function wechatUser(WechatUserServices $services)
  293. {
  294. $where = $this->request->getMore([
  295. ['page', 1],
  296. ['limit', 20],
  297. ['nickname', ''],
  298. ['data', ''],
  299. ['tagid_list', ''],
  300. ['groupid', '-1'],
  301. ['sex', ''],
  302. ['export', '1'],
  303. ['subscribe', '']
  304. ]);
  305. $tagidList = explode(',', $where['tagid_list']);
  306. foreach ($tagidList as $k => $v) {
  307. if (!$v) {
  308. unset($tagidList[$k]);
  309. }
  310. }
  311. $tagidList = array_unique($tagidList);
  312. $where['tagid_list'] = implode(',', $tagidList);
  313. $data = $services->exportData($where);
  314. return app('json')->success($this->service->wechatUser($data));
  315. }
  316. /**
  317. * 商铺砍价活动导出
  318. * @param StoreBargainServices $services
  319. * @return mixed
  320. */
  321. public function storeBargain(StoreBargainServices $services)
  322. {
  323. $where = $this->request->getMore([
  324. ['start_status', ''],
  325. ['status', ''],
  326. ['store_name', ''],
  327. ]);
  328. $data = $services->getList($where);
  329. return app('json')->success($this->service->storeBargain($data));
  330. }
  331. /**
  332. * 拼团导出
  333. * @param StoreCombinationServices $services
  334. * @return mixed
  335. */
  336. public function storeCombination(StoreCombinationServices $services)
  337. {
  338. $where = $this->request->getMore([
  339. ['start_status', ''],
  340. ['is_show', ''],
  341. ['store_name', ''],
  342. ]);
  343. $data = $services->getList($where);
  344. /** @var StorePinkServices $storePinkServices */
  345. $storePinkServices = app()->make(StorePinkServices::class);
  346. $countAll = $storePinkServices->getPinkCount([]);
  347. $countTeam = $storePinkServices->getPinkCount(['k_id' => 0, 'status' => 2]);
  348. $countPeople = $storePinkServices->getPinkCount(['k_id' => 0]);
  349. foreach ($data as &$item) {
  350. $item['count_people'] = $countPeople[$item['id']] ?? 0;//拼团数量
  351. $item['count_people_all'] = $countAll[$item['id']] ?? 0;//参与人数
  352. $item['count_people_pink'] = $countTeam[$item['id']] ?? 0;//成团数量
  353. $item['stop_status'] = $item['stop_time'] < time() ? 1 : 0;
  354. if ($item['is_show']) {
  355. if ($item['start_time'] > time())
  356. $item['start_name'] = '未开始';
  357. else if ($item['stop_time'] < time())
  358. $item['start_name'] = '已结束';
  359. else if ($item['stop_time'] > time() && $item['start_time'] < time()) {
  360. $item['start_name'] = '进行中';
  361. }
  362. } else $item['start_name'] = '已结束';
  363. }
  364. return app('json')->success($this->service->storeCombination($data));
  365. }
  366. /**
  367. * 秒杀导出
  368. * @param StoreSeckillServices $services
  369. * @return mixed
  370. */
  371. public function storeSeckill(StoreSeckillServices $services)
  372. {
  373. $where = $this->request->getMore([
  374. ['start_status', ''],
  375. ['status', ''],
  376. ['store_name', '']
  377. ]);
  378. $data = $services->getList($where);
  379. return app('json')->success($this->service->storeSeckill($data));
  380. }
  381. /**
  382. * 商品导出
  383. * @param StoreProductServices $services
  384. * @return mixed
  385. */
  386. public function storeProduct(StoreProductServices $services)
  387. {
  388. $where = $this->request->getMore([
  389. ['store_name', ''],
  390. ['cate_id', ''],
  391. ['type', 1]
  392. ]);
  393. $data = $services->searchList($where, true, false);
  394. return app('json')->success($this->service->storeProduct($data['list'] ?? []));
  395. }
  396. /**
  397. * 订单列表导出
  398. * @param StoreOrderServices $services
  399. * @return mixed
  400. * @throws \think\db\exception\DataNotFoundException
  401. * @throws \think\db\exception\DbException
  402. * @throws \think\db\exception\ModelNotFoundException
  403. */
  404. public function storeOrder(StoreOrderServices $services)
  405. {
  406. $where = $this->request->getMore([
  407. ['status', ''],
  408. ['real_name', ''],
  409. ['data', '', '', 'time']
  410. ]);
  411. $where['pid'] = 0;
  412. $ids = $this->request->get('ids');
  413. if ($ids) {
  414. $idsArr = array_filter(explode(',', $ids));
  415. if ($idsArr) {
  416. $where['id'] = $idsArr;
  417. }
  418. }
  419. $data = $services->getExportList($where);
  420. return app('json')->success($this->service->storeOrder($data));
  421. }
  422. /**
  423. * 获取提货点
  424. * @param SystemStoreServices $services
  425. * @return mixed
  426. * @throws \think\db\exception\DataNotFoundException
  427. * @throws \think\db\exception\DbException
  428. * @throws \think\db\exception\ModelNotFoundException
  429. */
  430. public function storeMerchant(SystemStoreServices $services)
  431. {
  432. $where = $this->request->getMore([
  433. [['keywords', 's'], ''],
  434. [['type', 'd'], 0],
  435. ]);
  436. $data = $services->getExportData($where);
  437. return app('json')->success($this->service->storeMerchant($data));
  438. }
  439. /**
  440. * 会员卡导出
  441. * @param int $id
  442. * @param MemberCardServices $services
  443. * @return mixed
  444. * @throws \think\db\exception\DataNotFoundException
  445. * @throws \think\db\exception\DbException
  446. * @throws \think\db\exception\ModelNotFoundException
  447. */
  448. public function memberCard(int $id, MemberCardServices $services)
  449. {
  450. $data = $services->getExportData(['batch_card_id' => $id]);
  451. return app('json')->success($this->service->memberCard($data));
  452. }
  453. }