| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085 |
- <?php
- namespace backend\modules\mall\controllers;
- use backend\controllers\MallController;
- use backend\modules\mall\services\LevelService;
- use backend\modules\mall\services\StatisticsService;
- use backend\modules\mall\services\TeamService;
- use common\enums\RabbitMqEnum;
- use common\helpers\DateHelper;
- use common\logic\statistics\UserTeamStatisticsLogic;
- use common\models\census\CensusMall;
- use common\models\census\CensusMallGoods;
- use common\models\census\CensusMallSingleDay;
- use common\models\census\CensusMallSingleHour;
- use common\models\census\CensusMallUser;
- use common\models\common\Region;
- use common\models\statistics\GlobalStatistics;
- use common\models\statistics\UserStatistics;
- use common\models\statistics\GoodsStatistics;
- use common\models\statistics\RegionStatistics;
- use common\models\user\User;
- use common\models\goods\Goods;
- use common\enums\DownloadEnum;
- use common\enums\RedisKeyEnum;
- use common\helpers\csv\CsvExportHelper;
- use common\models\user\UserPartitionRelationship;
- use common\models\user\UserLevel;
- use common\enums\StatusEnum;
- use common\models\common\MallSetting;
- use common\models\order\Order;
- use Yii;
- use common\models\user\UserTeamStatistics;
- class StatisticsController extends MallController
- {
- public $enableCsrfValidation = false;
- /**
- *
- * 数据概况
- */
- public function actionDataStatisticsOld() {
- if (Yii::$app->request->isAjax) {
- //用户数
- $redis_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL, '', true) . ':' . $this->mall_id;
- $userNum = Yii::$app->redis->hget($redis_key,'total_users');
- if(empty($userNum)){
- $census_mall = CensusMall::findOne(['mall_id'=>$this->mall_id,'status' => StatusEnum::ENABLED]);
- $userNum = $census_mall['total_users'];
- }
- $post = Yii::$app->request->post();
- $goodsParam['where'][] = ['=', 'mall_id', $this->mall_id];
- if (isset($post['date_start']) && !empty($post['date_start']) && isset($post['date_end']) && !empty($post['date_end'])) {
- $goodsParam['where'][] = ['>=', 'created_at', strtotime($post['date_start'] . '0:0:0')];
- $goodsParam['where'][] = ['<=', 'created_at', strtotime($post['date_end'] . '23:59:59')];
- $startTime = implode('', explode('-', $post['date_start']));
- $endTime = implode('', explode('-', $post['date_end']));
- if ($startTime === $endTime) {
- $params['where'][] = ['=', 'date', $startTime];
- } else {
- $params['where'][] = ['>=', 'date', $startTime];
- $params['where'][] = ['<=', 'date', $endTime];
- }
- }
- $params['where'][] = ['=', 'mall_id', $this->mall_id];
- $goodsNum = Goods::count($goodsParam);
- if (!$goodsNum) $goodsNum = 0;
- //用户数,商品数,订单数,代发货订单数,售后订单数
- $orderStatistics = UserStatistics::getOrderStatistics(
- $params,
- ['sum(order_num) order_num', 'sum(refund_order_num) pro_order'],
- 'mall_id'
- );
- $orderStatistics['order_num'] = $orderStatistics[0]['order_num'] ?? 0;
- $orderStatistics['pro_order'] = $orderStatistics[0]['pro_order'] ?? 0;
- unset($orderStatistics[0]);
- $orderStatistics['user_count'] = $userNum;
- $orderStatistics['goods_num'] = $goodsNum;
- return $this->success('操作成功', $orderStatistics);
- }
- return $this->render('data-tatistics');
- }
- public function actionDataStatistics() {
- if (Yii::$app->request->isAjax) {
- //用户数
- $redis_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL, '', true) . ':' . $this->mall_id;
- $userNum = Yii::$app->redis->hget($redis_key,'total_users');
- if(empty($userNum)){
- $census_mall = CensusMall::findOne(['mall_id'=>$this->mall_id,'status' => StatusEnum::ENABLED]);
- $userNum = $census_mall['total_users'];
- }
- $post = Yii::$app->request->post();
- $params = [];
- $where[] = ['mall_id'=>$this->mall_id];
- if ( !empty($post['date_start']) && !empty($post['date_end'])) {
- $where[] = ['>=', 'created_at', strtotime($post['date_start'] . ' 00:00:00')];
- $where[] = ['<=', 'created_at', strtotime($post['date_end'] . '23:59:59')];
- }
- $params['where'] = $where;
- $params['select'] = 'sum(add_goods) as add_goods,sum(add_users) as add_users,sum(add_orders) as add_orders,sum(add_refund_orders) as add_refund_orders';
- $result = CensusMallSingleDay::lists($params);
- $orderStatistics['order_num'] = 0;
- $orderStatistics['pro_order'] = 0;
- $orderStatistics['user_count'] = $userNum;
- $orderStatistics['goods_num'] = 0;
- $orderStatistics['user_count'] = $orderStatistics['user_count'] ?: 0;
- if(!empty($result[0])){
- $orderStatistics['order_num'] = $result[0]['add_orders'] ? :0;
- $orderStatistics['pro_order'] = $result[0]['add_refund_orders'] ?: 0;
- $orderStatistics['goods_num'] =$result[0]['add_goods'] ?:0;
- }
- return $this->success('操作成功', $orderStatistics);
- }
- return $this->render('data-tatistics');
- }
- /**
- * 销售情况
- */
- public function actionSaleInfoOld() {
- //销售情况
- $day = Yii::$app->request->post('day');
- $day = $day ?? 1;
- $start_date = strtotime("-$day day 0:0:0");
- $end_date = strtotime("-1 day 23:59:59");
- $params['where'][] = ['>=', 'created_at', $start_date];
- $params['where'][] = ['<=', 'created_at', $end_date];
- $params['where'][] = ['=', 'mall_id', $this->mall_id];
- $saleList = UserStatistics::getOrderStatistics($params, ['created_at', 'pay_num', 'pay_money', 'pay_goods_num']);
- $saleInfo = [
- 'user_count' => 0, //支付人数
- 'order_num' => 0, //支付订单数
- 'total_pay_price' => 0, //支付金额
- 'goods_num' => 0 //支付件数
- ];
- $arr = [];
- foreach ($saleList as $item) {
- //筛选昨日按照每小时数量分组,筛选七日按照每日数据分组
- if ($day == 7) {
- $date = date('Y-m-d', $item['created_at']);
- } else {
- $date = intval(date('H', $item['created_at']));
- }
- if (isset($arr[$date])) {
- $arr[$date]['user_num'] += $item['pay_money'] > 0 ? 1: 0;
- $arr[$date]['order_num'] += $item['pay_num'] ?? 0;
- $arr[$date]['total_pay_price'] += $item['pay_money'] ?? 0;
- $arr[$date]['goods_num'] += $item['pay_goods_num'] ?? 0;
- } else {
- $arr[$date]['created_at'] = $day == 7 ? $date : $date.":00";
- $arr[$date]['user_num'] = $item['pay_money'] > 0 ? 1: 0;
- $arr[$date]['order_num'] = $item['pay_num'] ?? 0;
- $arr[$date]['total_pay_price'] = $item['pay_money'] ?? 0;
- $arr[$date]['goods_num'] = $item['pay_goods_num'] ?? 0;
- }
- $saleInfo['user_count'] += $item['pay_money'] > 0 ? 1: 0;
- $saleInfo['order_num'] += $item['pay_num'] ?? 0;
- $saleInfo['total_pay_price'] += $item['pay_money'] ?? 0;
- $saleInfo['goods_num'] += $item['pay_goods_num'] ?? 0;
- }
- if ($day == 1) {
- for ($i = 0; $i < 24; $i++) {
- if (!isset($arr[$i])) {
- $arr[$i] = ['created_at' => $i.':00', 'user_num' => 0, 'order_num' => 0, 'total_pay_price' => 0, 'goods_num' => 0];
- }
- }
- ksort($arr);
- } else {
- $temp = [];
- for ($i = 0; $i < 7; $i++) {
- $date = $start_date + ($i * 86400);
- $date = date('Y-m-d', $date);
- if (isset($arr[$date])) {
- $temp[] = $arr[$date];
- } else {
- $temp[] = ['created_at' => $date, 'user_num' => 0, 'order_num' => 0, 'total_pay_price' => 0, 'goods_num' => 0];
- }
- }
- $arr = $temp;
- }
- return $this->success('操作成功', ['table_list' => $arr, 'table_data' => $saleInfo]);
- }
- public function actionSaleInfo() {
- //销售情况
- $day = Yii::$app->request->get('day');
- $day = $day ?? 1;
- $start_date = strtotime("-$day day 0:0:0");
- $params = [];
- if($day==1){
- $params['where'][] = ['=', 'mall_id', $this->mall_id];
- $params['where'][] = ['=', 'date', date('Y-m-d',strtotime("-1 day"))];
- $list = CensusMallSingleHour::lists($params);
- $one_day = CensusMallSingleDay::getOne([
- ['mall_id'=> $this->mall_id],
- ['date'=>date('Y-m-d',strtotime("-1 day"))]
- ]);
- $user_count = $one_day['add_pay_people_nums']??0;
- $order_num = $one_day['add_pay_orders']??0;
- $total_pay_price = $one_day['total_pay_money']??0;
- $add_pay_nums = $one_day['add_pay_nums']??0;
- $saleInfo = [
- 'user_count' => $user_count, //支付人数
- 'order_num' => $order_num, //支付订单数
- 'total_pay_price' => $total_pay_price, //支付金额
- 'goods_num' => $add_pay_nums //支付件数
- ];
- $list = array_column($list,null,'hour');
- $arr = [];
- for ($i = 0; $i < 24; $i++) {
- $k = $i;
- if($i<10) $k='0'.$i;
- if (!isset($list[$k])) {
- $arr[$i] = ['created_at' => $i.':00', 'user_num' => 0, 'order_num' => 0, 'total_pay_price' => 0, 'goods_num' => 0];
- }else{
- $arr[$i] = ['created_at' => $i.':00', 'user_num' => $list[$k]['add_pay_people_nums'],
- 'order_num' => $list[$k]['add_pay_orders'], 'total_pay_price' => $list[$k]['total_pay_money'],
- 'goods_num' => $list[$k]['add_pay_nums']];
- }
- }
- }else{
- $dates = [];
- for ($i=0;$i<$day;$i++){
- $dates[] = date('Y-m-d',strtotime("-$i day"));
- }
- $params['where'][] = ['=', 'mall_id', $this->mall_id];
- $params['where']['date'] = ['in', 'date',$dates];
- $list = CensusMallSingleDay::lists($params);
- $user_count = array_sum(array_column($list,'add_pay_people_nums'));
- $order_num = array_sum(array_column($list,'add_pay_orders'));
- $total_pay_price = array_sum(array_column($list,'total_pay_money'));
- $add_pay_nums = array_sum(array_column($list,'add_pay_nums'));
- $saleInfo = [
- 'user_count' => $user_count, //支付人数
- 'order_num' => $order_num, //支付订单数
- 'total_pay_price' => $total_pay_price, //支付金额
- 'goods_num' => $add_pay_nums //支付件数
- ];
- $list = array_column($list,null,'date');
- $temp = [];
- for ($i = 0; $i < 7; $i++) {
- $date = $start_date + ($i * 86400);
- $date = date('Y-m-d', $date);
- if (isset($list[$date])) {
- $temp[] = ['created_at' => $date,
- 'user_num' => $list[$date]['add_pay_people_nums'],
- 'order_num' => $list[$date]['add_pay_orders'],
- 'total_pay_price' => $list[$date]['total_pay_money'],
- 'goods_num' => $list[$date]['add_pay_nums']
- ];
- } else {
- $temp[] = ['created_at' => $date, 'user_num' => 0, 'order_num' => 0, 'total_pay_price' => 0, 'goods_num' => 0];
- }
- }
- $arr = $temp;
- }
- return $this->success('操作成功', ['table_list' => $arr, 'table_data' => $saleInfo]);
- }
- /**
- * 数据概况-排行榜
- * data['user_rank'] 用户购买力TOP排行
- * data['goods_rank'] 商品购买力TOP排行
- * @return void
- */
- public function actionTopRankOld() {
- $userRank = [];
- $goodsRank = [];
- $get = Yii::$app->request->get();
- if ((!isset($get['order_type']) || empty($get['order_type'])) || (isset($get['order_type']) && $get['order_type'] == 'user_rank')) {
- $order = isset($get['order_by']) && !empty($get['order_by']) ? $get['order_by'] : 'pay_money desc';
- $param['where']=[['mall_id' => $this->mall_id]];
- $userRank = UserStatistics::getOrderStatistics($param, ['user_id', 'sum(pay_money) as pay_money', 'sum(pay_goods_num) as pay_goods_num'], 'user_id', 10, $order);
- $user_id = array_column($userRank, 'user_id');
- $userList = User::find()->where(['id' => $user_id])->select(['avatar_url','nickname','id'])->indexBy('id')->asArray()->all();
- foreach ($userRank as &$goods) {
- if (isset($userList[$goods['user_id']]['avatar_url'])) {
- $goods['avatar_url'] = $userList[$goods['user_id']]['avatar_url'];
- } else {
- $goods['avatar_url'] = '';
- }
- if (isset($userList[$goods['user_id']]['nickname'])) {
- $goods['nickname'] = $userList[$goods['user_id']]['nickname'];
- } else {
- $goods['nickname'] = '';
- }
- }
- }
- if((!isset($get['order_type']) || empty($get['order_type'])) || (isset($get['order_type']) && $get['order_type'] == 'goods_rank')){
- $orderBy = 'sales_num';
- $stor = 'desc';
- $redis = \Yii::$app->redis;
- if (isset($get['order_by']) && !empty($get['order_by'])) {
- $orderBy = explode(' ', $get['order_by'])[0];
- $stor = explode(' ', $get['order_by'])[1];
- }
- $stor = strtolower($stor);
- $orderBy = strtolower($orderBy);
- $goodsRank = Yii::$app->services->statistics->goods->get($this->mall_id, $stor, $orderBy);
- if (!empty($goodsRank)) {
- foreach ($goodsRank as &$goods) {
- //如果支付金额排序关联销售数量,如果销售数量排序关联金额
- if ($orderBy == 'pay_money') {
- $goods['sales_num'] = $redis->zscore(RedisKeyEnum::suffix(RedisKeyEnum::GOODS_STATISTICS_SALE, 'mall_id_'. $this->mall_id), 'goods_id:' . $goods['goods_id']) ?? 0;;
- } else {
- $goods['pay_money'] = $redis->zscore(RedisKeyEnum::suffix(RedisKeyEnum::GOODS_STATISTICS_MONEY, 'mall_id_' . $this->mall_id), 'goods_id:' . $goods['goods_id']) ?? 0;
- }
- }
- }
- }
- $data['user_rank'] = empty($userRank) ? [] : array_values($userRank);
- $data['goods_rank'] = empty($goodsRank) ? [] : array_values($goodsRank);
- return $this->success('操作成功', $data);
- }
- public function actionTopRank() {
- $get = Yii::$app->request->get();
- if ((!isset($get['order_type']) || empty($get['order_type'])) || (isset($get['order_type']) && $get['order_type'] == 'user_rank')) {
- $where = [];
- $where[]=['mall_id'=>$this->mall_id];
- $params['where'] = $where;
- $params['limit'] = 10;
- $order = 'total_pay_money desc';
- if (!empty($get['order_by'])) {
- $arr = explode(' ', $get['order_by']);
- $orderBy =$arr[0];
- $field = 'total_pay_money';
- if($orderBy=='pay_money') $field = 'total_pay_money';
- if($orderBy=='sales_num ') $field = 'total_pay_money';
- $sort = $arr[1];
- $order = $field. ' '.$sort;
- }
- $params['order'] = $order;
- $user_list = CensusMallUser::lists($params);
- if(!empty($user_list)){
- $user_ids = array_column($user_list,'user_id');
- $user_arr = User::find()->where(['id' => $user_ids])->select(['avatar_url','nickname','id'])->indexBy('id')->asArray()->all();
- foreach ($user_list as &$item){
- $item['avatar_url'] = '';
- $item['nickname'] = '';
- $item['pay_money'] = $item['total_pay_money'];
- $item['pay_goods_num'] = $item['add_pay_nums'];
- if(isset($user_arr[$item['user_id']])){
- $item['avatar_url'] = $user_arr[$item['user_id']]['avatar_url'];
- $item['nickname'] = $user_arr[$item['user_id']]['nickname'];
- }
- }
- }
- }
- if((!isset($get['order_type']) || empty($get['order_type'])) || (isset($get['order_type']) && $get['order_type'] == 'goods_rank')){
- $where = [];
- $where[]=['mall_id'=>$this->mall_id];
- $params['where'] = $where;
- $params['limit'] = 10;
- $order = 'total_sales_volume desc';
- if (!empty($get['order_by'])) {
- $arr = explode(' ', $get['order_by']);
- $orderBy =$arr[0];
- $field = 'total_pay_money';
- if($orderBy=='pay_money') $field = 'total_pay_money';
- if($orderBy=='sales_num ') $field = 'total_sales_volume';
- $sort = $arr[1];
- $order = $field. ' '.$sort;
- }
- $params['order'] = $order;
- $list = CensusMallGoods::lists($params);
- if(!empty($list)){
- $goods_ids = array_column($list,'goods_id');
- $goods_list = Goods::lists(['where'=>[['mall_id'=>$this->mall_id],['id'=>$goods_ids]],'index'=>'id']);
- foreach ($list as &$item){
- $item['cover_pic'] = '';
- $item['goods_name'] = '';
- $item['pay_money'] = $item['total_pay_money'];
- $item['sales_num'] = $item['total_sales_volume'];
- if(isset($goods_list[$item['goods_id']])){
- $item['goods_name'] = $goods_list[$item['goods_id']]['goods_name'];
- $item['cover_pic'] = $goods_list[$item['goods_id']]['cover_pic'];
- }
- }
- }
- }
- // $data['user_rank'] = empty($userRank) ? [] : array_values($userRank);
- $data['user_rank'] = empty($user_list) ? [] : $user_list;
- $data['goods_rank'] = empty($list) ? [] : $list;
- return $this->success('操作成功', $data);
- }
- /**
- * 销售数据
- */
- public function actionSaleStatisticsOld() {
- if (\Yii::$app->request->isAjax) {
- $params = Yii::$app->request->get();
- $where['where'][] = ['=', 'mall_id', $this->mall_id];
- if (isset($params['pay_type']) && !empty($params['pay_type']) && $params['pay_type'] == 'wechat') $where['where'][] = ['>', 'wechat_pay', 0];
- if (isset($params['pay_type']) && !empty($params['pay_type']) && $params['pay_type'] == 'balance') $where['where'][] = ['>', 'balance_pay', 0];
- if (isset($params['date_start']) && !empty($params['date_start']) && isset($params['date_end']) && !empty($params['date_end'])) {
- $startTime = implode('', explode('-', $params['date_start']));
- $endTime = implode('', explode('-', $params['date_end']));
- $where['where'][] = ['>=', 'date', $startTime];
- $where['where'][] = ['<=', 'date', $endTime];
- }
- $where['select'] = ['date', 'count(user_id) user_num'];
- //已完成订单数
- if ($params['status'] == 1) {
- array_push($where['select'], 'sum(finish_order_num) order_num', 'sum(finish_order_money) order_money', 'sum(finish_goods_num) goods_num');
- $where['where'][] = ['>', 'finish_order_num', 0];
- }
- //已取消订单数
- if ($params['status'] == 2) {
- array_push($where['select'], 'sum(cancel_order_num) order_num', 'sum(cancel_order_money) order_money', 'sum(cancel_goods_num) goods_num');
- $where['where'][] = ['>', 'cancel_order_num', 0];
- }
- //已退款单数
- if ($params['status'] == 3) {
- array_push($where['select'], 'sum(refund_order_num) order_num', 'sum(refund_order_money) order_money', 'sum(refund_goods_num) goods_num');
- $where['where'][] = ['>', 'refund_order_num', 0];
- }
- //全部
- if (!$params['status']) {
- array_push($where['select'], 'sum(pay_num) order_num', 'sum(pay_money) order_money', 'sum(pay_goods_num) goods_num');
- }
- $where['limit'] = 10;
- $where['group'] = 'date';
- $where['order'] = 'date desc';
- $list = UserStatistics::listPage($where, false);
- foreach ($list['list'] as $k => $v) {
- $list['list'][$k]['date'] = substr($v['date'], 0, 4) . '-' . substr($v['date'], 4, 2) . '-' . substr($v['date'], 6, 2);
- }
- $allWhere['where'] = $where['where'];
- $allData = UserStatistics::getOrderStatistics(
- $allWhere,
- ['sum(pay_num) pay_num', 'sum(pay_goods_num) pay_goods_num', 'count(user_id) user_num', 'sum(pay_money) pay_money']
- );
- $list['all_data'] = $allData[0];//总成交
- $date = date("Ymd", time());
- $nowWhere['where'] = [['=', 'mall_id', $this->mall_id], ['=', 'date', $date]];
- $nowData = UserStatistics::getOrderStatistics(
- $nowWhere,
- ['sum(pay_num) pay_num', 'sum(pay_goods_num) pay_goods_num', 'count(user_id) user_num', 'sum(pay_money) pay_money']
- );
- $list['now_data'] = $nowData[0];//今日实时成交
- return $this->success('操作成功', $list);
- }
- return $this->render('sale-statistics');
- }
- public function actionSaleStatistics() {
- if (\Yii::$app->request->isAjax) {
- $params = Yii::$app->request->get();
- $where = [];
- $where[]=['mall_id'=>$this->mall_id];
- $where[]=['status'=>StatusEnum::ENABLED];
- if ( !empty($params['date_start'])) {
- $where[] = ['>=', 'created_at', strtotime($params['date_start'].' 00:00:00')];
- }
- if (!empty($params['date_end'])) {
- $where[] = ['<=', 'created_at', strtotime($params['date_end'].' 23:59:59')];
- }
- $params['where'] = $where;
- $select = 'add_pay_orders as order_num,add_pay_nums as goods_num,add_pay_people_nums as user_num,total_pay_money as order_money,date';
- $params = array( 'where' => $where, 'select'=>$select,'order'=>'date desc', 'limit' => 20,);
- $list = CensusMallSingleDay::listPage($params,false);
- $params['select'] = 'sum(add_pay_orders) pay_num,sum(add_pay_nums) pay_goods_num,sum(add_pay_people_nums) user_num,sum(total_pay_money) pay_money';
- $result = CensusMallSingleDay::lists($params);
- $list['all_data'] = [ 'pay_num'=>0,'pay_goods_num'=>0,'user_num'=>0,'pay_money'=>0];
- if(!empty($result))$list['all_data'] = $result[0];//总成交
- $date = date("Y-m-d", time());
- $result = CensusMallSingleDay::getOne([['mall_id'=>$this->mall_id],['date'=>$date]],true);
- $list['now_data'] = [
- 'pay_num'=>0,'pay_goods_num'=>0,'user_num'=>0,'pay_money'=>0,
- ];
- if($result){
- $list['now_data'] = [
- 'pay_num'=>$result['add_pay_orders'],'pay_goods_num'=>$result['add_pay_nums'],
- 'user_num'=>$result['add_pay_people_nums'],'pay_money'=>$result['total_pay_money'],
- ];
- }
- return $this->success('操作成功', $list);
- }
- return $this->render('sale-statistics');
- }
- /**
- * 团队人数
- *
- * @return mixed
- */
- public function actionTeamSize()
- {
- if (Yii::$app->request->isAjax) {
- $params = Yii::$app->request->get();
- $service = new TeamService(['mall_id' => $this->mall_id]);
- return $this->success('操作成功', $service->getTeamSizePageList($params));
- }
- return $this->render($this->action->id);
- }
- /**
- * (个人)团队业绩
- *
- * @param integer $uid
- * @return mixed
- */
- public function actionTeamAchievement(int $uid)
- {
- if (Yii::$app->request->isAjax) {
- $params = Yii::$app->request->get();
- $service = new TeamService(['mall_id' => $this->mall_id]);
- return $this->success('操作成功', $service->getTeamAchievementPageList($uid, $params));
- }
- return $this->render($this->action->id);
- }
- public function actionTeamAchievementExport()
- {
- $data = Yii::$app->request->post('params');
- if (empty($data)) {
- return $this->error('参数错误');
- }
- $filename = '团队业绩数据-' . date('YmdHis') . '_' . rand(10000, 99999);
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_GROUP_DATA, TeamService::class, 'achievementExport', $data);
- if ($res === false) {
- return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- }
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- /**
- * 会员数据
- */
- public function actionUserData() {
- if (Yii::$app->request->isAjax) {
- $post = Yii::$app->request->get();
- $params['limit' ] = 10;
- $params['where'][] = ['=', 'mall_id', $this->mall_id];
- $params['where'][] = ['in', 'status', [StatusEnum::ENABLED,StatusEnum::DISABLED]];
- if (isset($post['level'])&&!empty($post['level']!=-1)) $params['where'][] = ['=', 'level', $post['level']];
- if (isset($post['keyword']) && !empty($post['keyword'])) {
- $params['where'][] = [
- 'or',
- ['like', 'nickname', $post['keyword']],
- ['=', 'mobile', $post['keyword']],
- ['=', 'id', $post['keyword']]
- ];
- }
- $params['order'] = 'id asc';
- $params['select'] = ['nickname', 'id', 'avatar_url', 'mobile', 'level',];
- $data = User::listPage($params, false);
- if ($data === false) return $this->error(User::getStaticError());
- if(!empty($data['list'])){
- $user_id_arr = array_column($data['list'],'id');
- $user_data = CensusMallUser::lists(['where'=> [['user_id'=>$user_id_arr]], 'index'=>'user_id']);
- foreach ($data['list'] as &$item){
- $item['pay_num'] = $item['pay_money'] = $item['finish_order_num'] = $item['finish_order_money'] = 0;
- if(isset($user_data[$item['id']])){
- $item['pay_num'] = $user_data[$item['id']]['add_orders'];
- $item['pay_money'] = $user_data[$item['id']]['add_order_money'];
- $item['finish_order_num'] = $user_data[$item['id']]['add_sale_orders'];
- $item['finish_order_money'] = $user_data[$item['id']]['add_sale_money'];
- }
- }
- }
- $levels = UserLevel::getListIndexByLevelColumn($this->mall_id,[StatusEnum::ENABLED,StatusEnum::DISABLED]);
- $data['levels'] = $levels;
- $this->success('操作成功', $data);
- }
- return $this->render('user-data');
- }
- /**
- * 导出
- */
- public function actionExport() {
- $type = Yii::$app->request->post('type');
- $data['mall_id'] = $this->mall_id;
- switch ($type) {
- case 'goods_rank':
- $filename = '商品购买力列表-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_STATISTICS,GoodsStatistics::class,'exportRankHandle',$data);
- break;
- case 'user_rank':
- $filename = '用户购买力列表-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_STATISTICS,UserStatistics::class,'exportRankHandle',$data);
- break;
- case 'sale-statistics':
- $filename = '销售数据列表-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_STATISTICS,UserStatistics::class,'exportSaleStatisticsHandle',$data);
- break;
- case 'team-size':
- $filename = '渠道人数列表-' . date('YmdHis').'_'.rand(10000,99999);
- $data = Yii::$app->request->post('params');
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_MEMBER,User::class,'exportTeamSizeHandle',$data);
- break;
- default:
- # code...
- break;
- }
- if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- public function actionCarUserData()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/census/user-data');
- }
- $mall_id = $this->mall_id;
- $user_list = [];
- $redis = Yii::$app->redis;
- //获取等级分布开始
- $level = [];//会员等级分布
- $active_members = [];//会员活跃数
- $order = [];//复购数据
- $deal_members = [];//成交客户
- $cumulative_members = [];//累计会员数
- $redis_level_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_USER_LEVEL, '', true) . ':' . $mall_id;
- $redis_single_date_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_SINGLE_DATE, '', true) . ':' . $mall_id;
- $redis_census_mall_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL, '', true) . ':' . $mall_id;
- $result = $redis->hgetall($redis_level_key);
- if ($result) {
- $levels = UserLevel::getUserLevelArr($mall_id);
- foreach ($result as $key => $value) {
- if ($key % 2 == 0) {
- $level_key[] = $value;
- } else {
- $level_value[] = $value;
- }
- }
- $total_level_num = array_sum($level_value);
- $proportion_num = 100;
- $level_count = count($level_key);
- foreach ($level_key as $k => $v) {
- $level_exp = [];
- $level_exp = explode('_', $v);
- $now_proportion_num = floor($level_value[$k] / $total_level_num * 100);
- if ($k == $level_count - 1) {
- $now_proportion_num = $proportion_num;
- }
- if ($now_proportion_num == 0) {
- $now_proportion_num = ceil($level_value[$k] / $total_level_num * 100);
- }
- $proportion_num -= $now_proportion_num;
- if (isset($levels[$level_exp[1]])) {
- $level[$k]['level_name'] = $levels[$level_exp[1]];
- $level[$k]['num'] = $level_value[$k];
- $level[$k]['proportion'] = $now_proportion_num;
- } else {
- $level[$k]['level_name'] = '普通用户';
- $level[$k]['num'] = $level_value[$k];
- $level[$k]['proportion'] = $now_proportion_num;
- }
- }
- }
- //获取等级分布结束
- //获取活跃会员开始
- $day = date('Y-m-d', time());
- for ($i = 0; $i < 5; $i++) {
- $now_day = $day;
- if ($i > 0) {
- $now_day = date("Y-m-d", strtotime("-" . $i . " day", strtotime($day)));
- }
- $redis_key = $redis_single_date_key . ':' . $now_day;
- $active_members[$i]['num'] = $redis->hget($redis_key, 'total_actives') ?? 0;
- $active_members[$i]['day'] = date('m-d', strtotime($now_day));
- $user_list[$i]['num'] = $redis->hget($redis_key, 'total_users') ?? 0;
- $user_list[$i]['day'] = date('m-d', strtotime($now_day));
- }
- if($active_members){
- $active_members = array_reverse($active_members);
- }
- if($user_list){
- $user_list = array_reverse($user_list);
- }
- //获取活跃会员结束
- //复购情况开始
- $order['repurchase_people'] = $redis->hget($redis_census_mall_key, 'repurchase_people') ?? 0;//复购会员数
- $order['total_pay_people'] = $redis->hget($redis_census_mall_key, 'total_pay_people') ?? 0;//支付人数
- $total_views = $redis->hget($redis_census_mall_key, 'total_visitors') ?? 0;//
- $total_orders = $redis->hget($redis_census_mall_key, 'number_of_orders') ?? 0;//
- $total_pay_orders = $redis->hget($redis_census_mall_key, 'total_pay_people') ?? 0;//
- $order['order_proportion'] = 0;
- $order['pay_order_proportion'] = 0;
- if ($total_views > 0) {
- if ($total_orders > 0) {
- $order['order_proportion'] = (bcdiv($total_orders , $total_views,2)*100).'%';//
- }
- if ($total_pay_orders > 0) {
- $order['pay_order_proportion'] =(bcdiv($total_pay_orders , $total_views,2)*100).'%';
- }
- }
- //复购情况结束
- //成交会员开始
- $deal_members['new_customers_pay_peoples'] = $redis->hget($redis_census_mall_key, 'new_customers_pay_peoples') ?? 0;//新客户成交人数
- $deal_members['new_customers_pay_money'] = $redis->hget($redis_census_mall_key, 'new_customers_pay_money') ?? 0;//新客户成交金额
- $deal_members['regular_customers_pay_peoples'] = $redis->hget($redis_census_mall_key, 'regular_customers_pay_peoples') ?? 0;//老客户成交人数
- $deal_members['regular_customers_pay_money'] = $redis->hget($redis_census_mall_key, 'regular_customers_pay_money') ?? 0;//老客户成交金额
- $total_pay_people = $deal_members['new_customers_pay_peoples'] + $deal_members['regular_customers_pay_peoples'];
- $total_pay_money = bcadd($deal_members['new_customers_pay_money'], $deal_members['regular_customers_pay_money'], 2);
- $deal_members['new_customers_proportion'] = ceil($deal_members['new_customers_pay_peoples'] / $total_pay_people * 100);
- $deal_members['regular_customers_proportion'] = 100 - $deal_members['new_customers_proportion'];
- $deal_members['new_customers_pay_money_proportion'] = ceil($deal_members['new_customers_pay_money'] / $total_pay_money * 100);
- $deal_members['regular_customers_pay_money_proportion'] = 100 - $deal_members['new_customers_pay_money_proportion'];
- //成交会员结束
- //累计会员开始
- $cumulative_members['total_users'] = $redis->hget($redis_census_mall_key, 'total_users') ?? 0;//新客户成交人数
- $cumulative_members['new_user'] = $user_list;//新客户成交人数
- //累计会员结束
- return $this->success('获取成功', compact('cumulative_members', 'level', 'active_members', 'order', 'deal_members'));
- }
- public function actionCarUserTradData()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/census/transaction-data');
- }
- $mall_id = $this->mall_id;
- $redis = Yii::$app->redis;
- $from = [];
- $trad_trend = [];
- $trad_map = [];
- $cart = [];
- $rank = [];
- $redis_census_mall_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL, '', true) . ':' . $mall_id;
- $redis_census_map_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_REGION, '', true) . ':' . $mall_id;
- $redis_goods_member_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_GOODS_CARD_NUMBERS, '', true) . ':' . $mall_id;
- $redis_goods_money_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_GOODS_PAY_MONEY, '', true) . ':' . $mall_id;
- $total_num = $redis->hget($redis_census_mall_key, 'total_pay_money') ?? 0;
- //访客下单支付开始
- $from['total_visitors'] = $redis->hget($redis_census_mall_key, 'total_visitors') ?? 0;//访客
- $from['number_of_orders'] = $redis->hget($redis_census_mall_key, 'number_of_orders') ?? 0;//下单人数
- $from['total_order_money'] = $redis->hget($redis_census_mall_key, 'total_order_money') ?? 0;//下单金额
- $from['total_pay_money'] = $redis->hget($redis_census_mall_key, 'total_pay_money') ?? 0;//支付金额
- $from['total_pay_people'] = $redis->hget($redis_census_mall_key, 'total_pay_people') ?? 0;//支付人数
- $from['order_proportion'] = 0;//下单转化率
- $from['pay_proportion'] = 0;//支付转化率
- $from['unit_price'] = 0;//客单价
- if ($from['total_pay_people'] > 0 && $from['total_pay_money'] > 0) {
- $from['unit_price'] = bcdiv($from['total_pay_money'], $from['total_pay_people'], 2);
- }
- if ($from['total_visitors'] > 0) {
- if ($from['number_of_orders'] > 0) {
- $from['order_proportion'] = bcdiv($from['number_of_orders'] , $from['total_visitors'],2)*100;//
- }
- if ($from['total_pay_people'] > 0) {
- $from['pay_proportion'] =bcdiv($from['total_pay_people'] , $from['total_visitors'],2)*100;
- }
- }
- //访客下单支付结束
- //实时成交趋势
- $date = date('Y-m-d', time());
- // $date = '2022-04-12';
- $redis_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_SINGLE_HOUR . ':' . $mall_id . ':' . $date, '', true);
- $result = $redis->hgetall($redis_key);
- if ($result) {
- foreach ($result as $key => $value) {
- if ($key % 2 == 0) {
- $trad_trend_key[] = $value;
- } else {
- $trad_trend_value[] = $value;
- }
- }
- foreach ($trad_trend_key as $k => $v) {
- $hour = explode('_', $v);
- $trad_trend[$k]['hour'] = $hour[1];
- $trad_trend[$k]['num'] = $trad_trend_value[$k];
- }
- }
- // 实时成交趋势
- //加购情况
- $cart_list = $redis->zrevrange($redis_goods_member_key, 0, 9, 'WITHSCORES');
- if ($cart_list) {
- foreach ($cart_list as $ke => $valu) {
- if ($ke % 2 == 0) {
- $cart_trend_key[] = $valu;
- } else {
- $cart_trend_value[] = $valu;
- }
- }
- foreach ($cart_trend_key as $item => $val) {
- $goods_id = explode(':', $val);
- $name = Goods::getOne([['id' => $goods_id[1]]], true, [], '', 'goods_name,cover_pic');
- $cart[$item]['goods_name'] = $name['goods_name'];
- $cart[$item]['cover_pic'] = $name['cover_pic'];
- $cart[$item]['num'] = $cart_trend_value[$item];
- }
- }
- //加购情况
- //销售排行榜
- $rank_list = $redis->zrevrange($redis_goods_money_key, 0, 9, 'WITHSCORES');
- if ($rank_list) {
- foreach ($rank_list as $index => $vv) {
- if ($index % 2 == 0) {
- $rank_trend_key[] = $vv;
- } else {
- $rank_trend_value[] = $vv;
- }
- }
- foreach ($rank_trend_key as $i => $va) {
- $goods_id = explode(':', $va);
- $name = Goods::getOne([['id' => $goods_id[1]]], true, [], '', 'goods_name,cover_pic');
- $rank[$i]['goods_name'] = $name['goods_name'];
- $rank[$i]['cover_pic'] = $name['cover_pic'];
- $rank[$i]['num'] = round($rank_trend_value[$i], 2);
- }
- }
- //销售排行榜
- //交易地图热点
- $map_list = $redis->hgetall($redis_census_map_key);
- if ($map_list) {
- foreach ($map_list as $kk => $vva) {
- if ($kk % 2 == 0) {
- $map_trend_key[] = $vva;
- } else {
- $map_trend_value[] = $vva;
- }
- }
- $n = 0;
- foreach ($map_trend_key as $now_key => $now_val) {
- $ex_key = explode('id_', $now_val);
- if ($ex_key[0] == 'total_orders_province_') {
- $trad_map[$n]['province_id'] = $ex_key[1];
- $trad_map[$n]['order_num'] = $map_trend_value[$now_key];
- $n++;
- }
- }
- $province_ids = array_column($trad_map, 'province_id');
- $provinces = Region::find()
- ->select('id,name,short_title,areacode,initial')
- ->where(['id' => $province_ids, 'level' => 1])
- ->asArray()
- ->indexBy('id')
- ->all();
- foreach ($trad_map as &$items) {
- $province = $provinces[$items['province_id']] ?? [];
- $items['province_name'] = $province['name'] ?? '';
- $items['province_short_title'] = $province['short_title'] ?? '';
- }
- }
- //交易地图热点
- $user_ids = Order::find()->andWhere(['mall_id'=>$mall_id,'pay_status'=>1,'store_id'=>0,'mch_id'=>0])
- ->orderBy('id desc')->groupBy('user_id')->select('user_id')
- ->limit(20)->column();
- $scroll = [];
- if ($user_ids) {
- $user_name = User::lists(['where' => [['in','id',$user_ids]], 'select' => 'nickname,id','index'=>'id']);
- if($user_name){
- foreach ($user_ids as $user_id){
- if(isset($user_name[$user_id])){
- $scroll[] = $user_name[$user_id]['nickname'].'支付了订单';
- }
- }
- }
- }
- return $this->success('获取成功', compact('from', 'trad_trend', 'trad_map', 'cart', 'rank', 'total_num','scroll'));
- }
- public function actionCarAnalysis()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/census/analysis');
- }
- $type = Yii::$app->request->get('type');
- $mall_id = $this->mall_id;
- $redis = \Yii::$app->redis;
- if ($type == 1) {
- $redis_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_RF_ANALYSIS, '', true) . ':' . $mall_id;
- $total_pay_money = 'f_total_pay_money';
- $users = 'f_users';
- } else {
- $redis_key = RedisKeyEnum::suffix(RedisKeyEnum::CENSUS_MALL_RM_ANALYSIS, '', true) . ':' . $mall_id;
- $total_pay_money = 'm_total_pay_money';
- $users = 'm_users';
- }
- $result = $redis->get($redis_key);
- if ($result) {
- $result = \Qiniu\json_decode($result, true);
- foreach ($result as $k => &$v) {
- $v['unit_price1'] = 0;
- $v['unit_price2'] = 0;
- $v['unit_price3'] = 0;
- $v['unit_price4'] = 0;
- $v['unit_price5'] = 0;
- if ($v[$total_pay_money . '1'] > 0 && $v[$users . '1'] > 0) {
- $v['unit_price1'] = bcdiv($v[$total_pay_money . '1'], $v[$users . '1'], 2);
- }
- if ($v[$total_pay_money . '2'] > 0 && $v[$users . '2'] > 0) {
- $v['unit_price2'] = bcdiv($v[$total_pay_money . '2'], $v[$users . '2'], 2);
- }
- if ($v[$total_pay_money . '3'] > 0 && $v[$users . '3'] > 0) {
- $v['unit_price3'] = bcdiv($v[$total_pay_money . '3'], $v[$users . '3'], 2);
- }
- if ($v[$total_pay_money . '4'] > 0 && $v[$users . '4'] > 0) {
- $v['unit_price4'] = bcdiv($v[$total_pay_money . '4'], $v[$users . '4'], 2);
- }
- if ($v[$total_pay_money . '5'] > 0 && $v[$users . '5'] > 0) {
- $v['unit_price5'] = bcdiv($v[$total_pay_money . '5'], $v[$users . '5'], 2);
- }
- }
- }
- return $this->success('获取成功', $result);
- }
- /**
- * @notes:老用户订单数据更新
- * @author: lun
- * @Time: 2022/11/8 14:09
- */
- public function actionUpdateFinishOrder()
- {
- if (Yii::$app->request->isPost) {
- $redis = Yii::$app->redis;
- $cacheKey = RedisKeyEnum::suffix(\common\models\statistics\UserTeamStatistics::COUNT_FINISH_ORDER_KEY, 'mall_id_' . $this->mall_id);
- $checkCount = $redis->get($cacheKey);
- if ($checkCount && $checkCount == 1) return $this->error('数据正在更新或已更新完成');
- Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, ['mall_id' => $this->mall_id], UserTeamStatisticsLogic::class, 'countOldUserTeamAchievement');
- return $this->success('数据已进行异步更新,请耐心等候');
- }
- }
- /**
- * @return string|void
- */
- public function actionAllPayTypeRefund()
- {
- $service = new StatisticsService(['mall_id' => $this->mall_id]);
- if (!\Yii::$app->request->isAjax) {
- $thisMonth = array_values(DateHelper::thisMonth());
- array_walk($thisMonth, function (&$val) {
- $val = date('Y-m-d', $val);
- });
- return $this->render(
- $this->action->id,
- [
- 'pay_type_option' => json_encode($service->getPayTypeOption()),
- 'pay_identifier_option' => json_encode($service->getPayIdentifierOption()),
- 'export_field' => json_encode($service->getAllPayTypeRefundExportField()),
- 'this_month' => json_encode($thisMonth), // 默认查询本月的数据
- ]
- );
- }
- $this->success('success', $service->allPayTypeRefund($this->request->get()));
- }
- /**
- * @return string|void
- */
- public function actionAllPayTypeRefundDetails()
- {
- $service = new StatisticsService(['mall_id' => $this->mall_id]);
- if (!\Yii::$app->request->isAjax) {
- $thisMonth = array_values(DateHelper::thisMonth());
- array_walk($thisMonth, function (&$val) {
- $val = date('Y-m-d H:i:s', $val);
- });
- return $this->render(
- $this->action->id,
- [
- 'export_field' => json_encode($service->getAllPayTypeRefundDetailsExportField()),
- 'this_month' => json_encode($thisMonth), // 默认查询本月的数据
- ]
- );
- }
- $get = $this->request->get();
- $valid = Yii::$app->services->validate->validate($get, [
- [['id'], 'required'],
- [['id', 'user_keyword'], 'number', 'min' => 0],
- [['daterange'], 'safe'],
- ]);
- if ($valid === false) {
- $this->error(Yii::$app->services->validate->getErrorMessage());
- return;
- }
- $this->success('success', $service->allPayTypeRefundDetails($get));
- }
- /**
- * @return mixed|null
- * @throws \Random\RandomException
- */
- public function actionAllPayTypeRefundExport()
- {
- $data = Yii::$app->request->post();
- if (empty($data['daterange'])) {
- $filename = '支付通道退款统计数据_' . date('YmdHis') . '_' . random_int(10000, 99999);
- } else {
- $filename = sprintf('支付通道退款统计数据_%s至%s_%d', $data['daterange'][0], $data['daterange'][1], random_int(10000, 99999));
- }
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_PAY_TYPE_REFUND_STATISTICS, StatisticsService::class, 'allPayTypeRefundExport', $data);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- /**
- * @return mixed|null
- * @throws \Random\RandomException
- */
- public function actionAllPayTypeRefundDetailsExport()
- {
- $data = Yii::$app->request->post();
- if (empty($data['daterange'])) {
- $filename = '支付通道退款统计明细数据_' . date('YmdHis') . '_' . random_int(10000, 99999);
- } else {
- $filename = sprintf('支付通道退款统计明细数据_%s至%s_%d', $data['daterange'][0], $data['daterange'][1], random_int(10000, 99999));
- }
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_PAY_TYPE_REFUND_STATISTICS_DETAILS, StatisticsService::class, 'allPayTypeRefundDetailsExport', $data);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- /**
- * 订单详情
- */
- public function actionOrderDetail()
- {
- $order_id = $this->request->get('order_id');
- if (!is_numeric($order_id)) return $this->error('参数错误');
-
- $order = Order::find()->where(['id' => $order_id, 'status' => StatusEnum::ENABLED])->with(['detail'])->asArray()->all();
- if (!$order) return $this->error('订单不存在');
- $return_data = [];
- foreach ($order as &$item) {
- $temp = [];
- foreach ($item['detail'] as &$detail) {
- $temp[$detail['goods_id']][] = $detail;
- }
- foreach ($temp as $goods_detail) {
- $item['detail'] = [];
- $item['detail'] = $goods_detail;
- $return_data[] = $item;
- }
- }
- return $this->success('success', $return_data);
- }
- }
|