ExportRepositories.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <?php
  2. namespace crmeb\repositories;
  3. use crmeb\services\SpreadsheetExcelService;
  4. /**
  5. * Class ExportRepositories
  6. * @package crmeb\repositories
  7. */
  8. class ExportRepositories
  9. {
  10. /**
  11. * 真实请求导出
  12. * @param $header excel表头
  13. * @param $title 标题
  14. * @param array $export 填充数据
  15. * @param string $filename 保存文件名称
  16. * @param string $suffix 保存文件后缀
  17. * @param bool $is_save true|false 是否保存到本地
  18. * @return mixed
  19. */
  20. public static function export($header, $title_arr, $export = [], $filename = '', $suffix = 'xlsx', $is_save = false)
  21. {
  22. $title = isset($title_arr[0]) && !empty($title_arr[0]) ? $title_arr[0] : '导出数据';
  23. $name = isset($title_arr[1]) && !empty($title_arr[1]) ? $title_arr[1] : '导出数据';
  24. $info = isset($title_arr[2]) && !empty($title_arr[2]) ? $title_arr[2] : date('Y-m-d H:i:s', time());
  25. $path = SpreadsheetExcelService::instance()->setExcelHeader($header)
  26. ->setExcelTile($title, $name, $info)
  27. ->setExcelContent($export)
  28. ->excelSave($filename, $suffix, $is_save);
  29. $path = self::siteUrl() . $path;
  30. return [$path];
  31. }
  32. public static function siteUrl()
  33. {
  34. $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
  35. $domainName = $_SERVER['HTTP_HOST'];
  36. return $protocol . $domainName;
  37. }
  38. /**
  39. * 用户资金导出
  40. * @param $data 导出数据
  41. */
  42. public static function userFinance($data = [])
  43. {
  44. $export = [];
  45. if (!empty($data)) {
  46. foreach ($data as $value) {
  47. $export[] = [
  48. $value['uid'],
  49. $value['nickname'],
  50. $value['pm'] == 0 ? '-' . $value['number'] : $value['number'],
  51. $value['title'],
  52. $value['mark'],
  53. $value['add_time'],
  54. ];
  55. }
  56. }
  57. $header = ['会员ID', '昵称', '金额/积分', '类型', '备注', '创建时间'];
  58. $title = ['资金监控', '资金监控', date('Y-m-d H:i:s', time())];
  59. $filename = '';
  60. $suffix = 'xlsx';
  61. $is_save = true;
  62. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  63. }
  64. /**
  65. * 用户佣金导出
  66. * @param $data 导出数据
  67. */
  68. public static function userCommission($data = [])
  69. {
  70. $export = [];
  71. if (!empty($data)) {
  72. foreach ($data as &$value) {
  73. $export[] = [
  74. $value['nickname'],
  75. $value['sum_number'],
  76. $value['now_money'],
  77. $value['brokerage_price'],
  78. $value['extract_price'],
  79. ];
  80. }
  81. }
  82. $header = ['昵称/姓名', '总佣金金额', '账户余额', '账户佣金', '提现到账佣金'];
  83. $title = ['拥金记录', '拥金记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  84. $filename = '';
  85. $suffix = 'xlsx';
  86. $is_save = true;
  87. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  88. }
  89. /**
  90. * 用户积分导出
  91. * @param $data 导出数据
  92. */
  93. public static function userPoint($data = [])
  94. {
  95. $export = [];
  96. if (!empty($data)) {
  97. foreach ($data as $key => $item) {
  98. $export[] = [
  99. $item['id'],
  100. $item['title'],
  101. $item['balance'],
  102. $item['number'],
  103. $item['mark'],
  104. $item['nickname'],
  105. date('Y-m-d H:i:s', $item['add_time']),
  106. ];
  107. }
  108. }
  109. $header = ['编号', '标题', '积分余量', '明细数字', '备注', '用户微信昵称', '添加时间'];
  110. $title = ['积分日志', '积分日志' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  111. $filename = '';
  112. $suffix = 'xlsx';
  113. $is_save = true;
  114. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  115. }
  116. /**
  117. * 用户充值导出
  118. * @param $data 导出数据
  119. */
  120. public static function userRecharge($data = [])
  121. {
  122. $export = [];
  123. if (!empty($data)) {
  124. foreach ($data as $item) {
  125. switch ($item['recharge_type']) {
  126. case 'routine':
  127. $item['_recharge_type'] = '小程序充值';
  128. break;
  129. case 'weixin':
  130. $item['_recharge_type'] = '公众号充值';
  131. break;
  132. default:
  133. $item['_recharge_type'] = '其他充值';
  134. break;
  135. }
  136. $item['_pay_time'] = $item['pay_time'] ? date('Y-m-d H:i:s', $item['pay_time']) : '暂无';
  137. $item['_add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '暂无';
  138. $item['paid_type'] = $item['paid'] ? '已支付' : '未支付';
  139. $export[] = [
  140. $item['nickname'],
  141. $item['price'],
  142. $item['paid_type'],
  143. $item['_recharge_type'],
  144. $item['_pay_time'],
  145. $item['paid'] == 1 && $item['refund_price'] == $item['price'] ? '已退款' : '未退款',
  146. $item['_add_time']
  147. ];
  148. }
  149. }
  150. $header = ['昵称/姓名', '充值金额', '是否支付', '充值类型', '支付时间', '是否退款', '添加时间'];
  151. $title = ['充值记录', '充值记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  152. $filename = '';
  153. $suffix = 'xlsx';
  154. $is_save = true;
  155. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  156. }
  157. /**
  158. * 用户推广导出
  159. * @param $data 导出数据
  160. */
  161. public static function userAgent($data = [])
  162. {
  163. $export = [];
  164. if (!empty($data)) {
  165. foreach ($data as $index => $item) {
  166. $export[] = [
  167. $item['uid'],
  168. $item['nickname'],
  169. $item['phone'],
  170. $item['spread_count'],
  171. $item['order_count'],
  172. $item['order_price'],
  173. $item['brokerage_money'],
  174. $item['extract_count_price'],
  175. $item['extract_count_num'],
  176. $item['brokerage_price'],
  177. $item['spread_name'],
  178. ];
  179. }
  180. }
  181. $header = ['用户编号', '昵称', '电话号码', '推广用户数量', '订单数量', '推广订单金额', '佣金金额', '已提现金额', '提现次数', '未提现金额', '上级推广人'];
  182. $title = ['推广用户', '推广用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  183. $filename = '';
  184. $suffix = 'xlsx';
  185. $is_save = true;
  186. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  187. }
  188. /**
  189. * 微信用户导出
  190. * @param $data 导出数据
  191. */
  192. public static function wechatUser($data = [])
  193. {
  194. $export = [];
  195. if (!empty($data)) {
  196. foreach ($data as $index => $item) {
  197. $export[] = [
  198. $item['nickname'],
  199. $item['sex'],
  200. $item['country'] . $item['province'] . $item['city'],
  201. $item['subscribe'] == 1 ? '关注' : '未关注',
  202. ];
  203. }
  204. }
  205. $header = ['名称', '性别', '地区', '是否关注公众号'];
  206. $title = ['微信用户导出', '微信用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  207. $filename = '';
  208. $suffix = 'xlsx';
  209. $is_save = true;
  210. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  211. }
  212. /**
  213. * 订单资金导出
  214. * @param $data 导出数据
  215. */
  216. public static function orderFinance($data = [])
  217. {
  218. $export = [];
  219. if (!empty($data)) {
  220. foreach ($data as $info) {
  221. $time = $info['pay_time'];
  222. $price = $info['total_price'] + $info['pay_postage'];
  223. $zhichu = $info['coupon_price'] + $info['deduction_price'] + $info['cost'];
  224. $profit = ($info['total_price'] + $info['pay_postage']) - ($info['coupon_price'] + $info['deduction_price'] + $info['cost']);
  225. $deduction = $info['deduction_price'];//积分抵扣
  226. $coupon = $info['coupon_price'];//优惠
  227. $cost = $info['cost'];//成本
  228. $export[] = [$time, $price, $zhichu, $cost, $coupon, $deduction, $profit];
  229. }
  230. }
  231. $header = ['时间', '营业额(元)', '支出(元)', '成本', '优惠', '积分抵扣', '盈利(元)'];
  232. $title = ['财务统计', '财务统计', date('Y-m-d H:i:s', time())];
  233. $filename = '';
  234. $suffix = 'xlsx';
  235. $is_save = true;
  236. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  237. }
  238. /**
  239. * 商铺砍价活动导出
  240. * @param $data 导出数据
  241. */
  242. public static function storeBargain($data = [])
  243. {
  244. $export = [];
  245. if (!empty($data)) {
  246. foreach ($data as $index => $item) {
  247. $export[] = [
  248. $item['title'],
  249. $item['info'],
  250. '¥' . $item['price'],
  251. '¥' . $item['cost'],
  252. $item['num'],
  253. '¥' . $item['bargain_max_price'],
  254. '¥' . $item['bargain_min_price'],
  255. $item['bargain_num'],
  256. $item['status'] ? '开启' : '关闭',
  257. empty($item['start_time']) ? '' : date('Y-m-d H:i:s', (int)$item['start_time']),
  258. empty($item['stop_time']) ? '' : date('Y-m-d H:i:s', (int)$item['stop_time']),
  259. $item['sales'],
  260. $item['stock'],
  261. $item['give_integral'],
  262. empty($item['add_time']) ? '' : $item['add_time'],
  263. ];
  264. }
  265. }
  266. $header = ['砍价活动名称', '砍价活动简介', '砍价金额', '成本价', '每次购买的砍价商品数量', '用户每次砍价的最大金额', '用户每次砍价的最小金额',
  267. '用户每次砍价的次数', '砍价状态', '砍价开启时间', '砍价结束时间', '销量', '库存', '返多少积分', '添加时间'];
  268. $title = ['砍价商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  269. $filename = '';
  270. $suffix = 'xlsx';
  271. $is_save = true;
  272. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  273. }
  274. /**
  275. * 商铺拼团导出
  276. * @param $data 导出数据
  277. */
  278. public static function storeCombination($data = [])
  279. {
  280. $export = [];
  281. if (!empty($data)) {
  282. foreach ($data as $item) {
  283. $export[] = [
  284. $item['id'],
  285. $item['title'],
  286. $item['ot_price'],
  287. $item['price'],
  288. $item['stock'],
  289. $item['people'],
  290. $item['count_people_browse'],
  291. $item['browse'],
  292. $item['count_people_all'],
  293. $item['count_people_pink'],
  294. $item['sales'] ?? 0,
  295. $item['is_show'] ? '开启' : '关闭',
  296. empty($item['stop_time']) ? '' : date('Y/m/d H:i:s', (int)$item['stop_time'])
  297. ];
  298. }
  299. }
  300. $header = ['编号', '拼团名称', '原价', '拼团价', '库存', '拼团人数', '访客人数', '展现量', '参与人数', '成团数量', '销量', '商品状态', '结束时间'];
  301. $title = ['拼团商品导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time())];
  302. $filename = '';
  303. $suffix = 'xlsx';
  304. $is_save = true;
  305. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  306. }
  307. /**
  308. * 商铺助力导出
  309. * @param $data 导出数据
  310. */
  311. public static function storeAssistance($data = [])
  312. {
  313. $export = [];
  314. if (!empty($data)) {
  315. foreach ($data as $item) {
  316. $export[] = [
  317. $item['id'],
  318. $item['title'],
  319. $item['ot_price'],
  320. $item['price'],
  321. $item['stock'],
  322. $item['people'],
  323. $item['count_people_browse'],
  324. $item['browse'],
  325. $item['count_people_all'],
  326. $item['count_people_assistance'],
  327. $item['sales'] ?? 0,
  328. $item['is_show'] ? '开启' : '关闭',
  329. empty($item['stop_time']) ? '' : date('Y/m/d H:i:s', (int)$item['stop_time'])
  330. ];
  331. }
  332. }
  333. $header = ['编号', '助力名称', '原价', '助力价', '库存', '助力人数', '访客人数', '展现量', '参与人数', '成团数量', '销量', '商品状态', '结束时间'];
  334. $title = ['拼团商品导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time())];
  335. $filename = '';
  336. $suffix = 'xlsx';
  337. $is_save = true;
  338. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  339. }
  340. /**
  341. * 商铺秒杀活动导出
  342. * @param $data 导出数据
  343. */
  344. public static function storeSeckill($data = [])
  345. {
  346. $export = [];
  347. if (!empty($data)) {
  348. foreach ($data as $item) {
  349. if ($item['status']) {
  350. if ($item['start_time'] > time())
  351. $item['start_name'] = '活动未开始';
  352. else if ($item['stop_time'] < time())
  353. $item['start_name'] = '活动已结束';
  354. else if ($item['stop_time'] > time() && $item['start_time'] < time())
  355. $item['start_name'] = '正在进行中';
  356. } else {
  357. $item['start_name'] = '关闭';
  358. }
  359. $export[] = [
  360. $item['id'],
  361. $item['title'],
  362. $item['info'],
  363. $item['ot_price'],
  364. $item['price'],
  365. $item['stock'],
  366. $item['sales'],
  367. $item['start_name'],
  368. $item['stop_time'] ? date('Y-m-d H:i:s', $item['stop_time']) : '/',
  369. $item['status'] ? '开启' : '关闭',
  370. ];
  371. }
  372. }
  373. $header = ['编号', '活动标题', '活动简介', '原价', '秒杀价', '库存', '销量', '秒杀状态', '结束时间', '状态'];
  374. $title = ['秒杀商品导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time())];
  375. $filename = '';
  376. $suffix = 'xlsx';
  377. $is_save = true;
  378. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  379. }
  380. /**
  381. * 商铺商品导出
  382. * @param $data 导出数据
  383. */
  384. public static function storeProduct($data = [])
  385. {
  386. $export = [];
  387. if (!empty($data)) {
  388. foreach ($data as $index => $item) {
  389. $export[] = [
  390. $item['store_name'],
  391. $item['store_info'],
  392. $item['cate_name'],
  393. '¥' . $item['price'],
  394. $item['stock'],
  395. $item['sales'],
  396. $item['browse'],
  397. $item['collect']
  398. ];
  399. }
  400. }
  401. $header = ['商品名称', '商品简介', '商品分类', '价格', '库存', '销量', '浏览量', '收藏人数'];
  402. $title = ['商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  403. $filename = '';
  404. $suffix = 'xlsx';
  405. $is_save = true;
  406. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  407. }
  408. /**
  409. * 商铺订单导出
  410. * @param $data 导出数据
  411. */
  412. public static function storeOrder($data = [])
  413. {
  414. $export = [];
  415. if (!empty($data)) {
  416. foreach ($data as $item) {
  417. if ($item['paid'] == 1) {
  418. switch ($item['pay_type']) {
  419. case 'weixin':
  420. $item['pay_type_name'] = '微信支付';
  421. break;
  422. case 'yue':
  423. $item['pay_type_name'] = '余额支付';
  424. break;
  425. case 'offline':
  426. $item['pay_type_name'] = '线下支付';
  427. break;
  428. default:
  429. $item['pay_type_name'] = '其他支付';
  430. break;
  431. }
  432. } else {
  433. switch ($item['pay_type']) {
  434. default:
  435. $item['pay_type_name'] = '未支付';
  436. break;
  437. case 'offline':
  438. $item['pay_type_name'] = '线下支付';
  439. $item['pay_type_info'] = 1;
  440. break;
  441. }
  442. }
  443. if ($item['paid'] == 0 && $item['status'] == 0) {
  444. $item['status_name'] = '未支付';
  445. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
  446. $item['status_name'] = '未发货';
  447. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  448. $item['status_name'] = '未核销';
  449. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
  450. $item['status_name'] = '待收货';
  451. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  452. $item['status_name'] = '未核销';
  453. } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
  454. $item['status_name'] = '待评价';
  455. } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
  456. $item['status_name'] = '已完成';
  457. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  458. $refundReasonTime = date('Y-m-d H:i', $item['refund_reason_time']);
  459. $refundReasonWapImg = json_decode($item['refund_reason_wap_img'], true);
  460. $refundReasonWapImg = $refundReasonWapImg ? $refundReasonWapImg : [];
  461. $img = '';
  462. if (count($refundReasonWapImg)) {
  463. foreach ($refundReasonWapImg as $itemImg) {
  464. if (strlen(trim($itemImg)))
  465. $img .= '<img style="height:50px;" src="' . $itemImg . '" />';
  466. }
  467. }
  468. if (!strlen(trim($img))) $img = '无';
  469. $item['status_name'] = <<<HTML
  470. <b style="color:#f124c7">申请退款</b><br/>
  471. <span>退款原因:{$item['refund_reason_wap']}</span><br/>
  472. <span>备注说明:{$item['refund_reason_wap_explain']}</span><br/>
  473. <span>退款时间:{$refundReasonTime}</span><br/>
  474. <span>退款凭证:{$img}</span>
  475. HTML;
  476. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  477. $item['status_name'] = '已退款';
  478. }
  479. $goodsName = [];
  480. foreach ($item['_info'] as $k => $v) {
  481. $suk = '';
  482. if (isset($v['productInfo']['attrInfo'])) {
  483. if (isset($v['productInfo']['attrInfo']['suk'])) {
  484. $suk = '(' . $v['productInfo']['attrInfo']['suk'] . ')';
  485. }
  486. }
  487. $goodsName[] = implode(
  488. [$v['productInfo']['store_name'],
  489. $suk,
  490. "[{$v['cart_num']} * {$v['truePrice']}]"
  491. ], ' ');
  492. }
  493. if ($item['sex'] == 1) $sex_name = '男';
  494. else if ($item['sex'] == 2) $sex_name = '女';
  495. else $sex_name = '未知';
  496. $export[] = [
  497. $item['order_id'],
  498. $sex_name,
  499. $item['real_name'],
  500. $item['user_phone'],
  501. $item['user_address'],
  502. $goodsName ? implode("\n", $goodsName) : '',
  503. $item['total_price'],
  504. $item['pay_postage'],
  505. $item['coupon_price'],
  506. $item['pay_price'],
  507. $item['pay_type_name'],
  508. $item['pay_time'] > 0 ? date('Y/m-d H:i', (int)$item['pay_time']) : '暂无',
  509. $item['status_name'],
  510. empty($item['add_time']) ? 0 : date('Y-m-d H:i:s', (int)$item['add_time']),
  511. $item['mark'],
  512. $item['remark']
  513. ];
  514. }
  515. }
  516. $header = ['订单号', '性别', '收货人姓名', '收货人电话', '收货地址', '商品信息',
  517. '总价格', '邮费', '优惠金额', '实际支付', '支付状态', '支付时间', '订单状态', '下单时间', '用户备注', '商家备注'];
  518. $title = ['订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  519. $filename = '';
  520. $suffix = 'xlsx';
  521. $is_save = true;
  522. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  523. }
  524. /**
  525. * 商铺自提点导出
  526. * @param $data 导出数据
  527. */
  528. public static function storeMerchant($data = [])
  529. {
  530. $export = [];
  531. if (!empty($data)) {
  532. foreach ($data as $index => $item) {
  533. $export[] = [
  534. $item['name'],
  535. $item['phone'],
  536. $item['address'] . '' . $item['detailed_address'],
  537. $item['day_time'],
  538. $item['is_show'] ? '开启' : '关闭'
  539. ];
  540. }
  541. }
  542. $header = ['提货点名称', '提货点', '地址', '营业时间', '状态'];
  543. $title = ['提货点导出', '提货点信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  544. $filename = '';
  545. $suffix = 'xlsx';
  546. $is_save = true;
  547. return self::export($header, $title, $export, $filename, $suffix, $is_save);
  548. }
  549. }