ExportServices.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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\services\other\export;
  12. use app\services\activity\bargain\StoreBargainServices;
  13. use app\services\activity\combination\StoreCombinationServices;
  14. use app\services\activity\seckill\StoreSeckillServices;
  15. use app\services\BaseServices;
  16. use app\services\order\StoreOrderServices;
  17. use app\services\product\product\StoreProductServices;
  18. use app\services\user\member\MemberCardServices;
  19. use app\services\user\UserServices;
  20. use crmeb\services\SpreadsheetExcelService;
  21. class ExportServices extends BaseServices
  22. {
  23. /**
  24. * 用户导出
  25. * @param $where
  26. * @return array
  27. */
  28. public function exportUserList($where)
  29. {
  30. /** @var UserServices $userServices */
  31. $userServices = app()->make(UserServices::class);
  32. $data = $userServices->index($where)['list'];
  33. $header = ['用户ID', '昵称', '真实姓名', '性别', '电话', '用户等级', '用户分组', '用户标签', '用户类型', '用户余额', '最后登录时间', '注册时间', '是否注销'];
  34. $filename = '用户列表_' . date('YmdHis', time());
  35. $export = $fileKey = [];
  36. if (!empty($data)) {
  37. $i = 0;
  38. foreach ($data as $item) {
  39. $one_data = [
  40. 'uid' => $item['uid'],
  41. 'nickname' => $item['nickname'],
  42. 'real_name' => $item['real_name'],
  43. 'sex' => $item['sex'],
  44. 'phone' => $item['phone'],
  45. 'level' => $item['level'],
  46. 'group_id' => $item['group_id'],
  47. 'labels' => $item['labels'],
  48. 'user_type' => $item['user_type'],
  49. 'now_money' => $item['now_money'],
  50. 'last_time' => date('Y-m-d H:i:s', $item['last_time']),
  51. 'add_time' => date('Y-m-d H:i:s', $item['add_time']),
  52. 'is_del' => $item['is_del'] ? '已注销' : '正常'
  53. ];
  54. $export[] = $one_data;
  55. if ($i == 0) {
  56. $fileKey = array_keys($one_data);
  57. }
  58. $i++;
  59. }
  60. }
  61. return compact('header', 'fileKey', 'export', 'filename');
  62. }
  63. /**
  64. * 订单导出
  65. * @param $where
  66. * @return array
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. */
  71. public function exportOrderList($where)
  72. {
  73. $header = ['订单号', '收货人姓名', '收货人电话', '收货地址', '商品名称', '规格', '数量', '价格', '总价格', '实际支付', '支付状态', '支付时间', '订单状态', '下单时间', '用户备注', '商家备注', '表单信息'];
  74. $filename = '订单列表_' . date('YmdHis', time());
  75. $export = $fileKey = [];
  76. /** @var StoreOrderServices $orderServices */
  77. $orderServices = app()->make(StoreOrderServices::class);
  78. $data = $orderServices->getOrderList($where)['data'];
  79. if (!empty($data)) {
  80. $i = 0;
  81. foreach ($data as $item) {
  82. if ($item['paid'] == 1) {
  83. switch ($item['pay_type']) {
  84. case 'weixin':
  85. $item['pay_type_name'] = '微信支付';
  86. break;
  87. case 'yue':
  88. $item['pay_type_name'] = '余额支付';
  89. break;
  90. case 'offline':
  91. $item['pay_type_name'] = '线下支付';
  92. break;
  93. default:
  94. $item['pay_type_name'] = '其他支付';
  95. break;
  96. }
  97. } else {
  98. switch ($item['pay_type']) {
  99. default:
  100. $item['pay_type_name'] = '未支付';
  101. break;
  102. case 'offline':
  103. $item['pay_type_name'] = '线下支付';
  104. break;
  105. }
  106. }
  107. if ($item['paid'] == 0 && $item['status'] == 0) {
  108. $item['status_name'] = '未支付';
  109. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
  110. $item['status_name'] = '未发货';
  111. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  112. $item['status_name'] = '未核销';
  113. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
  114. $item['status_name'] = '待收货';
  115. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  116. $item['status_name'] = '未核销';
  117. } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
  118. $item['status_name'] = '待评价';
  119. } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
  120. $item['status_name'] = '已完成';
  121. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  122. $item['status_name'] = '正在退款';
  123. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  124. $item['status_name'] = '已退款';
  125. }
  126. $custom_form = '';
  127. foreach ($item['custom_form'] as $custom_form_value) {
  128. if (is_string($custom_form_value['value'])) {
  129. $custom_form .= $custom_form_value['title'] . ':' . $custom_form_value['value'] . ';';
  130. } elseif (is_array($custom_form_value['value'])) {
  131. $custom_form .= $custom_form_value['title'] . ':' . implode(',', $custom_form_value['value']) . ';';
  132. }
  133. }
  134. // $goodsName = [];
  135. // foreach ($item['_info'] as $value) {
  136. // $_info = $value['cart_info'];
  137. // $sku = '';
  138. // if (isset($_info['productInfo']['attrInfo'])) {
  139. // if (isset($_info['productInfo']['attrInfo']['suk'])) {
  140. // $sku = '(' . $_info['productInfo']['attrInfo']['suk'] . ')';
  141. // }
  142. // }
  143. // if (isset($_info['productInfo']['store_name'])) {
  144. // $goodsName[] = implode(' ',
  145. // [$_info['productInfo']['store_name'],
  146. // $sku,
  147. // "[{$_info['cart_num']} * {$_info['truePrice']}]"
  148. // ]);
  149. // }
  150. // }
  151. // $one_data = [
  152. // 'order_id' => $item['order_id'],
  153. // 'real_name' => $item['real_name'],
  154. // 'user_phone' => $item['user_phone'],
  155. // 'user_address' => $item['user_address'],
  156. // 'goods_name' => $goodsName ? implode("\n", $goodsName) : '',
  157. // 'total_price' => $item['total_price'],
  158. // 'pay_price' => $item['pay_price'],
  159. // 'pay_type_name' => $item['pay_type_name'],
  160. // 'pay_time' => $item['pay_time'] > 0 ? date('Y-m-d H:i', (int)$item['pay_time']) : '暂无',
  161. // 'status_name' => $item['status_name'] ?? '未知状态',
  162. // 'add_time' => $item['add_time'],
  163. // 'mark' => $item['mark'],
  164. // 'remark' => $item['remark'],
  165. // 'custom_form' => $custom_form,
  166. // ];
  167. $goodsInfo = [];
  168. foreach ($item['_info'] as $value) {
  169. $goodsInfo[] = [
  170. $value['cart_info']['productInfo']['store_name'],
  171. $value['cart_info']['productInfo']['attrInfo']['suk'],
  172. $value['cart_info']['cart_num'],
  173. $value['cart_info']['truePrice'],
  174. ];
  175. }
  176. $one_data = [
  177. $item['order_id'],
  178. $item['real_name'],
  179. $item['user_phone'],
  180. $item['user_address'],
  181. $goodsInfo,
  182. $item['total_price'],
  183. $item['pay_price'],
  184. $item['pay_type_name'],
  185. $item['pay_time'] > 0 ? date('Y-m-d H:i', (int)$item['pay_time']) : '暂无',
  186. $item['status_name'] ?? '未知状态',
  187. $item['add_time'],
  188. $item['mark'],
  189. $item['remark'],
  190. $custom_form,
  191. ];
  192. $export[] = $one_data;
  193. if ($i == 0) {
  194. $fileKey = array_keys($one_data);
  195. }
  196. $i++;
  197. }
  198. }
  199. return compact('header', 'fileKey', 'export', 'filename');
  200. }
  201. /**
  202. * 订单导出
  203. * @return array
  204. * @throws \think\db\exception\DataNotFoundException
  205. * @throws \think\db\exception\DbException
  206. * @throws \think\db\exception\ModelNotFoundException
  207. */
  208. public function exportOrderDeliveryList()
  209. {
  210. $header = ['订单ID', '订单号', '快递名称', '快递编码', '快递单号', '收货人姓名', '收货人电话', '收货地址', '商品信息', '实际支付', '用户备注'];
  211. $filename = '发货单_' . date('YmdHis', time());
  212. $export = $fileKey = [];
  213. /** @var StoreOrderServices $orderServices */
  214. $orderServices = app()->make(StoreOrderServices::class);
  215. $data = $orderServices->getOrderList(['status' => 1, 'shipping_type' => 1])['data'];
  216. if (!empty($data)) {
  217. $i = 0;
  218. foreach ($data as $item) {
  219. $goodsName = [];
  220. foreach ($item['_info'] as $value) {
  221. $_info = $value['cart_info'];
  222. $sku = '';
  223. if (isset($_info['productInfo']['attrInfo'])) {
  224. if (isset($_info['productInfo']['attrInfo']['suk'])) {
  225. $sku = '(' . $_info['productInfo']['attrInfo']['suk'] . ')';
  226. }
  227. }
  228. if (isset($_info['productInfo']['store_name'])) {
  229. $goodsName[] = implode(' ',
  230. [$_info['productInfo']['store_name'],
  231. $sku,
  232. "[{$_info['cart_num']} * {$_info['truePrice']}]"
  233. ]);
  234. }
  235. }
  236. $one_data = [
  237. 'id' => $item['id'],
  238. 'order_id' => $item['order_id'],
  239. 'delivery_name' => '',
  240. 'delivery_code' => '',
  241. 'delivery_id' => '',
  242. 'real_name' => $item['real_name'],
  243. 'user_phone' => $item['user_phone'],
  244. 'user_address' => $item['user_address'],
  245. 'goods_name' => $goodsName ? implode("\n", $goodsName) : '',
  246. 'pay_price' => $item['pay_price'],
  247. 'mark' => $item['mark'],
  248. ];
  249. $export[] = $one_data;
  250. if ($i == 0) {
  251. $fileKey = array_keys($one_data);
  252. }
  253. $i++;
  254. }
  255. }
  256. return compact('header', 'fileKey', 'export', 'filename');
  257. }
  258. /**
  259. * 商品导出
  260. * @param $where
  261. * @return array
  262. */
  263. public function exportProductList($where)
  264. {
  265. $header = ['商品名称', '商品类型', '商品分类', '售价', '销量', '库存', '添加时间'];
  266. $filename = '商品列表_' . date('YmdHis', time());
  267. $export = $fileKey = [];
  268. /** @var StoreProductServices $productServices */
  269. $productServices = app()->make(StoreProductServices::class);
  270. $data = $productServices->getList($where)['list'];
  271. if (!empty($data)) {
  272. $i = 0;
  273. foreach ($data as $item) {
  274. $one_data = [
  275. 'store_name' => $item['store_name'],
  276. 'product_type' => $item['product_type'],
  277. 'cate_name' => $item['cate_name'],
  278. 'price' => $item['price'],
  279. 'sales' => $item['sales'],
  280. 'stock' => $item['stock'],
  281. 'add_time' => date('Y-m-d H:i:s', $item['add_time'])
  282. ];
  283. $export[] = $one_data;
  284. if ($i == 0) {
  285. $fileKey = array_keys($one_data);
  286. }
  287. $i++;
  288. }
  289. }
  290. return compact('header', 'fileKey', 'export', 'filename');
  291. }
  292. /**
  293. * 砍价商品导出
  294. * @param $where
  295. * @return array
  296. * @throws \think\db\exception\DataNotFoundException
  297. * @throws \think\db\exception\DbException
  298. * @throws \think\db\exception\ModelNotFoundException
  299. */
  300. public function exportBargainList($where)
  301. {
  302. $header = ['砍价名称', '起始价格', '最低价', '参与人数', '成功人数', '剩余库存', '活动状态', '活动时间', '添加时间'];
  303. $filename = '砍价列表_' . date('YmdHis', time());
  304. $export = $fileKey = [];
  305. /** @var StoreBargainServices $bargainServices */
  306. $bargainServices = app()->make(StoreBargainServices::class);
  307. $data = $bargainServices->getStoreBargainList($where)['list'];
  308. if (!empty($data)) {
  309. $i = 0;
  310. foreach ($data as $item) {
  311. $one_data = [
  312. 'title' => $item['title'],
  313. 'price' => $item['price'],
  314. 'min_price' => $item['min_price'],
  315. 'count_people_all' => $item['count_people_all'],
  316. 'count_people_success' => $item['count_people_success'],
  317. 'quota' => $item['quota'],
  318. 'start_name' => $item['start_name'],
  319. 'activity_time' => date('Y-m-d H:i:s', $item['start_time']) . '至' . date('Y-m-d H:i:s', $item['stop_time']),
  320. 'add_time' => $item['add_time']
  321. ];
  322. $export[] = $one_data;
  323. if ($i == 0) {
  324. $fileKey = array_keys($one_data);
  325. }
  326. $i++;
  327. }
  328. }
  329. return compact('header', 'fileKey', 'export', 'filename');
  330. }
  331. /**
  332. * 拼团商品导出
  333. * @param $where
  334. * @return array
  335. */
  336. public function exportCombinationList($where)
  337. {
  338. $header = ['拼团名称', '拼团价', '原价', '拼团人数', '参与人数', '成团数量', '剩余库存', '活动状态', '活动时间', '添加时间'];
  339. $filename = '拼团列表_' . date('YmdHis', time());
  340. $export = $fileKey = [];
  341. /** @var StoreCombinationServices $combinationServices */
  342. $combinationServices = app()->make(StoreCombinationServices::class);
  343. $data = $combinationServices->systemPage($where)['list'];
  344. if (!empty($data)) {
  345. $i = 0;
  346. foreach ($data as $item) {
  347. $one_data = [
  348. 'title' => $item['title'],
  349. 'price' => $item['price'],
  350. 'ot_price' => $item['ot_price'],
  351. 'count_people' => $item['count_people'],
  352. 'count_people_all' => $item['count_people_all'],
  353. 'count_people_pink' => $item['count_people_pink'],
  354. 'quota' => $item['quota'],
  355. 'start_name' => $item['start_name'],
  356. 'activity_time' => date('Y-m-d H:i:s', $item['start_time']) . '至' . date('Y-m-d H:i:s', $item['stop_time']),
  357. 'add_time' => $item['add_time']
  358. ];
  359. $export[] = $one_data;
  360. if ($i == 0) {
  361. $fileKey = array_keys($one_data);
  362. }
  363. $i++;
  364. }
  365. }
  366. return compact('header', 'fileKey', 'export', 'filename');
  367. }
  368. /**
  369. * 秒杀导出
  370. * @param $where
  371. * @return array
  372. * @throws \think\db\exception\DataNotFoundException
  373. * @throws \think\db\exception\DbException
  374. * @throws \think\db\exception\ModelNotFoundException
  375. */
  376. public function exportSeckillList($where)
  377. {
  378. $header = ['秒杀名称', '秒杀价', '原价', '剩余库存', '活动状态', '活动时间', '添加时间'];
  379. $filename = '秒杀列表_' . date('YmdHis', time());
  380. $export = $fileKey = [];
  381. /** @var StoreSeckillServices $seckillServices */
  382. $seckillServices = app()->make(StoreSeckillServices::class);
  383. $data = $seckillServices->systemPage($where)['list'];
  384. if (!empty($data)) {
  385. $i = 0;
  386. foreach ($data as $item) {
  387. $one_data = [
  388. 'title' => $item['title'],
  389. 'price' => $item['price'],
  390. 'ot_price' => $item['ot_price'],
  391. 'quota' => $item['quota'],
  392. 'start_name' => $item['start_name'],
  393. 'activity_time' => date('Y-m-d', $item['start_time']) . '至' . date('Y-m-d', $item['stop_time']),
  394. 'add_time' => $item['add_time']
  395. ];
  396. $export[] = $one_data;
  397. if ($i == 0) {
  398. $fileKey = array_keys($one_data);
  399. }
  400. $i++;
  401. }
  402. }
  403. return compact('header', 'fileKey', 'export', 'filename');
  404. }
  405. /**
  406. * 会员卡导出
  407. * @param $id
  408. * @return array
  409. * @throws \think\db\exception\DataNotFoundException
  410. * @throws \think\db\exception\DbException
  411. * @throws \think\db\exception\ModelNotFoundException
  412. */
  413. public function exportMemberCard($id)
  414. {
  415. /** @var MemberCardServices $memberCardServices */
  416. $memberCardServices = app()->make(MemberCardServices::class);
  417. $data = $memberCardServices->getExportData(['batch_card_id' => $id]);
  418. $header = ['会员卡号', '密码', '领取人', '领取人手机号', '领取时间', '是否使用'];
  419. $filename = $data['title'] . '批次列表_' . date('YmdHis', time());
  420. $export = $fileKey = [];
  421. if (!empty($data['data'])) {
  422. $userIds = array_column($data['data']->toArray(), 'use_uid');
  423. /** @var UserServices $userService */
  424. $userService = app()->make(UserServices::class);
  425. $userList = $userService->getColumn([['uid', 'in', $userIds]], 'nickname,phone,real_name', 'uid');
  426. $i = 0;
  427. foreach ($data['data'] as $item) {
  428. $one_data = [
  429. 'card_number' => $item['card_number'],
  430. 'card_password' => $item['card_password'],
  431. 'user_name' => $userList[$item['use_uid']]['real_name'] ?? $userList[$item['use_uid']]['nickname'] ?? '',
  432. 'user_phone' => $userList[$item['use_uid']]['phone'] ?? "",
  433. 'use_time' => $item['use_time'],
  434. 'use_uid' => $item['use_uid'] ? '已领取' : '未领取'
  435. ];
  436. $export[] = $one_data;
  437. if ($i == 0) {
  438. $fileKey = array_keys($one_data);
  439. }
  440. $i++;
  441. }
  442. }
  443. return compact('header', 'fileKey', 'export', 'filename');
  444. }
  445. /**
  446. * 真实请求导出
  447. * @param $header excel表头
  448. * @param $title 标题
  449. * @param array $export 填充数据
  450. * @param string $filename 保存文件名称
  451. * @param string $suffix 保存文件后缀
  452. * @param bool $is_save true|false 是否保存到本地
  453. * @return mixed
  454. */
  455. public function export($header, $title_arr, $export = [], $filename = '', $suffix = 'xlsx', $is_save = false)
  456. {
  457. $title = isset($title_arr[0]) && !empty($title_arr[0]) ? $title_arr[0] : '导出数据';
  458. $name = isset($title_arr[1]) && !empty($title_arr[1]) ? $title_arr[1] : '导出数据';
  459. $info = isset($title_arr[2]) && !empty($title_arr[2]) ? $title_arr[2] : date('Y-m-d H:i:s', time());
  460. $path = SpreadsheetExcelService::instance()->setExcelHeader($header)
  461. ->setExcelTile($title, $name, $info)
  462. ->setExcelContent($export)
  463. ->excelSave($filename, $suffix, $is_save);
  464. $path = $this->siteUrl() . $path;
  465. return [$path];
  466. }
  467. /**
  468. * 获取系统接口域名
  469. * @return string
  470. */
  471. public function siteUrl()
  472. {
  473. $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
  474. $domainName = $_SERVER['HTTP_HOST'];
  475. return $protocol . $domainName;
  476. }
  477. /**
  478. * 用户资金导出
  479. * @param $data 导出数据
  480. */
  481. public function userFinance($data = [])
  482. {
  483. $export = [];
  484. if (!empty($data)) {
  485. foreach ($data as $value) {
  486. $export[] = [
  487. $value['uid'],
  488. $value['nickname'],
  489. $value['pm'] == 0 ? '-' . $value['number'] : $value['number'],
  490. $value['title'],
  491. $value['mark'],
  492. $value['add_time'],
  493. ];
  494. }
  495. }
  496. $header = ['会员ID', '昵称', '金额/积分', '类型', '备注', '创建时间'];
  497. $title = ['资金监控', '资金监控', date('Y-m-d H:i:s', time())];
  498. $filename = '资金监控_' . date('YmdHis', time());
  499. $suffix = 'xlsx';
  500. $is_save = true;
  501. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  502. }
  503. /**
  504. * 用户佣金导出
  505. * @param $data 导出数据
  506. */
  507. public function userCommission($data = [])
  508. {
  509. $export = [];
  510. if (!empty($data)) {
  511. foreach ($data as &$value) {
  512. $export[] = [
  513. $value['nickname'],
  514. $value['sum_number'],
  515. $value['now_money'],
  516. $value['brokerage_price'],
  517. $value['extract_price'],
  518. ];
  519. }
  520. }
  521. $header = ['昵称/姓名', '总佣金金额', '账户余额', '账户佣金', '提现到账佣金'];
  522. $title = ['拥金记录', '拥金记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  523. $filename = '拥金记录_' . date('YmdHis', time());
  524. $suffix = 'xlsx';
  525. $is_save = true;
  526. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  527. }
  528. /**
  529. * 用户积分导出
  530. * @param $data 导出数据
  531. */
  532. public function userPoint($data = [])
  533. {
  534. $export = [];
  535. if (!empty($data)) {
  536. foreach ($data as $key => $item) {
  537. $export[] = [
  538. $item['id'],
  539. $item['title'],
  540. $item['balance'],
  541. $item['number'],
  542. $item['mark'],
  543. $item['nickname'],
  544. $item['add_time'],
  545. ];
  546. }
  547. }
  548. $header = ['编号', '标题', '变动前积分', '积分变动', '备注', '用户微信昵称', '添加时间'];
  549. $title = ['积分日志', '积分日志' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  550. $filename = '积分日志_' . date('YmdHis', time());
  551. $suffix = 'xlsx';
  552. $is_save = true;
  553. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  554. }
  555. /**
  556. * 用户充值导出
  557. * @param $data 导出数据
  558. */
  559. public function userRecharge($data = [])
  560. {
  561. $export = [];
  562. if (!empty($data)) {
  563. foreach ($data as $item) {
  564. $item['_pay_time'] = $item['pay_time'] ? date('Y-m-d H:i:s', $item['pay_time']) : '暂无';
  565. $item['_add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '暂无';
  566. $item['paid_type'] = $item['paid'] ? '已支付' : '未支付';
  567. $export[] = [
  568. $item['nickname'],
  569. $item['order_id'],
  570. $item['price'],
  571. $item['paid_type'],
  572. $item['_recharge_type'],
  573. $item['_pay_time'],
  574. $item['paid'] == 1 && $item['refund_price'] == $item['price'] ? '已退款' : '未退款'
  575. ];
  576. }
  577. }
  578. $header = ['昵称/姓名', '订单号', '充值金额', '是否支付', '充值类型', '支付时间', '是否退款'];
  579. $title = ['充值记录', '充值记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  580. $filename = '充值记录_' . date('YmdHis', time());
  581. $suffix = 'xlsx';
  582. $is_save = true;
  583. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  584. }
  585. /**
  586. * 用户推广导出
  587. * @param $data 导出数据
  588. */
  589. public function userAgent($data = [])
  590. {
  591. $export = [];
  592. if (!empty($data)) {
  593. foreach ($data as $index => $item) {
  594. $export[] = [
  595. $item['uid'],
  596. $item['nickname'],
  597. $item['phone'],
  598. $item['spread_count'],
  599. $item['spread_order']['order_count'],
  600. $item['spread_order']['order_price'],
  601. $item['brokerage_money'],
  602. $item['extract_count_price'],
  603. $item['extract_count_num'],
  604. $item['brokerage_price'],
  605. $item['spread_name'],
  606. ];
  607. }
  608. }
  609. $header = ['用户编号', '昵称', '电话号码', '推广用户数量', '推广订单数量', '推广订单金额', '佣金金额', '已提现金额', '提现次数', '未提现金额', '上级推广人'];
  610. $title = ['推广用户', '推广用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  611. $filename = '推广用户_' . date('YmdHis', time());
  612. $suffix = 'xlsx';
  613. $is_save = true;
  614. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  615. }
  616. /**
  617. * 微信用户导出
  618. * @param $data 导出数据
  619. */
  620. public function wechatUser($data = [])
  621. {
  622. $export = [];
  623. if (!empty($data)) {
  624. foreach ($data as $index => $item) {
  625. $export[] = [
  626. $item['nickname'],
  627. $item['sex'],
  628. $item['country'] . $item['province'] . $item['city'],
  629. $item['subscribe'] == 1 ? '关注' : '未关注',
  630. ];
  631. }
  632. }
  633. $header = ['名称', '性别', '地区', '是否关注公众号'];
  634. $title = ['微信用户导出', '微信用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  635. $filename = '微信用户导出_' . date('YmdHis', time());
  636. $suffix = 'xlsx';
  637. $is_save = true;
  638. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  639. }
  640. /**
  641. * 订单资金导出
  642. * @param $data 导出数据
  643. */
  644. public function orderFinance($data = [])
  645. {
  646. $export = [];
  647. if (!empty($data)) {
  648. foreach ($data as $info) {
  649. $time = $info['pay_time'];
  650. $price = $info['total_price'] + $info['pay_postage'];
  651. $zhichu = $info['coupon_price'] + $info['deduction_price'] + $info['cost'];
  652. $profit = ($info['total_price'] + $info['pay_postage']) - ($info['coupon_price'] + $info['deduction_price'] + $info['cost']);
  653. $deduction = $info['deduction_price'];//积分抵扣
  654. $coupon = $info['coupon_price'];//优惠
  655. $cost = $info['cost'];//成本
  656. $export[] = [$time, $price, $zhichu, $cost, $coupon, $deduction, $profit];
  657. }
  658. }
  659. $header = ['时间', '营业额(元)', '支出(元)', '成本', '优惠', '积分抵扣', '盈利(元)'];
  660. $title = ['财务统计', '财务统计', date('Y-m-d H:i:s', time())];
  661. $filename = '财务统计_' . date('YmdHis', time());
  662. $suffix = 'xlsx';
  663. $is_save = true;
  664. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  665. }
  666. /**
  667. * 商铺砍价活动导出
  668. * @param $data 导出数据
  669. */
  670. public function storeBargain($data = [])
  671. {
  672. $export = [];
  673. if (!empty($data)) {
  674. foreach ($data as $index => $item) {
  675. $export[] = [
  676. $item['title'],
  677. $item['info'],
  678. '¥' . $item['price'],
  679. $item['bargain_num'],
  680. $item['status'] ? '开启' : '关闭',
  681. empty($item['start_time']) ? '' : date('Y-m-d H:i:s', (int)$item['start_time']),
  682. empty($item['stop_time']) ? '' : date('Y-m-d H:i:s', (int)$item['stop_time']),
  683. $item['sales'],
  684. $item['quota'],
  685. empty($item['add_time']) ? '' : $item['add_time'],
  686. ];
  687. }
  688. }
  689. $header = ['砍价活动名称', '砍价活动简介', '砍价金额', '用户每次砍价的次数', '砍价状态', '砍价开启时间', '砍价结束时间', '销量', '限量', '添加时间'];
  690. $title = ['砍价商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  691. $filename = '砍价商品导出_' . date('YmdHis', time());
  692. $suffix = 'xlsx';
  693. $is_save = true;
  694. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  695. }
  696. /**
  697. * 商铺拼团导出
  698. * @param $data 导出数据
  699. */
  700. public function storeCombination($data = [])
  701. {
  702. $export = [];
  703. if (!empty($data)) {
  704. foreach ($data as $item) {
  705. $export[] = [
  706. $item['id'],
  707. $item['title'],
  708. $item['ot_price'],
  709. $item['price'],
  710. $item['quota'],
  711. $item['count_people'],
  712. $item['count_people_all'],
  713. $item['count_people_pink'],
  714. $item['sales'] ?? 0,
  715. $item['is_show'] ? '开启' : '关闭',
  716. empty($item['stop_time']) ? '' : date('Y/m/d H:i:s', (int)$item['stop_time'])
  717. ];
  718. }
  719. }
  720. $header = ['编号', '拼团名称', '原价', '拼团价', '限量', '拼团人数', '参与人数', '成团数量', '销量', '商品状态', '结束时间'];
  721. $title = ['拼团商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  722. $filename = '拼团商品导出_' . date('YmdHis', time());
  723. $suffix = 'xlsx';
  724. $is_save = true;
  725. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  726. }
  727. /**
  728. * 商铺秒杀活动导出
  729. * @param $data 导出数据
  730. */
  731. public function storeSeckill($data = [])
  732. {
  733. $export = [];
  734. if (!empty($data)) {
  735. foreach ($data as $item) {
  736. if ($item['status']) {
  737. if ($item['start_time'] > time())
  738. $item['start_name'] = '活动未开始';
  739. else if ($item['stop_time'] < time())
  740. $item['start_name'] = '活动已结束';
  741. else if ($item['stop_time'] > time() && $item['start_time'] < time())
  742. $item['start_name'] = '正在进行中';
  743. } else {
  744. $item['start_name'] = '活动已结束';
  745. }
  746. $export[] = [
  747. $item['id'],
  748. $item['title'],
  749. $item['info'],
  750. $item['ot_price'],
  751. $item['price'],
  752. $item['quota'],
  753. $item['sales'],
  754. $item['start_name'],
  755. $item['stop_time'] ? date('Y-m-d H:i:s', $item['stop_time']) : '/',
  756. $item['status'] ? '开启' : '关闭',
  757. ];
  758. }
  759. }
  760. $header = ['编号', '活动标题', '活动简介', '原价', '秒杀价', '限量', '销量', '秒杀状态', '结束时间', '状态'];
  761. $title = ['秒杀商品导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time())];
  762. $filename = '秒杀商品导出_' . date('YmdHis', time());
  763. $suffix = 'xlsx';
  764. $is_save = true;
  765. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  766. }
  767. /**
  768. * 商铺商品导出
  769. * @param $data 导出数据
  770. */
  771. public function storeProduct($data = [])
  772. {
  773. $export = [];
  774. if (!empty($data)) {
  775. foreach ($data as $index => $item) {
  776. $export[] = [
  777. $item['store_name'],
  778. $item['store_info'],
  779. $item['cate_name'],
  780. '¥' . $item['price'],
  781. $item['stock'],
  782. $item['sales'],
  783. $item['visitor'],
  784. ];
  785. }
  786. }
  787. $header = ['商品名称', '商品简介', '商品分类', '价格', '库存', '销量', '浏览量'];
  788. $title = ['商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  789. $filename = '商品导出_' . date('YmdHis', time());
  790. $suffix = 'xlsx';
  791. $is_save = true;
  792. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  793. }
  794. /**
  795. * 商铺自提点导出
  796. * @param $data 导出数据
  797. */
  798. public function storeMerchant($data = [])
  799. {
  800. $export = [];
  801. if (!empty($data)) {
  802. foreach ($data as $index => $item) {
  803. $export[] = [
  804. $item['name'],
  805. $item['phone'],
  806. $item['address'] . '' . $item['detailed_address'],
  807. $item['day_time'],
  808. $item['is_show'] ? '开启' : '关闭'
  809. ];
  810. }
  811. }
  812. $header = ['提货点名称', '提货点', '地址', '营业时间', '状态'];
  813. $title = ['提货点导出', '提货点信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  814. $filename = '提货点导出_' . date('YmdHis', time());
  815. $suffix = 'xlsx';
  816. $is_save = true;
  817. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  818. }
  819. public function memberCard($data = [])
  820. {
  821. $export = [];
  822. if (!empty($data)) {
  823. foreach ($data['data'] as $index => $item) {
  824. $export[] = [
  825. $item['card_number'],
  826. $item['card_password'],
  827. $item['user_name'],
  828. $item['user_phone'],
  829. $item['use_time'],
  830. $item['use_uid'] ? '已领取' : '未领取'
  831. ];
  832. }
  833. }
  834. $header = ['会员卡号', '密码', '领取人', '领取人手机号', '领取时间', '是否使用'];
  835. $title = ['会员卡导出', '会员卡导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  836. $filename = $data['title'] ? ("卡密会员_" . trim(str_replace(["\r\n", "\r", "\\", "\n", "/", "<", ">", "=", " "], '', $data['title']))) : "";
  837. $suffix = 'xlsx';
  838. $is_save = true;
  839. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  840. }
  841. public function tradeData($data = [], $tradeTitle = "交易统计")
  842. {
  843. $export = $header = [];
  844. if (!empty($data)) {
  845. $header = ['时间'];
  846. $headerArray = array_column($data['series'], 'name');
  847. $header = array_merge($header, $headerArray);
  848. $export = [];
  849. foreach ($data['series'] as $index => $item) {
  850. foreach ($data['x'] as $k => $v) {
  851. $export[$v]['time'] = $v;
  852. $export[$v][] = $item['value'][$k];
  853. }
  854. }
  855. }
  856. $title = [$tradeTitle, $tradeTitle, ' 生成时间:' . date('Y-m-d H:i:s', time())];
  857. $filename = $tradeTitle;
  858. $suffix = 'xlsx';
  859. $is_save = true;
  860. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  861. }
  862. /**
  863. * 商品统计
  864. * @param $data 导出数据
  865. */
  866. public function productTrade($data = [])
  867. {
  868. $export = [];
  869. if (!empty($data)) {
  870. foreach ($data as &$value) {
  871. $export[] = [
  872. $value['time'],
  873. $value['browse'],
  874. $value['user'],
  875. $value['cart'],
  876. $value['order'],
  877. $value['payNum'],
  878. $value['pay'],
  879. $value['cost'],
  880. $value['refund'],
  881. $value['refundNum'],
  882. $value['changes'] . '%'
  883. ];
  884. }
  885. }
  886. $header = ['日期/时间', '商品浏览量', '商品访客数', '加购件数', '下单件数', '支付件数', '支付金额', '成本金额', '退款金额', '退款件数', '访客-支付转化率'];
  887. $title = ['商品统计', '商品统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  888. $filename = '商品统计_' . date('YmdHis', time());
  889. $suffix = 'xlsx';
  890. $is_save = true;
  891. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  892. }
  893. public function userTrade($data = [])
  894. {
  895. $export = [];
  896. if (!empty($data)) {
  897. foreach ($data as &$value) {
  898. $export[] = [
  899. $value['time'],
  900. $value['user'],
  901. $value['browse'],
  902. $value['new'],
  903. $value['paid'],
  904. $value['vip'],
  905. ];
  906. }
  907. }
  908. $header = ['日期/时间', '访客数', '浏览量', '新增用户数', '成交用户数', '付费会员数'];
  909. $title = ['用户统计', '用户统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  910. $filename = '用户统计_' . date('YmdHis', time());
  911. $suffix = 'xlsx';
  912. $is_save = true;
  913. return $this->export($header, $title, $export, $filename, $suffix, $is_save);
  914. }
  915. }