canyin-project/ybcy/controllers/channel/IndexController.php
2024-11-01 16:07:54 +08:00

205 lines
9.1 KiB
PHP

<?php
namespace app\controllers\channel;
use Illuminate\Support\Facades\DB;
use Yii;
use yii\web\Controller;
use yii\web\Session;
use yii\web\Cookie;
use app\models\common\Statistics;
class IndexController extends CommonController{
public $enableCsrfValidation = false;
//业务后台首页
public function actionIndex(){
if(Yii::$app->params['isDev']==true) {
$we_res = (new \yii\db\Query())
->from('{{%ybwm_users}}')
->where(['uniacid' => $this->wqData['uniacid'],'type'=>1])
->one();
if (!$we_res) {
$role_re = [];
$salt = randoms(8);
$auth_key = Yii::$app->params['authkey'];
$password = checkPassWord($salt, $auth_key, rand(6));
$role_re = array(
'uniacid'=>$this->wqData['uniacid'],
'userName' => 'we7v2'.$this->wqData['uniacid'],
'passWord' => $password,
'salt' => $salt,
'type' => 1,
'createdAt' => time(),
);
YII::$app->db->createCommand()->insert('{{%ybwm_users}}', $role_re)->execute();
$role_re = array_merge($role_re, $_SESSION['userInfo']);
$role_re['role'] = $_SESSION['userInfo']['role'];
Yii::$app->session->set('userInfo', $role_re);
}
}
$session_name=$_SESSION['userInfo'];
if(!$session_name){
if(Yii::$app->params['isDev']==true){
header('Location: ' . Yii::$app->request->hostInfo);
}else{
Yii::$app->response->redirect(['admin/login/index'], 301)->send();die;
}
}
//微擎版本
if(Yii::$app->params['isDev']==true){
Yii::$app->response->redirect(Yii::$app->request->hostInfo.'/addons/'.$this->wqData['module'].'/views/channel/index/index.html');
//独立版本
}else{
Yii::$app->response->redirect(Yii::$app->request->hostInfo.'/views/channel/index/index.html');
}
}
//退出登陆
public function actionLoginout(){
$session = Yii::$app->session;
$session->remove('userInfo');
return $this->result(1,'成功');
}
//websocke测试页面
public function actionWs_ceshi(){
return $this->renderPartial('ws_ceshi');
}
//门店概况
public function actionStoreIndex(){
$result=axios_request();
$uniacid=$this->wqData['uniacid'];
$storeId=$result['storeId']?:$this->wqData['storeId'];
$storeInfo=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where(['uniacid'=>$uniacid,'id'=>$storeId])
->one();
$startTime=strtotime(date('Y-m-d 00:00:00',strtotime($result['startTime'])));
$endTime=strtotime(date('Y-m-d 23:59:59',strtotime($result['endTime'])));
$beforeStartTime=strtotime(date('Y-m-d 00:00:00',$endTime-14*24*60*60));
$beforeEndTime=$endTime;
//今日订单数
$sum=Statistics::getPayNum($uniacid,$storeId);
$totalSum=Statistics::getPayNum($uniacid,$storeId,$startTime,$endTime);
//今日营业额
$money=Statistics::getPayMoney($uniacid,$storeId);
$totalMoney=Statistics::getPayMoney($uniacid,$storeId,$startTime,$endTime);
//付款人数
$payUser=Statistics::getPayPeople($uniacid,$storeId);
$totalPayUser=Statistics::getPayPeople($uniacid,$storeId,$startTime,$endTime);
//浏览量
$visitCount=Statistics::getViews($uniacid,$storeId);
$totalVisitCount=Statistics::getViews($uniacid,$storeId,$startTime,$endTime);
$moneyArr=Statistics::getShopMoneyDayChart($this->wqData['uniacid'],$storeId,$beforeStartTime,$beforeEndTime);
$moneyResult=dataByTime($moneyArr,$result['endTime']);
$payArr=Statistics::getShopPayDayChart($this->wqData['uniacid'],$storeId,$beforeStartTime,$beforeEndTime);
$payResult=dataByTime($payArr,$result['endTime']);
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//预计收入
$yujiSum=Statistics::revenue($uniacid,$storeId,$startTime,$endTime);
$yesterSum=Statistics::revenue($uniacid,$storeId,$beginYesterday,$endYesterday);
//有效订单
$payCount=Statistics::payOkNum($uniacid,$storeId,$startTime,$endTime);
$yesPayCount=Statistics::payOkNum($uniacid,$storeId,$beginYesterday,$endYesterday);
//付款人数
$userCount=Statistics::getPayPeople($uniacid,$storeId,$startTime,$endTime);
$yesuserCount=Statistics::getPayPeople($uniacid,$storeId,$beginYesterday,$endYesterday);
//浏览量
// $visitCount=(new \yii\db\Query())
// ->from('{{%ybwm_visit_list}}')
// ->where(['uniacid'=>$uniacid])
// ->andWhere(['>=','createdAt',$startTime])
// ->andWhere(['<','createdAt',$endTime])
// ->andWhere(['in','modelname',[1,2]])
// ->count()?:0;
$yesVisitCount=(new \yii\db\Query())
->from('{{%ybwm_visit_list}}')
->where(['uniacid'=>$uniacid])
->andWhere(['>=','createdAt',$beginYesterday])
->andWhere(['<','createdAt',$endYesterday])
->andWhere(['in','modelname',[1,2]])
->count()?:0;
//商品销量TOP10
$goodsData=(new \yii\db\Query())
->select('b.name,sum(a.num)num,sum(a.money*a.num) money')
->from('{{%ybwm_order_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['a.uniacid'=>$uniacid,'a.storeId'=>$storeId])
->groupBy('goodsId')
->orderBy('num desc')
->limit(10)->all()?:[];
foreach ($goodsData as $key=>$v){
$goodsData[$key]['id']=$key+1;
}
//外卖订单
$query=(new \yii\db\Query())
->from('{{%ybwm_bill}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId]);
$sumMoney=$query->sum('money');
$outMoney=$query->andWhere(['origin'=>1])->sum('money');
$data=array(
'totalSum'=>$totalSum, //今日订单数
'sum'=>$sum, //总订单数
'totalMoney'=>$totalMoney, //今日营业额
'money'=>$money, //总营业额
'totalPayUser'=>$totalPayUser, //付款人数
'payUser'=>$payUser, //总付款人数
'totalVisitCount'=>$totalVisitCount,//浏览量
'visitCount'=>$visitCount, //总浏览量
'moneyResult'=>$moneyResult, //订单数柱形图
'payResult'=>$payResult, //营业额柱形图
'yujiSum'=>$yujiSum, //预计收入
'yesterSum'=>$yesterSum, //昨日预计收入
'payCount'=>$payCount, //有效订单
'yesPayCount'=>$yesPayCount, //昨日有效订单
'userCount'=>$userCount, //付款人数
'yesuserCount'=>$yesuserCount, //昨日付款人数
'yesVisitCount'=>$yesVisitCount, //昨日浏览量
'goodsData'=>$goodsData, //销量TOP10商品
'sumMoney'=>$sumMoney?:0, //营业额
'outMoney'=>$outMoney?:0, //外卖营业额
'goodsModel'=>$storeInfo['goodsModel'],
);
return $this->result(1,'成功',$data);
}
public function actionUserList(){
$result=axios_request();
$page=$result['page']?$result['page']:1;
$num=($page-1)*10;
$limit=10;
$query=(new \yii\db\Query())
->select(["FROM_UNIXTIME(a.createdAt,'%Y-%m-%d %H:%i:%s') createdAt",'a.id memberId','a.userName memberName','b.id userId','b.userName','a.portrait','apply_name','c.name','c.id storeId','d.id applyId'])
->from('{{%ybwm_merchant_member}} a')
->leftJoin('{{%ybwm_users}} b','a.id=b.userId')
->leftJoin('{{%ybwm_store}} c','b.storeId=c.id')
->leftJoin('{{%ybwm_apply}} d','b.uniacid=d.id')
->where(['>','a.portrait',''])
->orderBy('a.id desc');
$count=$query->count();
$data=(clone $query)->offset($num)->limit($limit)->all();
return $this->result(1,'成功',$data,$count);
}
//压缩小程序文件夹打包并下载
public function actionMiniDown(){
$dir='miniApp/';
$res=miniScan($dir);
//file_put_contents(Yii::$app->basePath.'/web/oldSoft.lock.json', json_encode($res));
$datalist=array_keys($res);
//dd($datalist);die;
if(file_exists(Yii::$app->basePath.'/web/upgraded/mini.zip')){
unlink(Yii::$app->basePath.'/web/upgraded/mini.zip');
}
//dd($newData);die;
addFileToZip($datalist,Yii::$app->basePath.'/web/upgraded/','mini.zip');
header('Content-Type:text/html;charset=utf-8');
header('Content-disposition:attachment;filename=mini.zip');
$filesize = filesize(Yii::$app->basePath.'/web/upgraded/mini.zip');
readfile(Yii::$app->basePath.'/web/upgraded/mini.zip');
header('Content-length:'.$filesize);
}
}