ExportServices.php 41 KB

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