1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\services\other\export;
- use app\model\user\User;
- use app\services\BaseServices;
- use app\jobs\system\ExportExcelJob;
- use app\services\pay\PayServices;
- use app\services\user\UserServices;
- use Cassandra\Exception\UnavailableException;
- use crmeb\services\SpreadsheetExcelService;
- use crmeb\services\WithdrawService;
- /**
- * 导出
- * Class ExportServices
- * @package app\services\other\export
- */
- class ExportServices extends BaseServices
- {
- /**
- * 不分页拆分处理最大条数
- * @var int
- */
- public $maxLimit = 1000;
- /**
- * 分页导出每页条数
- * @var int
- */
- public $limit = 1000;
- /**
- * 真实请求导出
- * @param $header excel表头
- * @param $title 标题
- * @param array $export 填充数据
- * @param string $filename 保存文件名称
- * @param string $suffix 保存文件后缀
- * @param bool $is_save true|false 是否保存到本地
- * @return mixed
- */
- public function export(array $header, array $title_arr, array $export = [], string $filename = '', string $suffix = 'xlsx', bool $is_save = true)
- {
- $path = [];
- $exportNum = count($export);
- $limit = $this->maxLimit;
- if ($exportNum < $limit) {
- $title = isset($title_arr[0]) && !empty($title_arr[0]) ? $title_arr[0] : '导出数据';
- $name = isset($title_arr[1]) && !empty($title_arr[1]) ? $title_arr[1] : '导出数据';
- $info = isset($title_arr[2]) && !empty($title_arr[2]) ? $title_arr[2] : date('Y-m-d H:i:s', time());
- $filePath = SpreadsheetExcelService::instance()->setExcelHeader($header)
- ->setExcelTile($title, $name, $info)
- ->setExcelContent($export)
- ->excelSave($filename, $suffix, $is_save);
- $path[] = sys_config('site_url') . $filePath;
- } else {
- $data = [];
- $i = $j = 0;
- $basePath = sys_config('site_url') . '/phpExcel/';
- foreach ($export as $item) {
- $data[] = $item;
- $i++;
- if ($limit <= 1 || $i == $exportNum) {
- if ($j > 0) {
- $filename .= '_' . $j;
- $header = [];
- $title_arr = [];
- }
- //加入队列
- ExportExcelJob::dispatch([$data, $filename, $header, $title_arr, $suffix, $is_save]);
- $path[] = $basePath . $filename . '.' . $suffix;
- $data = [];
- $limit = $this->limit + 1;
- $j++;
- }
- $limit--;
- }
- }
- return $path;
- }
- /**
- * 用户资金导出
- * @param array $data
- * @param int $type 1:直接返回数据前端生成excel 2:后台生成excel
- * @return array|mixed
- */
- public function userFinance($data = [], $type = 1)
- {
- $header = ['会员ID', '昵称', '金额', '类型', '备注', '创建时间'];
- $title = ['资金监控', '资金监控', date('Y-m-d H:i:s', time())];
- $filename = '资金监控_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $value) {
- $one_data = [
- 'uid' => $value['uid'],
- 'nickname' => $value['nickname'],
- 'pm' => $value['pm'] == 0 ? '-' . $value['number'] : $value['number'],
- 'title' => $value['title'],
- 'mark' => $value['mark'],
- 'add_time' => $value['add_time'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 用户佣金导出
- * @param $data 导出数据
- */
- public function userCommission($data = [], $type = 1)
- {
- $header = ['昵称/姓名', '总佣金金额', '账户余额', '账户佣金', '提现到账佣金', '时间'];
- $title = ['佣金记录', '佣金记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '佣金记录_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $value) {
- $one_data = [
- 'nickname' => $value['nickname'],
- 'sum_number' => $value['sum_number'],
- 'now_money' => $value['now_money'],
- 'brokerage_price' => $value['brokerage_price'],
- 'extract_price' => $value['extract_price'],
- 'time' => $value['time']
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 用户积分导出
- * @param $data 导出数据
- */
- public function userPoint($data = [], $type = 1)
- {
- $header = ['编号', '标题', '变动后积分', '积分变动', '备注', '用户微信昵称', '添加时间'];
- $title = ['积分日志', '积分日志' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '积分日志_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $key => $item) {
- $one_data = [
- 'id' => $item['id'],
- 'title' => $item['title'],
- 'balance' => $item['balance'],
- 'number' => $item['number'],
- 'mark' => $item['mark'],
- 'nickname' => $item['nickname'],
- 'add_time' => $item['add_time'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 用户充值导出
- * @param $data 导出数据
- */
- public function userRecharge($data = [], $type = 1)
- {
- $header = ['昵称/姓名', '充值金额', '是否支付', '充值类型', '支付时间', '是否退款', '添加时间'];
- $title = ['充值记录', '充值记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '充值记录_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $item) {
- switch ($item['recharge_type']) {
- case 'routine':
- $item['_recharge_type'] = '小程序充值';
- break;
- case 'weixin':
- $item['_recharge_type'] = '公众号充值';
- break;
- case 'balance':
- $item['_recharge_type'] = '佣金转入';
- break;
- case 'store':
- $item['_recharge_type'] = '门店余额充值';
- break;
- default:
- $item['_recharge_type'] = '其他充值';
- break;
- }
- $item['_pay_time'] = $item['pay_time'] ? date('Y-m-d H:i:s', $item['pay_time']) : '暂无';
- $item['_add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '暂无';
- $item['paid_type'] = $item['paid'] ? '已支付' : '未支付';
- $one_data = [
- 'nickname' => $item['nickname'],
- 'price' => $item['price'],
- 'paid_type' => $item['paid_type'],
- '_recharge_type' => $item['_recharge_type'],
- '_pay_time' => $item['_pay_time'],
- 'paid' => $item['paid'] == 1 && $item['refund_price'] == $item['price'] ? '已退款' : '未退款',
- '_add_time' => $item['_add_time']
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 用户推广导出
- * @param $data 导出数据
- */
- public function userAgent($data = [], $type = 1)
- {
- $header = ['用户编号', '昵称', '电话号码', '推广用户数量', '订单数量', '推广订单金额', '佣金金额', '已提现金额', '提现次数', '未提现金额', '上级推广人'];
- $title = ['推广用户', '推广用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '推广用户_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = [
- 'uid' => $item['uid'],
- 'nickname' => $item['nickname'],
- 'phone' => $item['phone'],
- 'spread_count' => $item['spread_count'],
- 'order_count' => $item['order_count'],
- 'order_price' => $item['order_price'],
- 'brokerage_money' => $item['brokerage_money'],
- 'extract_count_price' => $item['extract_count_price'],
- 'extract_count_num' => $item['extract_count_num'],
- 'brokerage_price' => $item['brokerage_price'],
- 'spread_name' => $item['spread_name'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 微信用户导出
- * @param $data 导出数据
- */
- public function wechatUser($data = [], $type = 1)
- {
- $header = ['名称', '性别', '地区', '是否关注公众号'];
- $title = ['微信用户导出', '微信用户导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '微信用户导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = [
- 'nickname' => $item['nickname'],
- 'sex' => $item['sex'],
- 'address' => $item['country'] . $item['province'] . $item['city'],
- 'subscribe' => $item['subscribe'] == 1 ? '关注' : '未关注',
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 订单资金导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function orderFinance($data = [], $type = 1)
- {
- $header = ['时间', '营业额(元)', '支出(元)', '成本', '优惠', '积分抵扣', '盈利(元)'];
- $title = ['财务统计', '财务统计', date('Y-m-d H:i:s', time())];
- $filename = '财务统计_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $info) {
- $time = $info['pay_time'];
- $price = $info['total_price'] + $info['pay_postage'];
- $zhichu = $info['coupon_price'] + $info['deduction_price'] + $info['cost'];
- $profit = ($info['total_price'] + $info['pay_postage']) - ($info['coupon_price'] + $info['deduction_price'] + $info['cost']);
- $deduction = $info['deduction_price'];//积分抵扣
- $coupon = $info['coupon_price'];//优惠
- $cost = $info['cost'];//成本
- $one_data = compact('time', 'price', 'zhichu', 'cost', 'coupon', 'deduction', 'profit');
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 砍价活动导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function storeBargain($data = [], $type = 1)
- {
- $header = ['砍价活动名称', '砍价活动简介', '砍价金额', '砍价最低价',
- '用户每次砍价的次数', '砍价状态', '砍价开启时间', '砍价结束时间', '销量', '库存', '返多少积分', '添加时间'];
- $title = ['砍价商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '砍价商品导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = [
- 'title' => $item['title'],
- 'info' => $item['info'],
- 'price' => '¥' . $item['price'],
- 'bargain_max_price' => '¥' . $item['min_price'],
- 'bargain_num' => $item['bargain_num'],
- 'status' => $item['status'] ? '开启' : '关闭',
- 'start_time' => empty($item['start_time']) ? '' : date('Y-m-d H:i:s', (int)$item['start_time']),
- 'stop_time' => empty($item['stop_time']) ? '' : date('Y-m-d H:i:s', (int)$item['stop_time']),
- 'sales' => $item['sales'],
- 'stock' => $item['stock'],
- 'give_integral' => $item['give_integral'],
- 'add_time' => empty($item['add_time']) ? '' : $item['add_time'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 拼团导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function storeCombination($data = [], $type = 1)
- {
- $header = ['编号', '拼团名称', '原价', '拼团价', '库存', '拼团人数', '参与人数', '成团数量', '销量', '商品状态', '结束时间'];
- $title = ['拼团商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '拼团商品导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $item) {
- $one_data = [
- 'id' => $item['id'],
- 'title' => $item['title'],
- 'ot_price' => $item['ot_price'],
- 'price' => $item['price'],
- 'stock' => $item['stock'],
- 'people' => $item['count_people'],
- 'count_people_all' => $item['count_people_all'],
- 'count_people_pink' => $item['count_people_pink'],
- 'sales' => $item['sales'] ?? 0,
- 'is_show' => $item['is_show'] ? '开启' : '关闭',
- 'stop_time' => empty($item['stop_time']) ? '' : date('Y/m/d H:i:s', (int)$item['stop_time'])
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 秒杀活动导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function storeSeckill($data = [], $type = 1)
- {
- $header = ['编号', '活动标题', '活动简介', '原价', '秒杀价', '限量', '限量剩余', '秒杀状态', '结束时间', '状态'];
- $title = ['秒杀商品导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '秒杀商品导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $item) {
- if ($item['status']) {
- if ($item['start_time'] > time())
- $item['start_name'] = '活动未开始';
- else if ($item['stop_time'] < time())
- $item['start_name'] = '活动已结束';
- else if ($item['stop_time'] > time() && $item['start_time'] < time())
- $item['start_name'] = '正在进行中';
- } else {
- $item['start_name'] = '活动已结束';
- }
- $one_data = [
- 'id' => $item['id'],
- 'title' => $item['title'],
- 'info' => $item['info'],
- 'ot_price' => $item['ot_price'],
- 'price' => $item['price'],
- 'quota_show' => $item['quota_show'],
- 'quota' => $item['quota'],
- 'start_name' => $item['start_name'],
- 'stop_time' => $item['stop_time'] ? date('Y-m-d H:i:s', $item['stop_time']) : '/',
- 'status' => $item['status'] ? '开启' : '关闭',
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 导出商品卡号、卡密模版
- * @param int $type
- * @return array|mixed
- */
- public function storeProductCardTemplate($type = 1)
- {
- $header = ['卡号', '卡密'];
- $title = ['商品卡密模版', '商品密' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '商品卡密模版_' . date('YmdHis', time());
- if ($type == 1) {
- $export = [];
- $filekey = ['card_no', 'card_pwd'];
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, [], $filename);
- }
- }
- /**
- * 商品导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function storeProduct($data = [], $type = 1)
- {
- $header = ['商品名称', '商品简介', '商品分类', '价格', '库存', '销量', '浏览量'];
- $title = ['商品导出', '商品信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '商品导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = [
- 'store_name' => $item['store_name'],
- 'store_info' => $item['store_info'],
- 'cate_name' => $item['cate_name'],
- 'price' => '¥' . $item['price'],
- 'stock' => $item['stock'],
- 'sales' => $item['sales'],
- 'visitor' => $item['visitor'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 商铺订单导出
- * @param array $data
- * @param string $type
- * @param int $export_type
- * @return array|mixed
- */
- public function storeOrder($data = [], $type = "", $export_type = 1)
- {
- if (!$type) {
- $header = ['订单ID', '订单编号', '性别', '电话', '收货人姓名', '收货人电话', '收货地址', '商品信息', '商品总数',
- '总价格', '实际支付', '邮费', '会员优惠金额', '优惠卷金额', '积分抵扣金额', '支付状态', '支付时间', '订单状态', '下单时间', '用户备注'];
- $title = ['订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '订单导出_' . date('YmdHis', time());
- } else {
- $header = ['订单ID', '订单编号', '物流公司', '物流编码', '物流单号', '发货地址', '收货人姓名', '收货人电话', '订单实付金额', '商品数量*售价', '商品ID', '商品名称', '商品规格', '商家备注', '订单成交时间'];
- $title = ['发货单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '发货单导出_' . date('YmdHis', time());
- }
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $item) {
- if (!$type) {
- if ($item['paid'] == 1) {
- switch ($item['pay_type']) {
- case PayServices::WEIXIN_PAY:
- $item['pay_type_name'] = '微信支付';
- break;
- case PayServices::YUE_PAY:
- $item['pay_type_name'] = '余额支付';
- break;
- case PayServices::OFFLINE_PAY:
- $item['pay_type_name'] = '线下支付';
- break;
- case PayServices::ALIAPY_PAY:
- $item['pay_type_name'] = '支付宝支付';
- break;
- case PayServices::CASH_PAY:
- $item['pay_type_name'] = '现金支付';
- break;
- default:
- $item['pay_type_name'] = '其他支付';
- break;
- }
- } else {
- switch ($item['pay_type']) {
- default:
- $item['pay_type_name'] = '未支付';
- break;
- case 'offline':
- $item['pay_type_name'] = '线下支付';
- $item['pay_type_info'] = 1;
- break;
- }
- }
- if ($item['paid'] == 0 && $item['status'] == 0) {
- $item['status_name'] = '未支付';
- } else if ($item['paid'] == 1 && $item['status'] == 4 && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
- $item['status_name'] = '部分发货';
- } else if ($item['paid'] == 1 && $item['status'] == 5 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
- $item['status_name'] = '部分核销';
- } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
- $item['status_name'] = '申请退款';
- } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
- $item['status_name'] = '已退款';
- } else if ($item['paid'] == 1 && $item['refund_status'] == 4) {
- $item['status_name'] = '退款中';
- } else if ($item['paid'] == 1 && $item['status'] == 0 && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
- $item['status_name'] = '未发货';
- } else if ($item['paid'] == 1 && in_array($item['status'], [0, 1]) && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
- $item['status_name'] = '未核销';
- } else if ($item['paid'] == 1 && in_array($item['status'], [1, 5]) && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
- $item['status_name'] = '待收货';
- } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
- $item['status_name'] = '待评价';
- } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
- $item['status_name'] = '已完成';
- } else if ($item['paid'] == 1 && $item['refund_status'] == 3) {
- $item['status_name'] = '部分退款';
- }
- $goodsName = [];
- $vip_sum_price = 0;
- foreach ($item['_info'] as $k => $v) {
- $suk = '';
- if (isset($v['productInfo']['attrInfo'])) {
- if (isset($v['productInfo']['attrInfo']['suk'])) {
- $suk = '(' . $v['productInfo']['attrInfo']['suk'] . ')';
- }
- }
- if (isset($v['productInfo']['store_name'])) {
- $goodsName[] = implode(' ',
- [
- $v['productInfo']['store_name'],
- $suk,
- "[{$v['cart_num']} * {$v['truePrice']}]",
- ]);
- }
- $vip_sum_price = bcadd((string)$vip_sum_price, bcmul($v['vip_truePrice'], $v['cart_num'] ? $v['cart_num'] : 1, 4), 2);
- }
- if ($item['sex'] == 1) $sex_name = '男';
- else if ($item['sex'] == 2) $sex_name = '女';
- else $sex_name = '未知';
- $one_data = [
- 'id' => $item['id'],
- 'order_id' => $item['order_id'],
- 'sex' => $sex_name,
- 'phone' => $item['user_phone'],
- 'real_name' => $item['real_name'],
- 'user_phone' => $item['user_phone'],
- 'user_address' => $item['user_address'],
- 'goods_name' => $goodsName ? implode("\n", $goodsName) : '',
- 'total_num' => $item['total_num'],
- 'total_price' => $item['total_price'],
- 'pay_price' => $item['pay_price'],
- 'pay_postage' => $item['pay_postage'],
- 'vip_sum_price' => $vip_sum_price,
- 'coupon_price' => $item['coupon_price'],
- 'deduction_price' => $item['deduction_price'] ?? 0,
- 'pay_type_name' => $item['pay_type_name'],
- 'pay_time' => $item['pay_time'] > 0 ? date('Y/m-d H:i', (int)$item['pay_time']) : '暂无',
- 'status_name' => $item['status_name'] ?? '未知状态',
- 'add_time' => empty($item['add_time']) ? 0 : date('Y-m-d H:i:s', (int)$item['add_time']),
- 'mark' => $item['mark']
- ];
- } else {
- if (isset($item['pinkStatus']) && $item['pinkStatus'] != 2) {
- continue;
- }
- if (isset($item['refund']) && $item['refund']) {
- continue;
- }
- $goodsName = [];
- $g = 0;
- foreach ($item['_info'] as $k => $v) {
- $goodsName['cart_num'][$g] = $v['cart_num'] . ' * ' . ($v['productInfo']['attrInfo']['price'] ?? $v['productInfo']['price'] ?? 0.00);
- $goodsName['product_id'][$g] = $v['product_id'];
- $suk = $barCode = $code = '';
- if (!empty($v['productInfo']['attrInfo']['bar_code'])) {
- $barCode = $v['productInfo']['attrInfo']['bar_code'];
- }
- if (!empty($v['productInfo']['attrInfo']['code'])) {
- $code = $v['productInfo']['attrInfo']['code'];
- }
- if (isset($v['productInfo']['attrInfo'])) {
- if (isset($v['productInfo']['attrInfo']['suk'])) {
- $suk = '(' . $v['productInfo']['attrInfo']['suk'] . '|条码:' . $barCode . '|编码:' . $code . ')';
- }
- }
- $name = [];
- if (isset($v['productInfo']['store_name'])) {
- $name[] = implode(' ',
- [
- $v['productInfo']['store_name'],
- $suk,
- "[{$v['cart_num']} * {$v['truePrice']}]",
- ]);
- }
- $goodsName['goods_name'][$g] = implode(' ', $name);
- $goodsName['attr'][$g] = $v['productInfo']['attrInfo']['suk'] ?? '';
- $g++;
- }
- $one_data = [
- 'id' => $item['id'],
- 'order_id' => $item['order_id'],
- 'a' => "",
- 'b' => "",
- 'c' => "",
- 'user_address' => $item['user_address'],
- 'real_name' => $item['real_name'],
- 'user_phone' => $item['user_phone'],
- 'pay_price' => $item['pay_price'],
- 'cart_num' => isset($goodsName['cart_num']) ? implode("\n", $goodsName['cart_num']) : '',
- 'product_id' => isset($goodsName['product_id']) ? implode("\n", $goodsName['product_id']) : '',
- 'goods_name' => isset($goodsName['goods_name']) ? implode("\n", $goodsName['goods_name']) : '',
- 'attr' => isset($goodsName['attr']) ? implode("\n", $goodsName['attr']) : '',
- 'remark' => $item['remark'],
- 'pay_time' => $item['pay_time'] ? date('Y-m-d H:i:s', (int)$item['pay_time']) : '暂无',
- ];
- }
- if ($export_type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($export_type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * @param string $str
- * @return false|string|string[]|null
- */
- public function strToUtf8($str = '')
- {
- $current_encode = mb_detect_encoding($str, array("ASCII", "GB2312", "GBK", 'BIG5', 'UTF-8'));
- $encoded_str = mb_convert_encoding($str, 'UTF-8', $current_encode);
- return $encoded_str;
- }
- /**
- * 商铺自提点导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function storeMerchant($data = [], $type = 1)
- {
- $header = ['提货点名称', '提货点', '地址', '营业时间', '状态'];
- $title = ['提货点导出', '提货点信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '提货点导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = [
- 'name' => $item['name'],
- 'phone' => $item['phone'],
- 'address' => $item['address'] . '' . $item['detailed_address'],
- 'day_time' => $item['day_time'],
- 'is_show' => $item['is_show'] ? '开启' : '关闭'
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 商铺自提点导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function extract($data = [], $type = 1)
- {
- $header = ['收款账号', '收款人名称', '收款银行', '金额', '用途', '状态'];
- $title = ['用户提现导出', '用户提现信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '用户提现导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- // if ($item['bank_address'] == '灵活用工提现' && $item['status'] == 0) {
- // $userServices = app()->make(UserServices::class);
- // $userInfo = $userServices->get($item['uid']);
- // if (!$userInfo['professional_id']) {
- // throw new UnavailableException('用户未认证签约');
- // }
- // $bankInfo = WithdrawService::init()::contractInfo($userInfo['enterprise_professional_facilitator_id']);
- // if (!$bankInfo['sign_img']) throw new UnavailableException('用户未签约');
- // $one_data = [
- // 'bank_code' => $bankInfo['bank_code'],
- // 'real_name' => $bankInfo['name'],
- // 'bank_address' => '未知',
- // 'extract_price' => $item['extract_price'],
- // 'mark' => '工资发放',
- // 'status' => ($item['status'] == 1 ? '通过' : ($item['status'] == 0 ? '申请中' : '未通过'))
- // ];
- // } else
- $one_data = [
- 'bank_code' => $item['bank_code'],
- 'real_name' => $item['real_name'],
- 'bank_address' => $item['bank_address'],
- 'extract_price' => $item['extract_price'],
- 'mark' => '工资发放',
- 'status' => ($item['status'] == 1 ? '通过' : ($item['status'] == 0 ? '申请中' : '未通过'))
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 商铺自提点导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function exchange($data = [], $type = 1)
- {
- $header = ['交易账号', '姓名', '银行', '交易账号', '银行卡号', '身份证号', '联系电话', '申购价额', '申购份额', '冻结份额', '封闭期'];
- $title = ['用户能量转份额导出', '用户能量转份额信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '用户能量转份额导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = [
- 'trade_no' => '',
- 'real_name' => $item['user']['real_name'] ?? '--',
- 'bank' => $item['bank_address'],
- 'account' => $item['account'],
- 'bank_code' => $item['bank_code'],
- 'id_card' => $item['user']['card_id'] ?? '--',
- 'phone' => $item['user']['phone']?? '--',
- 'extract_price' => $item['extract_price'],
- 'exchange_num' => $item['exchange_num'],
- 'freeze_num' => '',
- 'lock_time' => ''
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 商铺自提点导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function extractInfo($data = [], $type = 1, $month = '')
- {
- $header = ['姓名', '证件号码', '所得项目', '收入', '费用', '免税收入', '扣除项目合计', '应纳税所得额', '税率/预扣率', '速算扣除数', '应纳税额', '减免税额', '应扣缴税额', '已缴税额', '应补(退)税额'];
- $title = [($month ?: date('Y-m')) . '月用户提现统计', '用户提现统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = ($month ?: date('Y-m')) . '月用户提现统计_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = $item;
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 会员卡导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function memberCard($data = [], $type = 1)
- {
- $header = ['会员卡号', '密码', '领取人', '领取人手机号', '领取时间', '是否使用'];
- $title = ['会员卡导出', '会员卡导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = $data['title'] ? ("卡密会员_" . trim(str_replace(["\r\n", "\r", "\\", "\n", "/", "<", ">", "=", " "], '', $data['title']))) : "";
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data['data'] as $index => $item) {
- $one_data = [
- 'card_number' => $item['card_number'],
- 'card_password' => $item['card_password'],
- 'user_name' => $item['user_name'],
- 'user_phone' => $item['user_phone'],
- 'use_time' => $item['use_time'],
- 'use_uid' => $item['use_uid'] ? '已领取' : '未领取'
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 批量任务发货记录导出
- * @param array $data
- * @param $queueType
- * @param int $type
- * @return array|mixed
- */
- public function batchOrderDelivery($data = [], $queueType, $type = 1)
- {
- if (in_array($queueType, [7, 8])) {
- $header = ['订单ID', '物流公司', '物流单号', '处理状态', '异常原因'];
- }
- if ($queueType == 9) {
- $header = ['订单ID', '配送员姓名', '配送员电话', '处理状态', '异常原因'];
- }
- if ($queueType == 10) {
- $header = ['订单ID', '虚拟发货内容', '处理状态', '异常原因'];
- }
- $title = ['发货记录导出', '发货记录导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '批量任务发货记录_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- if (!$item) {
- continue;
- }
- if (in_array($queueType, [7, 8, 9])) {
- $one_data = [
- 'order_id' => $item['order_id'] ?? '',
- 'delivery_name' => $item['delivery_name'] ?? '',
- 'delivery_id' => $item['delivery_id'] ?? '',
- 'status_cn' => $item['status_cn'] ?? '',
- 'error' => $item['error'] ?? '',
- ];
- } else {
- $one_data = [
- 'order_id' => $item['order_id'] ?? '',
- 'fictitious_content' => $item['fictitious_content'] ?? '',
- 'status_cn' => $item['status_cn'] ?? '',
- 'error' => $item['error'] ?? '',
- ];
- }
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 物流公司对照表
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function expressList($data = [], $type = 1)
- {
- $header = ['物流公司名称', '物流公司编码'];
- $title = ['物流公司对照表导出', '物流公司对照表导出' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '物流公司对照表_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $index => $item) {
- $one_data = [
- 'name' => $item['name'],
- 'code' => $item['code'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 交易统计
- * @param array $data
- * @param string $tradeTitle
- * @param int $type
- * @return array|mixed
- */
- public function tradeData($data = [], $tradeTitle = "交易统计", $type = 1)
- {
- $header = ['时间'];
- $title = [$tradeTitle, $tradeTitle, ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = $tradeTitle . '_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $headerArray = array_column($data['series'], 'name');
- $header = array_merge($header, $headerArray);
- $export = [];
- foreach ($data['series'] as $index => $item) {
- foreach ($data['x'] as $k => $v) {
- $export[$v]['time'] = $v;
- $export[$v][] = $item['value'][$k];
- }
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 商品统计
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function productTrade($data = [], $type = 1)
- {
- $header = ['日期/时间', '商品浏览量', '商品访客数', '加购件数', '下单件数', '支付件数', '支付金额', '成本金额', '退款金额', '退款件数', '访客-支付转化率'];
- $title = ['商品统计', '商品统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '商品统计_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $value) {
- $one_data = [
- 'time' => $value['time'],
- 'browse' => $value['browse'],
- 'user' => $value['user'],
- 'cart' => $value['cart'],
- 'order' => $value['order'],
- 'payNum' => $value['payNum'],
- 'pay' => $value['pay'],
- 'cost' => $value['cost'],
- 'refund' => $value['refund'],
- 'refundNum' => $value['refundNum'],
- 'changes' => $value['changes'] . '%'
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 用户统计
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function userTrade($data = [], $type = 1)
- {
- $header = ['日期/时间', '访客数', '浏览量', '新增用户数', '成交用户数', '访客-支付转化率', '付费会员数', '充值用户数', '客单价'];
- $title = ['用户统计', '用户统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '用户统计_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $value) {
- $one_data = [
- 'time' => $value['time'],
- 'user' => $value['user'],
- 'browse' => $value['browse'],
- 'new' => $value['new'],
- 'paid' => $value['paid'],
- 'changes' => $value['changes'] . '%',
- 'vip' => $value['vip'],
- 'recharge' => $value['recharge'],
- 'payPrice' => $value['payPrice'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 导出积分兑换订单
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function storeIntegralOrder($data = [], $type = 1)
- {
- $header = ['订单号', '电话', '收货人姓名', '收货人电话', '收货地址', '商品信息', '订单状态', '下单时间', '用户备注'];
- $title = ['积分兑换订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '积分兑换订单导出_' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $item) {
- $one_data = [
- 'order_id' => $item['order_id'],
- 'phone' => $item['user_phone'],
- 'real_name' => $item['real_name'],
- 'user_phone' => $item['user_phone'],
- 'user_address' => $item['user_address'],
- 'goods_name' => $item['store_name'],
- 'status_name' => $item['status_name'] ?? '未知状态',
- 'add_time' => $item['add_time'],
- 'mark' => $item['mark']
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 门店账单导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function financeRecord($data = [], $name = '账单导出', $type = 1)
- {
- $header = ['交易单号', '关联订单', '交易时间', '交易金额', '支出收入', '交易人', '关联店员', '交易类型', '支付方式'];
- $title = [$name, $name . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = $name . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $key => $item) {
- $one_data = [
- 'order_id' => $item['order_id'],
- 'link_id' => $item['link_id'],
- 'trade_time' => $item['trade_time'],
- 'number' => $item['number'],
- 'pm' => $item['pm'] == 1 ? '收入' : '支出',
- 'user_nickname' => $item['user_nickname'],
- 'staff_name' => $item['staff_name'] ?? '',
- 'type_name' => $item['type_name'],
- 'pay_type_name' => $item['pay_type_name'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 供应商账单导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function SupplierFinanceRecord($data = [], $name = '账单导出', $type = 1)
- {
- $header = ['交易单号', '关联订单', '交易时间', '交易金额', '支出收入', '交易人', '交易类型', '支付方式'];
- $title = [$name, $name . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = $name . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $key => $item) {
- $one_data = [
- 'order_id' => $item['order_id'],
- 'link_id' => $item['link_id'],
- 'trade_time' => $item['trade_time'],
- 'number' => $item['number'],
- 'pm' => $item['pm'] == 1 ? '收入' : '支出',
- 'user_nickname' => $item['user_nickname'],
- 'type_name' => $item['type_name'],
- 'pay_type_name' => $item['pay_type_name'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function vipOrder(array $data, int $type = 1)
- {
- $header = ['订单号', '用户名', '手机号', '会员类型', '有效期限', '支付金额', '支付方式', '购买时间', '到期时间'];
- $title = ['会员订单', '会员订单' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '会员订单' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $key => $item) {
- $one_data = [
- 'order_id' => $item['order_id'],
- 'nickname' => $item['user']['nickname'] ?? '',
- 'phone' => $item['user']['phone'] ?? '',
- 'member_type' => $item['member_type'],
- 'vip_day' => $item['vip_day'],
- 'pay_price' => $item['pay_price'],
- 'pay_type' => $item['pay_type'],
- 'pay_time' => $item['pay_time'],
- 'overdue_time' => $item['overdue_time']
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 发票导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function invoiceRecord(array $data, int $type = 1)
- {
- $header = ['订单号', '订单金额', '发票类型', '发票抬头类型', '发票抬头名称', '下单时间', '开票状态', '订单状态'];
- $title = ['发票导出', '发票导出' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '发票导出' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $key => $item) {
- $one_data = [
- 'order_id' => $item['order_id'],
- 'pay_price' => $item['pay_price'],
- 'type' => $item['type'] == 1 ? '电子普通发票' : '纸质专用发票',
- 'header_type' => $item['header_type'] == 1 ? '个人' : '企业',
- 'name' => $item['name'],
- 'add_time' => $item['add_time'],
- 'is_invoice' => $item['is_invoice'] == 1 ? '已开票' : '未开票'
- ];
- if ($item['refund_status'] > 0) {
- if ($item['refund_status'] == 1) {
- $one_data['status'] = '退款中';
- } else {
- $one_data['status'] = '已退款';
- }
- } else {
- if ($item['status'] == 0) {
- $one_data['status'] = '未发货';
- } elseif ($item['status'] == 1) {
- $one_data['status'] = '待收货';
- } elseif ($item['status'] == 2) {
- $one_data['status'] = '待评价';
- } elseif ($item['status'] == 3) {
- $one_data['status'] = '已完成';
- }
- }
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- /**
- * 系统表单收集数据导出
- * @param array $data
- * @param int $type
- * @return array|mixed
- */
- public function systemFormData(array $data, int $type = 1)
- {
- $header = ['模版名称', '用户UID', '用户昵称', '手机号', '模版内容', '创建时间'];
- $title = ['系统表单收集数据导出', '表单收集数据导出' . time(), '生成时间:' . date('Y-m-d H:i:s', time())];
- $filename = '系统表单收集数据导出' . date('YmdHis', time());
- $export = [];
- $filekey = [];
- if (!empty($data)) {
- $i = 0;
- foreach ($data as $key => $item) {
- $one_data = [
- 'system_form_name' => $item['system_form_name'] ?? '',
- 'uid' => $item['uid'] ?? 0,
- 'nickname' => $item['nickname'] ?? '',
- 'phone' => $item['phone'] ?? '',
- 'form_data' => is_string($item['value']) ? json_decode($item['value']) : $item['value'],
- 'add_time' => $item['add_time'],
- ];
- if ($type == 1) {
- $export[] = $one_data;
- if ($i == 0) {
- $filekey = array_keys($one_data);
- }
- } else {
- $export[] = array_values($one_data);
- }
- $i++;
- }
- }
- if ($type == 1) {
- return compact('header', 'filekey', 'export', 'filename');
- } else {
- return $this->export($header, $title, $export, $filename);
- }
- }
- }
|