ExportServices.php 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\other\export;
  12. use app\model\user\User;
  13. use app\services\BaseServices;
  14. use app\jobs\system\ExportExcelJob;
  15. use app\services\pay\PayServices;
  16. use app\services\user\UserServices;
  17. use Cassandra\Exception\UnavailableException;
  18. use crmeb\services\SpreadsheetExcelService;
  19. use crmeb\services\WithdrawService;
  20. /**
  21. * 导出
  22. * Class ExportServices
  23. * @package app\services\other\export
  24. */
  25. class ExportServices extends BaseServices
  26. {
  27. /**
  28. * 不分页拆分处理最大条数
  29. * @var int
  30. */
  31. public $maxLimit = 1000;
  32. /**
  33. * 分页导出每页条数
  34. * @var int
  35. */
  36. public $limit = 1000;
  37. /**
  38. * 真实请求导出
  39. * @param $header excel表头
  40. * @param $title 标题
  41. * @param array $export 填充数据
  42. * @param string $filename 保存文件名称
  43. * @param string $suffix 保存文件后缀
  44. * @param bool $is_save true|false 是否保存到本地
  45. * @return mixed
  46. */
  47. public function export(array $header, array $title_arr, array $export = [], string $filename = '', string $suffix = 'xlsx', bool $is_save = true)
  48. {
  49. $path = [];
  50. $exportNum = count($export);
  51. $limit = $this->maxLimit;
  52. if ($exportNum < $limit) {
  53. $title = isset($title_arr[0]) && !empty($title_arr[0]) ? $title_arr[0] : '导出数据';
  54. $name = isset($title_arr[1]) && !empty($title_arr[1]) ? $title_arr[1] : '导出数据';
  55. $info = isset($title_arr[2]) && !empty($title_arr[2]) ? $title_arr[2] : date('Y-m-d H:i:s', time());
  56. $filePath = SpreadsheetExcelService::instance()->setExcelHeader($header)
  57. ->setExcelTile($title, $name, $info)
  58. ->setExcelContent($export)
  59. ->excelSave($filename, $suffix, $is_save);
  60. $path[] = sys_config('site_url') . $filePath;
  61. } else {
  62. $data = [];
  63. $i = $j = 0;
  64. $basePath = sys_config('site_url') . '/phpExcel/';
  65. foreach ($export as $item) {
  66. $data[] = $item;
  67. $i++;
  68. if ($limit <= 1 || $i == $exportNum) {
  69. if ($j > 0) {
  70. $filename .= '_' . $j;
  71. $header = [];
  72. $title_arr = [];
  73. }
  74. //加入队列
  75. ExportExcelJob::dispatch([$data, $filename, $header, $title_arr, $suffix, $is_save]);
  76. $path[] = $basePath . $filename . '.' . $suffix;
  77. $data = [];
  78. $limit = $this->limit + 1;
  79. $j++;
  80. }
  81. $limit--;
  82. }
  83. }
  84. return $path;
  85. }
  86. /**
  87. * 用户资金导出
  88. * @param array $data
  89. * @param int $type 1:直接返回数据前端生成excel 2:后台生成excel
  90. * @return array|mixed
  91. */
  92. public function userFinance($data = [], $type = 1)
  93. {
  94. $header = ['会员ID', '昵称', '金额', '类型', '备注', '创建时间'];
  95. $title = ['资金监控', '资金监控', date('Y-m-d H:i:s', time())];
  96. $filename = '资金监控_' . date('YmdHis', time());
  97. $export = [];
  98. $filekey = [];
  99. if (!empty($data)) {
  100. $i = 0;
  101. foreach ($data as $value) {
  102. $one_data = [
  103. 'uid' => $value['uid'],
  104. 'nickname' => $value['nickname'],
  105. 'pm' => $value['pm'] == 0 ? '-' . $value['number'] : $value['number'],
  106. 'title' => $value['title'],
  107. 'mark' => $value['mark'],
  108. 'add_time' => $value['add_time'],
  109. ];
  110. if ($type == 1) {
  111. $export[] = $one_data;
  112. if ($i == 0) {
  113. $filekey = array_keys($one_data);
  114. }
  115. } else {
  116. $export[] = array_values($one_data);
  117. }
  118. $i++;
  119. }
  120. }
  121. if ($type == 1) {
  122. return compact('header', 'filekey', 'export', 'filename');
  123. } else {
  124. return $this->export($header, $title, $export, $filename);
  125. }
  126. }
  127. /**
  128. * 用户佣金导出
  129. * @param $data 导出数据
  130. */
  131. public function userCommission($data = [], $type = 1)
  132. {
  133. $header = ['昵称/姓名', '总佣金金额', '账户余额', '账户佣金', '提现到账佣金', '时间'];
  134. $title = ['佣金记录', '佣金记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  135. $filename = '佣金记录_' . date('YmdHis', time());
  136. $export = [];
  137. $filekey = [];
  138. if (!empty($data)) {
  139. $i = 0;
  140. foreach ($data as $value) {
  141. $one_data = [
  142. 'nickname' => $value['nickname'],
  143. 'sum_number' => $value['sum_number'],
  144. 'now_money' => $value['now_money'],
  145. 'brokerage_price' => $value['brokerage_price'],
  146. 'extract_price' => $value['extract_price'],
  147. 'time' => $value['time']
  148. ];
  149. if ($type == 1) {
  150. $export[] = $one_data;
  151. if ($i == 0) {
  152. $filekey = array_keys($one_data);
  153. }
  154. } else {
  155. $export[] = array_values($one_data);
  156. }
  157. $i++;
  158. }
  159. }
  160. if ($type == 1) {
  161. return compact('header', 'filekey', 'export', 'filename');
  162. } else {
  163. return $this->export($header, $title, $export, $filename);
  164. }
  165. }
  166. /**
  167. * 用户积分导出
  168. * @param $data 导出数据
  169. */
  170. public function userPoint($data = [], $type = 1)
  171. {
  172. $header = ['编号', '标题', '变动后积分', '积分变动', '备注', '用户微信昵称', '添加时间'];
  173. $title = ['积分日志', '积分日志' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  174. $filename = '积分日志_' . date('YmdHis', time());
  175. $export = [];
  176. $filekey = [];
  177. if (!empty($data)) {
  178. $i = 0;
  179. foreach ($data as $key => $item) {
  180. $one_data = [
  181. 'id' => $item['id'],
  182. 'title' => $item['title'],
  183. 'balance' => $item['balance'],
  184. 'number' => $item['number'],
  185. 'mark' => $item['mark'],
  186. 'nickname' => $item['nickname'],
  187. 'add_time' => $item['add_time'],
  188. ];
  189. if ($type == 1) {
  190. $export[] = $one_data;
  191. if ($i == 0) {
  192. $filekey = array_keys($one_data);
  193. }
  194. } else {
  195. $export[] = array_values($one_data);
  196. }
  197. $i++;
  198. }
  199. }
  200. if ($type == 1) {
  201. return compact('header', 'filekey', 'export', 'filename');
  202. } else {
  203. return $this->export($header, $title, $export, $filename);
  204. }
  205. }
  206. /**
  207. * 用户充值导出
  208. * @param $data 导出数据
  209. */
  210. public function userRecharge($data = [], $type = 1)
  211. {
  212. $header = ['昵称/姓名', '充值金额', '是否支付', '充值类型', '支付时间', '是否退款', '添加时间'];
  213. $title = ['充值记录', '充值记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  214. $filename = '充值记录_' . date('YmdHis', time());
  215. $export = [];
  216. $filekey = [];
  217. if (!empty($data)) {
  218. $i = 0;
  219. foreach ($data as $item) {
  220. switch ($item['recharge_type']) {
  221. case 'routine':
  222. $item['_recharge_type'] = '小程序充值';
  223. break;
  224. case 'weixin':
  225. $item['_recharge_type'] = '公众号充值';
  226. break;
  227. case 'balance':
  228. $item['_recharge_type'] = '佣金转入';
  229. break;
  230. case 'store':
  231. $item['_recharge_type'] = '门店余额充值';
  232. break;
  233. default:
  234. $item['_recharge_type'] = '其他充值';
  235. break;
  236. }
  237. $item['_pay_time'] = $item['pay_time'] ? date('Y-m-d H:i:s', $item['pay_time']) : '暂无';
  238. $item['_add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '暂无';
  239. $item['paid_type'] = $item['paid'] ? '已支付' : '未支付';
  240. $one_data = [
  241. 'nickname' => $item['nickname'],
  242. 'price' => $item['price'],
  243. 'paid_type' => $item['paid_type'],
  244. '_recharge_type' => $item['_recharge_type'],
  245. '_pay_time' => $item['_pay_time'],
  246. 'paid' => $item['paid'] == 1 && $item['refund_price'] == $item['price'] ? '已退款' : '未退款',
  247. '_add_time' => $item['_add_time']
  248. ];
  249. if ($type == 1) {
  250. $export[] = $one_data;
  251. if ($i == 0) {
  252. $filekey = array_keys($one_data);
  253. }
  254. } else {
  255. $export[] = array_values($one_data);
  256. }
  257. $i++;
  258. }
  259. }
  260. if ($type == 1) {
  261. return compact('header', 'filekey', 'export', 'filename');
  262. } else {
  263. return $this->export($header, $title, $export, $filename);
  264. }
  265. }
  266. /**
  267. * 用户推广导出
  268. * @param $data 导出数据
  269. */
  270. public function userAgent($data = [], $type = 1)
  271. {
  272. $header = ['用户编号', '昵称', '电话号码', '推广用户数量', '订单数量', '推广订单金额', '佣金金额', '已提现金额', '提现次数', '未提现金额', '上级推广人'];
  273. $title = ['推广用户', '推广用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  274. $filename = '推广用户_' . date('YmdHis', time());
  275. $export = [];
  276. $filekey = [];
  277. if (!empty($data)) {
  278. $i = 0;
  279. foreach ($data as $index => $item) {
  280. $one_data = [
  281. 'uid' => $item['uid'],
  282. 'nickname' => $item['nickname'],
  283. 'phone' => $item['phone'],
  284. 'spread_count' => $item['spread_count'],
  285. 'order_count' => $item['order_count'],
  286. 'order_price' => $item['order_price'],
  287. 'brokerage_money' => $item['brokerage_money'],
  288. 'extract_count_price' => $item['extract_count_price'],
  289. 'extract_count_num' => $item['extract_count_num'],
  290. 'brokerage_price' => $item['brokerage_price'],
  291. 'spread_name' => $item['spread_name'],
  292. ];
  293. if ($type == 1) {
  294. $export[] = $one_data;
  295. if ($i == 0) {
  296. $filekey = array_keys($one_data);
  297. }
  298. } else {
  299. $export[] = array_values($one_data);
  300. }
  301. $i++;
  302. }
  303. }
  304. if ($type == 1) {
  305. return compact('header', 'filekey', 'export', 'filename');
  306. } else {
  307. return $this->export($header, $title, $export, $filename);
  308. }
  309. }
  310. /**
  311. * 微信用户导出
  312. * @param $data 导出数据
  313. */
  314. public function wechatUser($data = [], $type = 1)
  315. {
  316. $header = ['名称', '性别', '地区', '是否关注公众号'];
  317. $title = ['微信用户导出', '微信用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  318. $filename = '微信用户导出_' . date('YmdHis', time());
  319. $export = [];
  320. $filekey = [];
  321. if (!empty($data)) {
  322. $i = 0;
  323. foreach ($data as $index => $item) {
  324. $one_data = [
  325. 'nickname' => $item['nickname'],
  326. 'sex' => $item['sex'],
  327. 'address' => $item['country'] . $item['province'] . $item['city'],
  328. 'subscribe' => $item['subscribe'] == 1 ? '关注' : '未关注',
  329. ];
  330. if ($type == 1) {
  331. $export[] = $one_data;
  332. if ($i == 0) {
  333. $filekey = array_keys($one_data);
  334. }
  335. } else {
  336. $export[] = array_values($one_data);
  337. }
  338. $i++;
  339. }
  340. }
  341. if ($type == 1) {
  342. return compact('header', 'filekey', 'export', 'filename');
  343. } else {
  344. return $this->export($header, $title, $export, $filename);
  345. }
  346. }
  347. /**
  348. * 订单资金导出
  349. * @param array $data
  350. * @param int $type
  351. * @return array|mixed
  352. */
  353. public function orderFinance($data = [], $type = 1)
  354. {
  355. $header = ['时间', '营业额(元)', '支出(元)', '成本', '优惠', '积分抵扣', '盈利(元)'];
  356. $title = ['财务统计', '财务统计', date('Y-m-d H:i:s', time())];
  357. $filename = '财务统计_' . date('YmdHis', time());
  358. $export = [];
  359. $filekey = [];
  360. if (!empty($data)) {
  361. $i = 0;
  362. foreach ($data as $info) {
  363. $time = $info['pay_time'];
  364. $price = $info['total_price'] + $info['pay_postage'];
  365. $zhichu = $info['coupon_price'] + $info['deduction_price'] + $info['cost'];
  366. $profit = ($info['total_price'] + $info['pay_postage']) - ($info['coupon_price'] + $info['deduction_price'] + $info['cost']);
  367. $deduction = $info['deduction_price'];//积分抵扣
  368. $coupon = $info['coupon_price'];//优惠
  369. $cost = $info['cost'];//成本
  370. $one_data = compact('time', 'price', 'zhichu', 'cost', 'coupon', 'deduction', 'profit');
  371. if ($type == 1) {
  372. $export[] = $one_data;
  373. if ($i == 0) {
  374. $filekey = array_keys($one_data);
  375. }
  376. } else {
  377. $export[] = array_values($one_data);
  378. }
  379. $i++;
  380. }
  381. }
  382. if ($type == 1) {
  383. return compact('header', 'filekey', 'export', 'filename');
  384. } else {
  385. return $this->export($header, $title, $export, $filename);
  386. }
  387. }
  388. /**
  389. * 砍价活动导出
  390. * @param array $data
  391. * @param int $type
  392. * @return array|mixed
  393. */
  394. public function storeBargain($data = [], $type = 1)
  395. {
  396. $header = ['砍价活动名称', '砍价活动简介', '砍价金额', '砍价最低价',
  397. '用户每次砍价的次数', '砍价状态', '砍价开启时间', '砍价结束时间', '销量', '库存', '返多少积分', '添加时间'];
  398. $title = ['砍价商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  399. $filename = '砍价商品导出_' . date('YmdHis', time());
  400. $export = [];
  401. $filekey = [];
  402. if (!empty($data)) {
  403. $i = 0;
  404. foreach ($data as $index => $item) {
  405. $one_data = [
  406. 'title' => $item['title'],
  407. 'info' => $item['info'],
  408. 'price' => '¥' . $item['price'],
  409. 'bargain_max_price' => '¥' . $item['min_price'],
  410. 'bargain_num' => $item['bargain_num'],
  411. 'status' => $item['status'] ? '开启' : '关闭',
  412. 'start_time' => empty($item['start_time']) ? '' : date('Y-m-d H:i:s', (int)$item['start_time']),
  413. 'stop_time' => empty($item['stop_time']) ? '' : date('Y-m-d H:i:s', (int)$item['stop_time']),
  414. 'sales' => $item['sales'],
  415. 'stock' => $item['stock'],
  416. 'give_integral' => $item['give_integral'],
  417. 'add_time' => empty($item['add_time']) ? '' : $item['add_time'],
  418. ];
  419. if ($type == 1) {
  420. $export[] = $one_data;
  421. if ($i == 0) {
  422. $filekey = array_keys($one_data);
  423. }
  424. } else {
  425. $export[] = array_values($one_data);
  426. }
  427. $i++;
  428. }
  429. }
  430. if ($type == 1) {
  431. return compact('header', 'filekey', 'export', 'filename');
  432. } else {
  433. return $this->export($header, $title, $export, $filename);
  434. }
  435. }
  436. /**
  437. * 拼团导出
  438. * @param array $data
  439. * @param int $type
  440. * @return array|mixed
  441. */
  442. public function storeCombination($data = [], $type = 1)
  443. {
  444. $header = ['编号', '拼团名称', '原价', '拼团价', '库存', '拼团人数', '参与人数', '成团数量', '销量', '商品状态', '结束时间'];
  445. $title = ['拼团商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  446. $filename = '拼团商品导出_' . date('YmdHis', time());
  447. $export = [];
  448. $filekey = [];
  449. if (!empty($data)) {
  450. $i = 0;
  451. foreach ($data as $item) {
  452. $one_data = [
  453. 'id' => $item['id'],
  454. 'title' => $item['title'],
  455. 'ot_price' => $item['ot_price'],
  456. 'price' => $item['price'],
  457. 'stock' => $item['stock'],
  458. 'people' => $item['count_people'],
  459. 'count_people_all' => $item['count_people_all'],
  460. 'count_people_pink' => $item['count_people_pink'],
  461. 'sales' => $item['sales'] ?? 0,
  462. 'is_show' => $item['is_show'] ? '开启' : '关闭',
  463. 'stop_time' => empty($item['stop_time']) ? '' : date('Y/m/d H:i:s', (int)$item['stop_time'])
  464. ];
  465. if ($type == 1) {
  466. $export[] = $one_data;
  467. if ($i == 0) {
  468. $filekey = array_keys($one_data);
  469. }
  470. } else {
  471. $export[] = array_values($one_data);
  472. }
  473. $i++;
  474. }
  475. }
  476. if ($type == 1) {
  477. return compact('header', 'filekey', 'export', 'filename');
  478. } else {
  479. return $this->export($header, $title, $export, $filename);
  480. }
  481. }
  482. /**
  483. * 秒杀活动导出
  484. * @param array $data
  485. * @param int $type
  486. * @return array|mixed
  487. */
  488. public function storeSeckill($data = [], $type = 1)
  489. {
  490. $header = ['编号', '活动标题', '活动简介', '原价', '秒杀价', '限量', '限量剩余', '秒杀状态', '结束时间', '状态'];
  491. $title = ['秒杀商品导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time())];
  492. $filename = '秒杀商品导出_' . date('YmdHis', time());
  493. $export = [];
  494. $filekey = [];
  495. if (!empty($data)) {
  496. $i = 0;
  497. foreach ($data as $item) {
  498. if ($item['status']) {
  499. if ($item['start_time'] > time())
  500. $item['start_name'] = '活动未开始';
  501. else if ($item['stop_time'] < time())
  502. $item['start_name'] = '活动已结束';
  503. else if ($item['stop_time'] > time() && $item['start_time'] < time())
  504. $item['start_name'] = '正在进行中';
  505. } else {
  506. $item['start_name'] = '活动已结束';
  507. }
  508. $one_data = [
  509. 'id' => $item['id'],
  510. 'title' => $item['title'],
  511. 'info' => $item['info'],
  512. 'ot_price' => $item['ot_price'],
  513. 'price' => $item['price'],
  514. 'quota_show' => $item['quota_show'],
  515. 'quota' => $item['quota'],
  516. 'start_name' => $item['start_name'],
  517. 'stop_time' => $item['stop_time'] ? date('Y-m-d H:i:s', $item['stop_time']) : '/',
  518. 'status' => $item['status'] ? '开启' : '关闭',
  519. ];
  520. if ($type == 1) {
  521. $export[] = $one_data;
  522. if ($i == 0) {
  523. $filekey = array_keys($one_data);
  524. }
  525. } else {
  526. $export[] = array_values($one_data);
  527. }
  528. $i++;
  529. }
  530. }
  531. if ($type == 1) {
  532. return compact('header', 'filekey', 'export', 'filename');
  533. } else {
  534. return $this->export($header, $title, $export, $filename);
  535. }
  536. }
  537. /**
  538. * 导出商品卡号、卡密模版
  539. * @param int $type
  540. * @return array|mixed
  541. */
  542. public function storeProductCardTemplate($type = 1)
  543. {
  544. $header = ['卡号', '卡密'];
  545. $title = ['商品卡密模版', '商品密' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  546. $filename = '商品卡密模版_' . date('YmdHis', time());
  547. if ($type == 1) {
  548. $export = [];
  549. $filekey = ['card_no', 'card_pwd'];
  550. return compact('header', 'filekey', 'export', 'filename');
  551. } else {
  552. return $this->export($header, $title, [], $filename);
  553. }
  554. }
  555. /**
  556. * 商品导出
  557. * @param array $data
  558. * @param int $type
  559. * @return array|mixed
  560. */
  561. public function storeProduct($data = [], $type = 1)
  562. {
  563. $header = ['商品名称', '商品简介', '商品分类', '价格', '库存', '销量', '浏览量'];
  564. $title = ['商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  565. $filename = '商品导出_' . date('YmdHis', time());
  566. $export = [];
  567. $filekey = [];
  568. if (!empty($data)) {
  569. $i = 0;
  570. foreach ($data as $index => $item) {
  571. $one_data = [
  572. 'store_name' => $item['store_name'],
  573. 'store_info' => $item['store_info'],
  574. 'cate_name' => $item['cate_name'],
  575. 'price' => '¥' . $item['price'],
  576. 'stock' => $item['stock'],
  577. 'sales' => $item['sales'],
  578. 'visitor' => $item['visitor'],
  579. ];
  580. if ($type == 1) {
  581. $export[] = $one_data;
  582. if ($i == 0) {
  583. $filekey = array_keys($one_data);
  584. }
  585. } else {
  586. $export[] = array_values($one_data);
  587. }
  588. $i++;
  589. }
  590. }
  591. if ($type == 1) {
  592. return compact('header', 'filekey', 'export', 'filename');
  593. } else {
  594. return $this->export($header, $title, $export, $filename);
  595. }
  596. }
  597. /**
  598. * 商铺订单导出
  599. * @param array $data
  600. * @param string $type
  601. * @param int $export_type
  602. * @return array|mixed
  603. */
  604. public function storeOrder($data = [], $type = "", $export_type = 1)
  605. {
  606. if (!$type) {
  607. $header = ['订单ID', '订单编号', '性别', '电话', '收货人姓名', '收货人电话', '收货地址', '商品信息', '商品总数',
  608. '总价格', '实际支付', '邮费', '会员优惠金额', '优惠卷金额', '积分抵扣金额', '支付状态', '支付时间', '订单状态', '下单时间', '用户备注'];
  609. $title = ['订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  610. $filename = '订单导出_' . date('YmdHis', time());
  611. } else {
  612. $header = ['订单ID', '订单编号', '物流公司', '物流编码', '物流单号', '发货地址', '收货人姓名', '收货人电话', '订单实付金额', '商品数量*售价', '商品ID', '商品名称', '商品规格', '商家备注', '订单成交时间'];
  613. $title = ['发货单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  614. $filename = '发货单导出_' . date('YmdHis', time());
  615. }
  616. $export = [];
  617. $filekey = [];
  618. if (!empty($data)) {
  619. $i = 0;
  620. foreach ($data as $item) {
  621. if (!$type) {
  622. if ($item['paid'] == 1) {
  623. switch ($item['pay_type']) {
  624. case PayServices::WEIXIN_PAY:
  625. $item['pay_type_name'] = '微信支付';
  626. break;
  627. case PayServices::YUE_PAY:
  628. $item['pay_type_name'] = '余额支付';
  629. break;
  630. case PayServices::OFFLINE_PAY:
  631. $item['pay_type_name'] = '线下支付';
  632. break;
  633. case PayServices::ALIAPY_PAY:
  634. $item['pay_type_name'] = '支付宝支付';
  635. break;
  636. case PayServices::CASH_PAY:
  637. $item['pay_type_name'] = '现金支付';
  638. break;
  639. default:
  640. $item['pay_type_name'] = '其他支付';
  641. break;
  642. }
  643. } else {
  644. switch ($item['pay_type']) {
  645. default:
  646. $item['pay_type_name'] = '未支付';
  647. break;
  648. case 'offline':
  649. $item['pay_type_name'] = '线下支付';
  650. $item['pay_type_info'] = 1;
  651. break;
  652. }
  653. }
  654. if ($item['paid'] == 0 && $item['status'] == 0) {
  655. $item['status_name'] = '未支付';
  656. } else if ($item['paid'] == 1 && $item['status'] == 4 && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
  657. $item['status_name'] = '部分发货';
  658. } else if ($item['paid'] == 1 && $item['status'] == 5 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  659. $item['status_name'] = '部分核销';
  660. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  661. $item['status_name'] = '申请退款';
  662. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  663. $item['status_name'] = '已退款';
  664. } else if ($item['paid'] == 1 && $item['refund_status'] == 4) {
  665. $item['status_name'] = '退款中';
  666. } else if ($item['paid'] == 1 && $item['status'] == 0 && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
  667. $item['status_name'] = '未发货';
  668. } else if ($item['paid'] == 1 && in_array($item['status'], [0, 1]) && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  669. $item['status_name'] = '未核销';
  670. } else if ($item['paid'] == 1 && in_array($item['status'], [1, 5]) && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
  671. $item['status_name'] = '待收货';
  672. } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
  673. $item['status_name'] = '待评价';
  674. } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
  675. $item['status_name'] = '已完成';
  676. } else if ($item['paid'] == 1 && $item['refund_status'] == 3) {
  677. $item['status_name'] = '部分退款';
  678. }
  679. $goodsName = [];
  680. $vip_sum_price = 0;
  681. foreach ($item['_info'] as $k => $v) {
  682. $suk = '';
  683. if (isset($v['productInfo']['attrInfo'])) {
  684. if (isset($v['productInfo']['attrInfo']['suk'])) {
  685. $suk = '(' . $v['productInfo']['attrInfo']['suk'] . ')';
  686. }
  687. }
  688. if (isset($v['productInfo']['store_name'])) {
  689. $goodsName[] = implode(' ',
  690. [
  691. $v['productInfo']['store_name'],
  692. $suk,
  693. "[{$v['cart_num']} * {$v['truePrice']}]",
  694. ]);
  695. }
  696. $vip_sum_price = bcadd((string)$vip_sum_price, bcmul($v['vip_truePrice'], $v['cart_num'] ? $v['cart_num'] : 1, 4), 2);
  697. }
  698. if ($item['sex'] == 1) $sex_name = '男';
  699. else if ($item['sex'] == 2) $sex_name = '女';
  700. else $sex_name = '未知';
  701. $one_data = [
  702. 'id' => $item['id'],
  703. 'order_id' => $item['order_id'],
  704. 'sex' => $sex_name,
  705. 'phone' => $item['user_phone'],
  706. 'real_name' => $item['real_name'],
  707. 'user_phone' => $item['user_phone'],
  708. 'user_address' => $item['user_address'],
  709. 'goods_name' => $goodsName ? implode("\n", $goodsName) : '',
  710. 'total_num' => $item['total_num'],
  711. 'total_price' => $item['total_price'],
  712. 'pay_price' => $item['pay_price'],
  713. 'pay_postage' => $item['pay_postage'],
  714. 'vip_sum_price' => $vip_sum_price,
  715. 'coupon_price' => $item['coupon_price'],
  716. 'deduction_price' => $item['deduction_price'] ?? 0,
  717. 'pay_type_name' => $item['pay_type_name'],
  718. 'pay_time' => $item['pay_time'] > 0 ? date('Y/m-d H:i', (int)$item['pay_time']) : '暂无',
  719. 'status_name' => $item['status_name'] ?? '未知状态',
  720. 'add_time' => empty($item['add_time']) ? 0 : date('Y-m-d H:i:s', (int)$item['add_time']),
  721. 'mark' => $item['mark']
  722. ];
  723. } else {
  724. if (isset($item['pinkStatus']) && $item['pinkStatus'] != 2) {
  725. continue;
  726. }
  727. if (isset($item['refund']) && $item['refund']) {
  728. continue;
  729. }
  730. $goodsName = [];
  731. $g = 0;
  732. foreach ($item['_info'] as $k => $v) {
  733. $goodsName['cart_num'][$g] = $v['cart_num'] . ' * ' . ($v['productInfo']['attrInfo']['price'] ?? $v['productInfo']['price'] ?? 0.00);
  734. $goodsName['product_id'][$g] = $v['product_id'];
  735. $suk = $barCode = $code = '';
  736. if (!empty($v['productInfo']['attrInfo']['bar_code'])) {
  737. $barCode = $v['productInfo']['attrInfo']['bar_code'];
  738. }
  739. if (!empty($v['productInfo']['attrInfo']['code'])) {
  740. $code = $v['productInfo']['attrInfo']['code'];
  741. }
  742. if (isset($v['productInfo']['attrInfo'])) {
  743. if (isset($v['productInfo']['attrInfo']['suk'])) {
  744. $suk = '(' . $v['productInfo']['attrInfo']['suk'] . '|条码:' . $barCode . '|编码:' . $code . ')';
  745. }
  746. }
  747. $name = [];
  748. if (isset($v['productInfo']['store_name'])) {
  749. $name[] = implode(' ',
  750. [
  751. $v['productInfo']['store_name'],
  752. $suk,
  753. "[{$v['cart_num']} * {$v['truePrice']}]",
  754. ]);
  755. }
  756. $goodsName['goods_name'][$g] = implode(' ', $name);
  757. $goodsName['attr'][$g] = $v['productInfo']['attrInfo']['suk'] ?? '';
  758. $g++;
  759. }
  760. $one_data = [
  761. 'id' => $item['id'],
  762. 'order_id' => $item['order_id'],
  763. 'a' => "",
  764. 'b' => "",
  765. 'c' => "",
  766. 'user_address' => $item['user_address'],
  767. 'real_name' => $item['real_name'],
  768. 'user_phone' => $item['user_phone'],
  769. 'pay_price' => $item['pay_price'],
  770. 'cart_num' => isset($goodsName['cart_num']) ? implode("\n", $goodsName['cart_num']) : '',
  771. 'product_id' => isset($goodsName['product_id']) ? implode("\n", $goodsName['product_id']) : '',
  772. 'goods_name' => isset($goodsName['goods_name']) ? implode("\n", $goodsName['goods_name']) : '',
  773. 'attr' => isset($goodsName['attr']) ? implode("\n", $goodsName['attr']) : '',
  774. 'remark' => $item['remark'],
  775. 'pay_time' => $item['pay_time'] ? date('Y-m-d H:i:s', (int)$item['pay_time']) : '暂无',
  776. ];
  777. }
  778. if ($export_type == 1) {
  779. $export[] = $one_data;
  780. if ($i == 0) {
  781. $filekey = array_keys($one_data);
  782. }
  783. } else {
  784. $export[] = array_values($one_data);
  785. }
  786. $i++;
  787. }
  788. }
  789. if ($export_type == 1) {
  790. return compact('header', 'filekey', 'export', 'filename');
  791. } else {
  792. return $this->export($header, $title, $export, $filename);
  793. }
  794. }
  795. /**
  796. * @param string $str
  797. * @return false|string|string[]|null
  798. */
  799. public function strToUtf8($str = '')
  800. {
  801. $current_encode = mb_detect_encoding($str, array("ASCII", "GB2312", "GBK", 'BIG5', 'UTF-8'));
  802. $encoded_str = mb_convert_encoding($str, 'UTF-8', $current_encode);
  803. return $encoded_str;
  804. }
  805. /**
  806. * 商铺自提点导出
  807. * @param array $data
  808. * @param int $type
  809. * @return array|mixed
  810. */
  811. public function storeMerchant($data = [], $type = 1)
  812. {
  813. $header = ['提货点名称', '提货点', '地址', '营业时间', '状态'];
  814. $title = ['提货点导出', '提货点信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  815. $filename = '提货点导出_' . date('YmdHis', time());
  816. $export = [];
  817. $filekey = [];
  818. if (!empty($data)) {
  819. $i = 0;
  820. foreach ($data as $index => $item) {
  821. $one_data = [
  822. 'name' => $item['name'],
  823. 'phone' => $item['phone'],
  824. 'address' => $item['address'] . '' . $item['detailed_address'],
  825. 'day_time' => $item['day_time'],
  826. 'is_show' => $item['is_show'] ? '开启' : '关闭'
  827. ];
  828. if ($type == 1) {
  829. $export[] = $one_data;
  830. if ($i == 0) {
  831. $filekey = array_keys($one_data);
  832. }
  833. } else {
  834. $export[] = array_values($one_data);
  835. }
  836. $i++;
  837. }
  838. }
  839. if ($type == 1) {
  840. return compact('header', 'filekey', 'export', 'filename');
  841. } else {
  842. return $this->export($header, $title, $export, $filename);
  843. }
  844. }
  845. /**
  846. * 商铺自提点导出
  847. * @param array $data
  848. * @param int $type
  849. * @return array|mixed
  850. */
  851. public function extract($data = [], $type = 1)
  852. {
  853. $header = ['收款账号', '收款人名称', '收款银行', '金额', '用途', '状态'];
  854. $title = ['用户提现导出', '用户提现信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  855. $filename = '用户提现导出_' . date('YmdHis', time());
  856. $export = [];
  857. $filekey = [];
  858. if (!empty($data)) {
  859. $i = 0;
  860. foreach ($data as $index => $item) {
  861. // if ($item['bank_address'] == '灵活用工提现' && $item['status'] == 0) {
  862. // $userServices = app()->make(UserServices::class);
  863. // $userInfo = $userServices->get($item['uid']);
  864. // if (!$userInfo['professional_id']) {
  865. // throw new UnavailableException('用户未认证签约');
  866. // }
  867. // $bankInfo = WithdrawService::init()::contractInfo($userInfo['enterprise_professional_facilitator_id']);
  868. // if (!$bankInfo['sign_img']) throw new UnavailableException('用户未签约');
  869. // $one_data = [
  870. // 'bank_code' => $bankInfo['bank_code'],
  871. // 'real_name' => $bankInfo['name'],
  872. // 'bank_address' => '未知',
  873. // 'extract_price' => $item['extract_price'],
  874. // 'mark' => '工资发放',
  875. // 'status' => ($item['status'] == 1 ? '通过' : ($item['status'] == 0 ? '申请中' : '未通过'))
  876. // ];
  877. // } else
  878. $one_data = [
  879. 'bank_code' => $item['bank_code'],
  880. 'real_name' => $item['real_name'],
  881. 'bank_address' => $item['bank_address'],
  882. 'extract_price' => $item['extract_price'],
  883. 'mark' => '工资发放',
  884. 'status' => ($item['status'] == 1 ? '通过' : ($item['status'] == 0 ? '申请中' : '未通过'))
  885. ];
  886. if ($type == 1) {
  887. $export[] = $one_data;
  888. if ($i == 0) {
  889. $filekey = array_keys($one_data);
  890. }
  891. } else {
  892. $export[] = array_values($one_data);
  893. }
  894. $i++;
  895. }
  896. }
  897. if ($type == 1) {
  898. return compact('header', 'filekey', 'export', 'filename');
  899. } else {
  900. return $this->export($header, $title, $export, $filename);
  901. }
  902. }
  903. /**
  904. * 商铺自提点导出
  905. * @param array $data
  906. * @param int $type
  907. * @return array|mixed
  908. */
  909. public function exchange($data = [], $type = 1)
  910. {
  911. $header = ['交易账号', '姓名', '银行', '交易账号', '银行卡号', '身份证号', '联系电话', '申购价额', '申购份额', '冻结份额', '封闭期'];
  912. $title = ['用户能量转份额导出', '用户能量转份额信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  913. $filename = '用户能量转份额导出_' . date('YmdHis', time());
  914. $export = [];
  915. $filekey = [];
  916. if (!empty($data)) {
  917. $i = 0;
  918. foreach ($data as $index => $item) {
  919. $one_data = [
  920. 'trade_no' => '',
  921. 'real_name' => $item['user']['real_name'] ?? '--',
  922. 'bank' => $item['bank_address'],
  923. 'account' => $item['account'],
  924. 'bank_code' => $item['bank_code'],
  925. 'id_card' => $item['user']['card_id'] ?? '--',
  926. 'phone' => $item['user']['phone']?? '--',
  927. 'extract_price' => $item['extract_price'],
  928. 'exchange_num' => $item['exchange_num'],
  929. 'freeze_num' => '',
  930. 'lock_time' => ''
  931. ];
  932. if ($type == 1) {
  933. $export[] = $one_data;
  934. if ($i == 0) {
  935. $filekey = array_keys($one_data);
  936. }
  937. } else {
  938. $export[] = array_values($one_data);
  939. }
  940. $i++;
  941. }
  942. }
  943. if ($type == 1) {
  944. return compact('header', 'filekey', 'export', 'filename');
  945. } else {
  946. return $this->export($header, $title, $export, $filename);
  947. }
  948. }
  949. /**
  950. * 商铺自提点导出
  951. * @param array $data
  952. * @param int $type
  953. * @return array|mixed
  954. */
  955. public function extractInfo($data = [], $type = 1, $month = '')
  956. {
  957. $header = ['姓名', '证件号码', '所得项目', '收入', '费用', '免税收入', '扣除项目合计', '应纳税所得额', '税率/预扣率', '速算扣除数', '应纳税额', '减免税额', '应扣缴税额', '已缴税额', '应补(退)税额'];
  958. $title = [($month ?: date('Y-m')) . '月用户提现统计', '用户提现统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  959. $filename = ($month ?: date('Y-m')) . '月用户提现统计_' . date('YmdHis', time());
  960. $export = [];
  961. $filekey = [];
  962. if (!empty($data)) {
  963. $i = 0;
  964. foreach ($data as $index => $item) {
  965. $one_data = $item;
  966. if ($type == 1) {
  967. $export[] = $one_data;
  968. if ($i == 0) {
  969. $filekey = array_keys($one_data);
  970. }
  971. } else {
  972. $export[] = array_values($one_data);
  973. }
  974. $i++;
  975. }
  976. }
  977. if ($type == 1) {
  978. return compact('header', 'filekey', 'export', 'filename');
  979. } else {
  980. return $this->export($header, $title, $export, $filename);
  981. }
  982. }
  983. /**
  984. * 会员卡导出
  985. * @param array $data
  986. * @param int $type
  987. * @return array|mixed
  988. */
  989. public function memberCard($data = [], $type = 1)
  990. {
  991. $header = ['会员卡号', '密码', '领取人', '领取人手机号', '领取时间', '是否使用'];
  992. $title = ['会员卡导出', '会员卡导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  993. $filename = $data['title'] ? ("卡密会员_" . trim(str_replace(["\r\n", "\r", "\\", "\n", "/", "<", ">", "=", " "], '', $data['title']))) : "";
  994. $export = [];
  995. $filekey = [];
  996. if (!empty($data)) {
  997. $i = 0;
  998. foreach ($data['data'] as $index => $item) {
  999. $one_data = [
  1000. 'card_number' => $item['card_number'],
  1001. 'card_password' => $item['card_password'],
  1002. 'user_name' => $item['user_name'],
  1003. 'user_phone' => $item['user_phone'],
  1004. 'use_time' => $item['use_time'],
  1005. 'use_uid' => $item['use_uid'] ? '已领取' : '未领取'
  1006. ];
  1007. if ($type == 1) {
  1008. $export[] = $one_data;
  1009. if ($i == 0) {
  1010. $filekey = array_keys($one_data);
  1011. }
  1012. } else {
  1013. $export[] = array_values($one_data);
  1014. }
  1015. $i++;
  1016. }
  1017. }
  1018. if ($type == 1) {
  1019. return compact('header', 'filekey', 'export', 'filename');
  1020. } else {
  1021. return $this->export($header, $title, $export, $filename);
  1022. }
  1023. }
  1024. /**
  1025. * 批量任务发货记录导出
  1026. * @param array $data
  1027. * @param $queueType
  1028. * @param int $type
  1029. * @return array|mixed
  1030. */
  1031. public function batchOrderDelivery($data = [], $queueType, $type = 1)
  1032. {
  1033. if (in_array($queueType, [7, 8])) {
  1034. $header = ['订单ID', '物流公司', '物流单号', '处理状态', '异常原因'];
  1035. }
  1036. if ($queueType == 9) {
  1037. $header = ['订单ID', '配送员姓名', '配送员电话', '处理状态', '异常原因'];
  1038. }
  1039. if ($queueType == 10) {
  1040. $header = ['订单ID', '虚拟发货内容', '处理状态', '异常原因'];
  1041. }
  1042. $title = ['发货记录导出', '发货记录导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  1043. $filename = '批量任务发货记录_' . date('YmdHis', time());
  1044. $export = [];
  1045. $filekey = [];
  1046. if (!empty($data)) {
  1047. $i = 0;
  1048. foreach ($data as $index => $item) {
  1049. if (!$item) {
  1050. continue;
  1051. }
  1052. if (in_array($queueType, [7, 8, 9])) {
  1053. $one_data = [
  1054. 'order_id' => $item['order_id'] ?? '',
  1055. 'delivery_name' => $item['delivery_name'] ?? '',
  1056. 'delivery_id' => $item['delivery_id'] ?? '',
  1057. 'status_cn' => $item['status_cn'] ?? '',
  1058. 'error' => $item['error'] ?? '',
  1059. ];
  1060. } else {
  1061. $one_data = [
  1062. 'order_id' => $item['order_id'] ?? '',
  1063. 'fictitious_content' => $item['fictitious_content'] ?? '',
  1064. 'status_cn' => $item['status_cn'] ?? '',
  1065. 'error' => $item['error'] ?? '',
  1066. ];
  1067. }
  1068. if ($type == 1) {
  1069. $export[] = $one_data;
  1070. if ($i == 0) {
  1071. $filekey = array_keys($one_data);
  1072. }
  1073. } else {
  1074. $export[] = array_values($one_data);
  1075. }
  1076. $i++;
  1077. }
  1078. }
  1079. if ($type == 1) {
  1080. return compact('header', 'filekey', 'export', 'filename');
  1081. } else {
  1082. return $this->export($header, $title, $export, $filename);
  1083. }
  1084. }
  1085. /**
  1086. * 物流公司对照表
  1087. * @param array $data
  1088. * @param int $type
  1089. * @return array|mixed
  1090. */
  1091. public function expressList($data = [], $type = 1)
  1092. {
  1093. $header = ['物流公司名称', '物流公司编码'];
  1094. $title = ['物流公司对照表导出', '物流公司对照表导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  1095. $filename = '物流公司对照表_' . date('YmdHis', time());
  1096. $export = [];
  1097. $filekey = [];
  1098. if (!empty($data)) {
  1099. $i = 0;
  1100. foreach ($data as $index => $item) {
  1101. $one_data = [
  1102. 'name' => $item['name'],
  1103. 'code' => $item['code'],
  1104. ];
  1105. if ($type == 1) {
  1106. $export[] = $one_data;
  1107. if ($i == 0) {
  1108. $filekey = array_keys($one_data);
  1109. }
  1110. } else {
  1111. $export[] = array_values($one_data);
  1112. }
  1113. $i++;
  1114. }
  1115. }
  1116. if ($type == 1) {
  1117. return compact('header', 'filekey', 'export', 'filename');
  1118. } else {
  1119. return $this->export($header, $title, $export, $filename);
  1120. }
  1121. }
  1122. /**
  1123. * 交易统计
  1124. * @param array $data
  1125. * @param string $tradeTitle
  1126. * @param int $type
  1127. * @return array|mixed
  1128. */
  1129. public function tradeData($data = [], $tradeTitle = "交易统计", $type = 1)
  1130. {
  1131. $header = ['时间'];
  1132. $title = [$tradeTitle, $tradeTitle, ' 生成时间:' . date('Y-m-d H:i:s', time())];
  1133. $filename = $tradeTitle . '_' . date('YmdHis', time());
  1134. $export = [];
  1135. $filekey = [];
  1136. if (!empty($data)) {
  1137. $headerArray = array_column($data['series'], 'name');
  1138. $header = array_merge($header, $headerArray);
  1139. $export = [];
  1140. foreach ($data['series'] as $index => $item) {
  1141. foreach ($data['x'] as $k => $v) {
  1142. $export[$v]['time'] = $v;
  1143. $export[$v][] = $item['value'][$k];
  1144. }
  1145. }
  1146. }
  1147. if ($type == 1) {
  1148. return compact('header', 'filekey', 'export', 'filename');
  1149. } else {
  1150. return $this->export($header, $title, $export, $filename);
  1151. }
  1152. }
  1153. /**
  1154. * 商品统计
  1155. * @param array $data
  1156. * @param int $type
  1157. * @return array|mixed
  1158. */
  1159. public function productTrade($data = [], $type = 1)
  1160. {
  1161. $header = ['日期/时间', '商品浏览量', '商品访客数', '加购件数', '下单件数', '支付件数', '支付金额', '成本金额', '退款金额', '退款件数', '访客-支付转化率'];
  1162. $title = ['商品统计', '商品统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  1163. $filename = '商品统计_' . date('YmdHis', time());
  1164. $export = [];
  1165. $filekey = [];
  1166. if (!empty($data)) {
  1167. $i = 0;
  1168. foreach ($data as $value) {
  1169. $one_data = [
  1170. 'time' => $value['time'],
  1171. 'browse' => $value['browse'],
  1172. 'user' => $value['user'],
  1173. 'cart' => $value['cart'],
  1174. 'order' => $value['order'],
  1175. 'payNum' => $value['payNum'],
  1176. 'pay' => $value['pay'],
  1177. 'cost' => $value['cost'],
  1178. 'refund' => $value['refund'],
  1179. 'refundNum' => $value['refundNum'],
  1180. 'changes' => $value['changes'] . '%'
  1181. ];
  1182. if ($type == 1) {
  1183. $export[] = $one_data;
  1184. if ($i == 0) {
  1185. $filekey = array_keys($one_data);
  1186. }
  1187. } else {
  1188. $export[] = array_values($one_data);
  1189. }
  1190. $i++;
  1191. }
  1192. }
  1193. if ($type == 1) {
  1194. return compact('header', 'filekey', 'export', 'filename');
  1195. } else {
  1196. return $this->export($header, $title, $export, $filename);
  1197. }
  1198. }
  1199. /**
  1200. * 用户统计
  1201. * @param array $data
  1202. * @param int $type
  1203. * @return array|mixed
  1204. */
  1205. public function userTrade($data = [], $type = 1)
  1206. {
  1207. $header = ['日期/时间', '访客数', '浏览量', '新增用户数', '成交用户数', '访客-支付转化率', '付费会员数', '充值用户数', '客单价'];
  1208. $title = ['用户统计', '用户统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  1209. $filename = '用户统计_' . date('YmdHis', time());
  1210. $export = [];
  1211. $filekey = [];
  1212. if (!empty($data)) {
  1213. $i = 0;
  1214. foreach ($data as $value) {
  1215. $one_data = [
  1216. 'time' => $value['time'],
  1217. 'user' => $value['user'],
  1218. 'browse' => $value['browse'],
  1219. 'new' => $value['new'],
  1220. 'paid' => $value['paid'],
  1221. 'changes' => $value['changes'] . '%',
  1222. 'vip' => $value['vip'],
  1223. 'recharge' => $value['recharge'],
  1224. 'payPrice' => $value['payPrice'],
  1225. ];
  1226. if ($type == 1) {
  1227. $export[] = $one_data;
  1228. if ($i == 0) {
  1229. $filekey = array_keys($one_data);
  1230. }
  1231. } else {
  1232. $export[] = array_values($one_data);
  1233. }
  1234. $i++;
  1235. }
  1236. }
  1237. if ($type == 1) {
  1238. return compact('header', 'filekey', 'export', 'filename');
  1239. } else {
  1240. return $this->export($header, $title, $export, $filename);
  1241. }
  1242. }
  1243. /**
  1244. * 导出积分兑换订单
  1245. * @param array $data
  1246. * @param int $type
  1247. * @return array|mixed
  1248. */
  1249. public function storeIntegralOrder($data = [], $type = 1)
  1250. {
  1251. $header = ['订单号', '电话', '收货人姓名', '收货人电话', '收货地址', '商品信息', '订单状态', '下单时间', '用户备注'];
  1252. $title = ['积分兑换订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
  1253. $filename = '积分兑换订单导出_' . date('YmdHis', time());
  1254. $export = [];
  1255. $filekey = [];
  1256. if (!empty($data)) {
  1257. $i = 0;
  1258. foreach ($data as $item) {
  1259. $one_data = [
  1260. 'order_id' => $item['order_id'],
  1261. 'phone' => $item['user_phone'],
  1262. 'real_name' => $item['real_name'],
  1263. 'user_phone' => $item['user_phone'],
  1264. 'user_address' => $item['user_address'],
  1265. 'goods_name' => $item['store_name'],
  1266. 'status_name' => $item['status_name'] ?? '未知状态',
  1267. 'add_time' => $item['add_time'],
  1268. 'mark' => $item['mark']
  1269. ];
  1270. if ($type == 1) {
  1271. $export[] = $one_data;
  1272. if ($i == 0) {
  1273. $filekey = array_keys($one_data);
  1274. }
  1275. } else {
  1276. $export[] = array_values($one_data);
  1277. }
  1278. $i++;
  1279. }
  1280. }
  1281. if ($type == 1) {
  1282. return compact('header', 'filekey', 'export', 'filename');
  1283. } else {
  1284. return $this->export($header, $title, $export, $filename);
  1285. }
  1286. }
  1287. /**
  1288. * 门店账单导出
  1289. * @param array $data
  1290. * @param int $type
  1291. * @return array|mixed
  1292. */
  1293. public function financeRecord($data = [], $name = '账单导出', $type = 1)
  1294. {
  1295. $header = ['交易单号', '关联订单', '交易时间', '交易金额', '支出收入', '交易人', '关联店员', '交易类型', '支付方式'];
  1296. $title = [$name, $name . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  1297. $filename = $name . date('YmdHis', time());
  1298. $export = [];
  1299. $filekey = [];
  1300. if (!empty($data)) {
  1301. $i = 0;
  1302. foreach ($data as $key => $item) {
  1303. $one_data = [
  1304. 'order_id' => $item['order_id'],
  1305. 'link_id' => $item['link_id'],
  1306. 'trade_time' => $item['trade_time'],
  1307. 'number' => $item['number'],
  1308. 'pm' => $item['pm'] == 1 ? '收入' : '支出',
  1309. 'user_nickname' => $item['user_nickname'],
  1310. 'staff_name' => $item['staff_name'] ?? '',
  1311. 'type_name' => $item['type_name'],
  1312. 'pay_type_name' => $item['pay_type_name'],
  1313. ];
  1314. if ($type == 1) {
  1315. $export[] = $one_data;
  1316. if ($i == 0) {
  1317. $filekey = array_keys($one_data);
  1318. }
  1319. } else {
  1320. $export[] = array_values($one_data);
  1321. }
  1322. $i++;
  1323. }
  1324. }
  1325. if ($type == 1) {
  1326. return compact('header', 'filekey', 'export', 'filename');
  1327. } else {
  1328. return $this->export($header, $title, $export, $filename);
  1329. }
  1330. }
  1331. /**
  1332. * 供应商账单导出
  1333. * @param array $data
  1334. * @param int $type
  1335. * @return array|mixed
  1336. */
  1337. public function SupplierFinanceRecord($data = [], $name = '账单导出', $type = 1)
  1338. {
  1339. $header = ['交易单号', '关联订单', '交易时间', '交易金额', '支出收入', '交易人', '交易类型', '支付方式'];
  1340. $title = [$name, $name . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  1341. $filename = $name . date('YmdHis', time());
  1342. $export = [];
  1343. $filekey = [];
  1344. if (!empty($data)) {
  1345. $i = 0;
  1346. foreach ($data as $key => $item) {
  1347. $one_data = [
  1348. 'order_id' => $item['order_id'],
  1349. 'link_id' => $item['link_id'],
  1350. 'trade_time' => $item['trade_time'],
  1351. 'number' => $item['number'],
  1352. 'pm' => $item['pm'] == 1 ? '收入' : '支出',
  1353. 'user_nickname' => $item['user_nickname'],
  1354. 'type_name' => $item['type_name'],
  1355. 'pay_type_name' => $item['pay_type_name'],
  1356. ];
  1357. if ($type == 1) {
  1358. $export[] = $one_data;
  1359. if ($i == 0) {
  1360. $filekey = array_keys($one_data);
  1361. }
  1362. } else {
  1363. $export[] = array_values($one_data);
  1364. }
  1365. $i++;
  1366. }
  1367. }
  1368. if ($type == 1) {
  1369. return compact('header', 'filekey', 'export', 'filename');
  1370. } else {
  1371. return $this->export($header, $title, $export, $filename);
  1372. }
  1373. }
  1374. /**
  1375. * @param array $data
  1376. * @param int $type
  1377. * @return array|mixed
  1378. */
  1379. public function vipOrder(array $data, int $type = 1)
  1380. {
  1381. $header = ['订单号', '用户名', '手机号', '会员类型', '有效期限', '支付金额', '支付方式', '购买时间', '到期时间'];
  1382. $title = ['会员订单', '会员订单' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  1383. $filename = '会员订单' . date('YmdHis', time());
  1384. $export = [];
  1385. $filekey = [];
  1386. if (!empty($data)) {
  1387. $i = 0;
  1388. foreach ($data as $key => $item) {
  1389. $one_data = [
  1390. 'order_id' => $item['order_id'],
  1391. 'nickname' => $item['user']['nickname'] ?? '',
  1392. 'phone' => $item['user']['phone'] ?? '',
  1393. 'member_type' => $item['member_type'],
  1394. 'vip_day' => $item['vip_day'],
  1395. 'pay_price' => $item['pay_price'],
  1396. 'pay_type' => $item['pay_type'],
  1397. 'pay_time' => $item['pay_time'],
  1398. 'overdue_time' => $item['overdue_time']
  1399. ];
  1400. if ($type == 1) {
  1401. $export[] = $one_data;
  1402. if ($i == 0) {
  1403. $filekey = array_keys($one_data);
  1404. }
  1405. } else {
  1406. $export[] = array_values($one_data);
  1407. }
  1408. $i++;
  1409. }
  1410. }
  1411. if ($type == 1) {
  1412. return compact('header', 'filekey', 'export', 'filename');
  1413. } else {
  1414. return $this->export($header, $title, $export, $filename);
  1415. }
  1416. }
  1417. /**
  1418. * 发票导出
  1419. * @param array $data
  1420. * @param int $type
  1421. * @return array|mixed
  1422. */
  1423. public function invoiceRecord(array $data, int $type = 1)
  1424. {
  1425. $header = ['订单号', '订单金额', '发票类型', '发票抬头类型', '发票抬头名称', '下单时间', '开票状态', '订单状态'];
  1426. $title = ['发票导出', '发票导出' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  1427. $filename = '发票导出' . date('YmdHis', time());
  1428. $export = [];
  1429. $filekey = [];
  1430. if (!empty($data)) {
  1431. $i = 0;
  1432. foreach ($data as $key => $item) {
  1433. $one_data = [
  1434. 'order_id' => $item['order_id'],
  1435. 'pay_price' => $item['pay_price'],
  1436. 'type' => $item['type'] == 1 ? '电子普通发票' : '纸质专用发票',
  1437. 'header_type' => $item['header_type'] == 1 ? '个人' : '企业',
  1438. 'name' => $item['name'],
  1439. 'add_time' => $item['add_time'],
  1440. 'is_invoice' => $item['is_invoice'] == 1 ? '已开票' : '未开票'
  1441. ];
  1442. if ($item['refund_status'] > 0) {
  1443. if ($item['refund_status'] == 1) {
  1444. $one_data['status'] = '退款中';
  1445. } else {
  1446. $one_data['status'] = '已退款';
  1447. }
  1448. } else {
  1449. if ($item['status'] == 0) {
  1450. $one_data['status'] = '未发货';
  1451. } elseif ($item['status'] == 1) {
  1452. $one_data['status'] = '待收货';
  1453. } elseif ($item['status'] == 2) {
  1454. $one_data['status'] = '待评价';
  1455. } elseif ($item['status'] == 3) {
  1456. $one_data['status'] = '已完成';
  1457. }
  1458. }
  1459. if ($type == 1) {
  1460. $export[] = $one_data;
  1461. if ($i == 0) {
  1462. $filekey = array_keys($one_data);
  1463. }
  1464. } else {
  1465. $export[] = array_values($one_data);
  1466. }
  1467. $i++;
  1468. }
  1469. }
  1470. if ($type == 1) {
  1471. return compact('header', 'filekey', 'export', 'filename');
  1472. } else {
  1473. return $this->export($header, $title, $export, $filename);
  1474. }
  1475. }
  1476. /**
  1477. * 系统表单收集数据导出
  1478. * @param array $data
  1479. * @param int $type
  1480. * @return array|mixed
  1481. */
  1482. public function systemFormData(array $data, int $type = 1)
  1483. {
  1484. $header = ['模版名称', '用户UID', '用户昵称', '手机号', '模版内容', '创建时间'];
  1485. $title = ['系统表单收集数据导出', '表单收集数据导出' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
  1486. $filename = '系统表单收集数据导出' . date('YmdHis', time());
  1487. $export = [];
  1488. $filekey = [];
  1489. if (!empty($data)) {
  1490. $i = 0;
  1491. foreach ($data as $key => $item) {
  1492. $one_data = [
  1493. 'system_form_name' => $item['system_form_name'] ?? '',
  1494. 'uid' => $item['uid'] ?? 0,
  1495. 'nickname' => $item['nickname'] ?? '',
  1496. 'phone' => $item['phone'] ?? '',
  1497. 'form_data' => is_string($item['value']) ? json_decode($item['value']) : $item['value'],
  1498. 'add_time' => $item['add_time'],
  1499. ];
  1500. if ($type == 1) {
  1501. $export[] = $one_data;
  1502. if ($i == 0) {
  1503. $filekey = array_keys($one_data);
  1504. }
  1505. } else {
  1506. $export[] = array_values($one_data);
  1507. }
  1508. $i++;
  1509. }
  1510. }
  1511. if ($type == 1) {
  1512. return compact('header', 'filekey', 'export', 'filename');
  1513. } else {
  1514. return $this->export($header, $title, $export, $filename);
  1515. }
  1516. }
  1517. }