303 lines
11 KiB
PHP
303 lines
11 KiB
PHP
<?php
|
||
/**
|
||
* 云贝餐饮连锁V2版权说明:
|
||
|
||
******************************************************************
|
||
|
||
《云贝餐饮连锁V2》是武汉云贝网络科技有限公司历经2余年时间独立创作开发而成,且在不断的进行升级开发中,《云贝餐饮连锁V2 》的源代码、布局、界面设计、电子文档等均已提交国家版权局登记备案,并已获得著作权审批 和销售许可 (软著登字第 6839058号 登记号 2021SR0114741)。
|
||
|
||
官方网址为:www.b-ke.cn
|
||
|
||
官方联系方式:153-0719-3890(王经理)
|
||
|
||
******************************************************************
|
||
|
||
注意:本软件非开源系统,版权归武汉云贝网络科技有限公司依法所有,并受到法律的严格保护;未经过我司授权,不得擅自二开、破解、倒卖等任何的侵权、盗版行为均将追究其法律责任。
|
||
*/
|
||
namespace app\controllers\channel;
|
||
use Yii;
|
||
use yii\web\Controller;
|
||
use yii\web\Session;
|
||
use yii\web\Cookie;
|
||
class CommonController extends Controller{
|
||
public $enableCsrfValidation = false;
|
||
protected $wqData=[];
|
||
protected $storeId=0;
|
||
protected $cloudUrl="http://upload.y-bei.cn/";
|
||
protected $shdUrl="https://shd.y-bei.cn/";
|
||
protected $userData=[];
|
||
public function result($code=1,$msg='成功',$data=[],$count=null){
|
||
return json_encode([
|
||
'code'=>$code,
|
||
'msg'=>$msg,
|
||
'data'=>$data,
|
||
'count'=>(int)$count
|
||
]);
|
||
}
|
||
protected $payMode = array(
|
||
'1' => '微信支付',
|
||
'2' => '支付宝支付',
|
||
'5' => '余额支付',
|
||
'6' => '现金支付',
|
||
'7' => '自有pos机',
|
||
'8' => '自有微信',
|
||
'9' => '自有支付宝',
|
||
'10' => '货到付款',
|
||
);
|
||
protected $origin = array(
|
||
'1' => '外卖',
|
||
'2' => '充值',
|
||
'3' => '积分商城',
|
||
'4' => '券包',
|
||
'5' => '当面付',
|
||
'6' => '快餐',
|
||
'7' => '堂食',
|
||
'8' => '付费会员卡',
|
||
);
|
||
protected $platform = array(
|
||
'1' => '微信小程序',
|
||
'3' => '支付宝小程序',
|
||
'5' => '收银台',
|
||
);
|
||
protected $timeArr=[];
|
||
public function json(array $data = []){
|
||
return json_encode($data);
|
||
}
|
||
function init(){
|
||
if (Yii::$app->request->isOptions) {
|
||
echo json_encode([
|
||
'code' => 2,
|
||
'msg' => '非法请求'
|
||
]);
|
||
exit();
|
||
}
|
||
$result=axios_request();
|
||
$this->wqData=$_SESSION['configData'];
|
||
// $this->wqData = [
|
||
// 'uniacid'=>46,
|
||
// 'module'=>"yb_wm"
|
||
// ];
|
||
$uniacid=$this->wqData['uniacid'];
|
||
// if(!$uniacid) {
|
||
// echo json_encode([
|
||
// 'code' => 2,
|
||
// 'msg' => '数据异常,请退出系统重新登录'
|
||
// ]);
|
||
// exit();
|
||
// }
|
||
$startTime=strtotime(date('Y-m-d')." 00:00:00");
|
||
$endTime=strtotime(date('Y-m-d')." 23:59:59");
|
||
$this->timeArr=[
|
||
1=>[//今天
|
||
'startTime'=>$startTime,
|
||
'endTime'=>$endTime,
|
||
],
|
||
2=>[//7天
|
||
'startTime'=>strtotime(date('Y-m-d')." 00:00:00 -6day"),
|
||
'endTime'=>strtotime(date('Y-m-d')." 23:59:59"),
|
||
],
|
||
3=>[//15天
|
||
'startTime'=>strtotime(date('Y-m-d')." 00:00:00 -14day"),
|
||
'endTime'=>strtotime(date('Y-m-d')." 23:59:59"),
|
||
],
|
||
4=>[//自定义
|
||
'startTime'=>strtotime($result['startTime']." 00:00:00"),
|
||
'endTime'=>strtotime($result['endTime']." 23:59:59"),
|
||
]
|
||
];
|
||
|
||
$this->storeId = Yii::$app->request->headers->get('storeId');
|
||
if(Yii::$app->request->hostInfo=="https://bkycms.com"||Yii::$app->request->hostInfo=="https://v2.bkycms.com"){
|
||
$this->wqData=[
|
||
'uniacid'=>39,
|
||
'module'=>"yb_wm",
|
||
'version_id'=>$_SESSION['configData']['version_id'],
|
||
];
|
||
$role_re=(new \yii\db\Query())
|
||
->from('{{%ybwm_users}}')
|
||
->where(['uniacid'=>39,'type'=>1])
|
||
->one();
|
||
$role_re['loginType']=2;
|
||
$role_re['role']=$_SESSION['userInfo']['role'];
|
||
|
||
// dd($role_re);die;
|
||
Yii::$app->session->set('userInfo',$role_re);
|
||
|
||
}
|
||
if(Yii::$app->params['isDev']==true){
|
||
//dd($_SESSION['userInfo']);die;
|
||
$result=axios_request();
|
||
if($result['from']=='ws'){
|
||
$role_re=(new \yii\db\Query())
|
||
->from('{{%ybwm_users}}')
|
||
->where('uniacid=:uniacid and type=1',[':uniacid'=>$uniacid])
|
||
->one()?:[];
|
||
if($role_re){
|
||
$role_re=array_merge($role_re,$_SESSION['userInfo']);
|
||
$role_re['role']=$_SESSION['userInfo']['role'];
|
||
$role_re['loginType']=2;
|
||
Yii::$app->session->set('userInfo',$role_re);
|
||
}
|
||
}
|
||
}
|
||
$this->userData=Yii::$app->session->get('userInfo');
|
||
parent::init();
|
||
}
|
||
|
||
public function getShopId($uniacid){
|
||
$res=(new \yii\db\Query())
|
||
->select(['id','name'])
|
||
->from('{{%ybwm_store}}')
|
||
->where('uniacid=:uniacid AND isMain=1',[':uniacid'=>$uniacid])
|
||
->one();
|
||
return $res['id'];
|
||
}
|
||
|
||
//获取平台ID
|
||
public function getApplyId(){
|
||
return isset($_SESSION['configData']['uniacid']) ? $_SESSION['configData']['uniacid'] : '';
|
||
}
|
||
|
||
public function checkRole(){
|
||
$array=YII::$app->db->createCommand("select c_name from {{%ybwm_nav}}")->queryAll();
|
||
$new_arr=array_column($array,'c_name');
|
||
//var_dump($new_arr);die;
|
||
$role_arr=explode('/',$this->id);
|
||
$model_name=$role_arr[0];
|
||
$controller_name=$role_arr[1];
|
||
$action_name=$this->action->id;
|
||
$a_str= $controller_name.'_'.$action_name;
|
||
//当前访问的路由在路由控制表的范围内
|
||
if(in_array($a_str,$new_arr)){
|
||
$role_id = Yii::$app->session->get('userInfo')['role_id'];
|
||
$query= (new \yii\db\Query())
|
||
->select('role_str')
|
||
->from('{{%ybwm_users}} a')
|
||
->leftJoin('{{%role_list}} b','a.role_id=b.id')
|
||
->where(['a.role_id'=>$role_id,'b.status'=>1]);
|
||
//echo $query->createCommand()->getRawSql();die;
|
||
$re=$query->one();
|
||
$arr=(new \yii\db\Query())
|
||
->select('c_name,a_name')
|
||
->from('{{%nav}}')
|
||
->where(['in','id',explode(',',$re['role_str'])])
|
||
->all();
|
||
$b_arr=[];
|
||
foreach ($arr as $v){
|
||
$b_arr[]= $v['c_name'].'_'.$v['a_name'];
|
||
}
|
||
//用户权限表和数据库对比
|
||
if(!in_array($a_str,$b_arr)){
|
||
return false;die;
|
||
//throw new \Exception('没有该路由请求的权限');
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
public function checkDomain(){
|
||
$url=Yii::$app->params['domain_url'].'/cloud/safe/checkDomain';
|
||
$data['domain_url']=Yii::$app->request->hostInfo;
|
||
$arr=httpRequest($url,$data);
|
||
if($arr){
|
||
$this->result(1,'成功');
|
||
}else{
|
||
$this->result(2,'该域名未激活请联系客服处理');
|
||
}
|
||
}
|
||
|
||
//单个或批量修改数据
|
||
//$this->batchUpdate('{{%ceshi}}',['92','93'],['aaa'=>111,'bbb'=>222);
|
||
public function batchUpdate($table,$ids,$data){
|
||
$request = Yii::$app->request;
|
||
if ($request->isPost){
|
||
if(is_array($ids)){
|
||
$res=YII::$app->db->createCommand()->update($table,$data, ['in','id',$ids])->execute();
|
||
}else{
|
||
$res=YII::$app->db->createCommand()->update($table,$data, 'id=:id', ['id' =>$ids])->execute();
|
||
}
|
||
if($res==false){
|
||
$this->result(2,'网络异常,请稍后再试');
|
||
}else{
|
||
$this->result(1,'成功');
|
||
}
|
||
}
|
||
}
|
||
//删除单个或多个记录函数
|
||
//$this->batchDel('{{%ceshi}}',['92','93']);
|
||
public function batchDel($table,$ids){
|
||
$request = Yii::$app->request;
|
||
if ($request->isPost){
|
||
if(is_array($ids)) {
|
||
$res = Yii::$app->db->createCommand()->delete($table,['in','id',$ids])->execute();
|
||
}else{
|
||
$res = Yii::$app->db->createCommand()->delete($table, "id='$ids'")->execute();
|
||
}
|
||
if($res){
|
||
$this->result(1,'成功');
|
||
}else{
|
||
$this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
}
|
||
public function getTree($arr,$id){
|
||
$list =array();
|
||
foreach ($arr as $k=>$v){
|
||
if ($v['pid'] == $id){
|
||
if($this -> getTree($arr,$v['id'])){
|
||
$v['children'] = $this -> getTree($arr,$v['id']);
|
||
}
|
||
$list[] = $v;
|
||
}
|
||
}
|
||
return $list;
|
||
}
|
||
//按时间段,门店支付金额,支付次数
|
||
public function payResult($startTime,$endTime,$type=1,$storeId=null){
|
||
if(strtotime(date('Y-m-d H:i:s',$startTime)) !== $startTime) {
|
||
$startTime=strtotime($startTime);
|
||
}
|
||
if(strtotime(date('Y-m-d H:i:s',$endTime)) !== $endTime) {
|
||
$endTime=strtotime($endTime);
|
||
}
|
||
$data=(new \yii\db\Query())
|
||
->from('{{%ybwm_bill}}')
|
||
->where('uniacid=:uniacid AND deleteAt=0',['uniacid'=>$this->wqData['uniacid']]);
|
||
$data->andwhere('createdAt>=:startTime AND createdAt<=:endTime',['startTime'=>$startTime,'endTime'=>$endTime]);
|
||
if($storeId){
|
||
$data->andwhere('storeId:storeId',['storeId'=>$storeId]);
|
||
}
|
||
switch ($type){
|
||
case 1;
|
||
$res=$data->sum('money');
|
||
break;
|
||
case 2;
|
||
$res=$data->sum('storeActualMoney');
|
||
break;
|
||
case 3;
|
||
$res=$data->groupBy('userId')->count();
|
||
break;
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
//支付方式判断
|
||
public function judgePayType($code){
|
||
$wechat_arr = [ "10", "11", "12", "13", "14", "15" ];
|
||
$alipay_arr = [ "25", "26", "27", "28", "29", "30" ];
|
||
if(empty($code)) return '';
|
||
if(in_array(substr($code, 0,2), $wechat_arr)){
|
||
return "WECHAT";
|
||
} elseif (in_array(substr($code, 0,2),$alipay_arr )) {
|
||
return "ALIPAY";
|
||
} else {
|
||
return "OTHER";
|
||
}
|
||
}
|
||
|
||
//获取当前登陆者id
|
||
public function getUserId(){
|
||
return $_SESSION['userInfo']['id'] ? $_SESSION['userInfo']['id'] : '';
|
||
}
|
||
}
|