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

1892 lines
86 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\controllers\channel;
use app\models\common\Ali;
use app\models\common\Bill;
use Illuminate\Support\Facades\DB;
use Yii;
use app\models\common\Config;
use app\models\common\WeChat;
use app\models\common\Store;
use app\models\common\Statistics;
use app\models\common\Financial;
use yii\db\Expression;
class ShopController extends CommonController{
public $enableCsrfValidation = false;
private $shop_id;
public function init(){
parent::init();
$this->shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id'];
$this->shop_id=$this->shop_id?:0;
}
//商家列表
public function actionStoreList(){
$typeId=Yii::$app->request->get('typeId');
$keyword=Yii::$app->request->get('keyword');
$type=Yii::$app->request->get('type');
$areaId=Yii::$app->request->get('areaId');
$label=Yii::$app->request->get('label');
$recycle=Yii::$app->request->get('recycle');
$page=Yii::$app->request->get('page')?:1;
$size=Yii::$app->request->get('size')?:10;
$checkShopGoodsModel=Yii::$app->request->get('checkShopGoodsModel');
$goodsModel=Yii::$app->request->get('goodsModel');
$table=(new \yii\db\Query())
->select(['a.id','a.typeId','a.areaId', 'a.name','b.name as typeName','a.storeTel','a.address','a.display','c.name as areaName','a.icon','a.goodsModel','a.type','a.deleteAt'])
->from('{{%ybwm_store}} as a')
->join('LEFT JOIN', '{{%ybwm_core_category}} as b', 'b.id = a.typeId')
->join('LEFT JOIN', '{{%ybwm_core_category}} as c', 'c.id = a.areaId')
//->where('a.uniacid=:uniacid',[':uniacid'=>$this->wqData['uniacid']]);
->where('a.uniacid=:uniacid AND a.isMain=2',[':uniacid'=>$this->wqData['uniacid']]);
if($typeId){
$table->andwhere('a.typeId=:typeId',[':typeId'=>$typeId]);
}
if($keyword){
$table->andwhere(['like','a.name',$keyword]);
}
if($type){
$table->andwhere('a.type=:type',[':type'=>$type]);
}
if($areaId){
$table->andwhere('a.areaId=:areaId',[':areaId'=>$areaId]);
}
if($label){
$table->andwhere('a.label=:label',[':label'=>$label]);
}
if($recycle==1){
$table->andwhere('a.deleteAt>0');
}else{
$table->andwhere('a.deleteAt=0');
}
if($goodsModel){
$table->andwhere(['goodsModel'=>$goodsModel]);
}else{
if($checkShopGoodsModel){
$table->andwhere(['in','goodsModel',[1,2]]);
}
}
$count=$table->count();
$res=$table->offset(($page - 1) * $size)->limit($size)->all();
if(Yii::$app->params['isDev']){
$url=Yii::$app->request->hostInfo.'/addons/yb_wm/views/channel/index/index.html#/login';
}else{
$url=Yii::$app->request->hostInfo.'/views/channel/index/index.html#/login';
}
$shopCount=(new \yii\db\Query())->from('{{%ybwm_store}}')->where(['uniacid'=>$this->wqData['uniacid']])->andWhere(['<>','isMain',1])->count();
$sysInfo=Config::getSystemSet('sysTopImage',$this->wqData['uniacid']);
if($sysInfo){
$shopNum=$sysInfo['shopNum'];
}else{
$sysInfo=Config::getSystemSet('superPower',$this->wqData['uniacid']);
$shopNum=$sysInfo['shopNum'];
}
//var_dump($sysInfo);die;
$serviceCharge=Config::getSystemSet('serviceCharge',$this->wqData['uniacid']);
foreach ($res as $key=>$v){
$storeSet=Config::getStoreSet('serviceCharge',$v['id']);
if($storeSet['rule']==2) {
$res[$key]['serviceCharge'] = $storeSet;
}else{
if($serviceCharge['rule']==1){
$res[$key]['serviceCharge']=$serviceCharge;
}elseif($serviceCharge['rule']==2) {
$storeType = (new \yii\db\Query())
->from('{{%ybwm_core_category}}')
->where('id=:id', [':id' => $v['typeId']])->one();
$res[$key]['serviceCharge']= json_decode($storeType['data'], true);
}elseif($serviceCharge['rule']==3) {
$storeType = (new \yii\db\Query())
->from('{{%ybwm_core_category}}')
->where('id=:id', [':id' => $v['areaId']])->one();
$res[$key]['serviceCharge']= json_decode($storeType['data'], true);
}else{
$res[$key]['serviceCharge']=$storeSet;
}
}
if(!$res[$key]['serviceCharge']){
$res[$key]['serviceCharge']['type']=1;
$res[$key]['serviceCharge']['goodsPlatformProportion']=0;
$res[$key]['serviceCharge']['boxPlatformProportion']=0;
$res[$key]['serviceCharge']['deliverPlatformProportion']=0;
$res[$key]['serviceCharge']['goodsFixedMoney']=0;
$res[$key]['serviceCharge']['boxFixedMoney']=0;
$res[$key]['serviceCharge']['deliverFixedMoney']=0;
}
if(!$v['goodsModel']){
$v['goodsModel']=1;
}
}
if($shopNum==0||!$shopNum){
$shopNum='无限';
}
if($shopNum>0){
$shopNum=$shopNum-$count;
}
$qq=Config::getSystemSet('sysTopImage',$this->wqData['uniacid'])['qq'];
if(!$qq){
$qq=Config::getSystemSet('superPower',0)['qq'];
}
echo json_encode(['code'=>1,'msg'=>'成功','shopCount'=>$shopCount,'data'=>$res,'count'=>intval($count),'url'=>$url,'shopNum'=>$shopNum,'qq'=>$qq]);die;
}
public function actionStoreInfo(){
$result=axios_request();
$shopInfo=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$result['storeId']])->one();
return $this->result(1,'成功',$shopInfo);
}
public function actionSelectStoreCategory(){
$type=(new \yii\db\Query())
->from('{{%ybwm_core_category}}')
->where('uniacid=:uniacid AND deleteAt=0 AND item=1',[':uniacid'=>$this->wqData['uniacid']])
->all();
$area=(new \yii\db\Query())
->from('{{%ybwm_core_category}}')
->where('uniacid=:uniacid AND deleteAt=0 AND item=2',[':uniacid'=>$this->wqData['uniacid']])
->all();
$label=(new \yii\db\Query())
->from('{{%ybwm_core_category}}')
->where('uniacid=:uniacid AND deleteAt=0 AND item=3',[':uniacid'=>$this->wqData['uniacid']])
->all();
$data['type']=$type;
$data['area']=$area;
$data['label']=$label;
return $this->result(1,'成功',$data);
}
//商家基本信息 添加门店
public function actionStoreBasic(){
$request = Yii::$app->request;
if ($request->isGet){
$shopInfo=(new \yii\db\Query())
->select(['id','goodsModel', 'name','icon','cityId','zoneId','provinceId','lat','lng','storeTel','address','storeOpen','type','storeLinkMan','storeNumber','timeType','timeArr','icon','display'])
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid',[':uniacid'=>$this->wqData['uniacid']]);
$result=Yii::$app->request->get();
if($result['id']){
$shopInfo->andwhere('id=:id',[':id'=>$result['id']]);
}elseif($result['storeType']!=2){
$shopInfo->andwhere('isMain=1');
}
$info=$shopInfo->one()?:[];
$sessionData=Yii::$app->session->get('userInfo');
//如果是独立入口登陆
// if($sessionData['loginType']==2&&$sessionData['type']==2){
// $info=(new \yii\db\Query())
// ->select(['id', 'name','icon','cityId','zoneId','provinceId','lat','lng','storeTel','address','storeOpen','type','storeLinkMan','storeNumber','timeType','timeArr','icon','display'])
// ->from('{{%ybwm_store}}')
// ->where('uniacid=:uniacid',[':uniacid'=>$sessionData['uniacid']])
// ->andwhere('id=:id',[':id'=>$sessionData['storeId']])->one()?:[];
// }
if($info){
$info['cityArr']=[$info['provinceId'],$info['cityId'],$info['zoneId']];
}
//dd($sessionData);die;
$info['coordinate']=Store::location($this->wqData['uniacid']);
if($shopInfo){
$info['coordinate']['address']=$info['address'];
$info['coordinate']['lat']=$info['lat'];
$info['coordinate']['lng']=$info['lng'];
}
$res=Config::getStoreSet('takeOutSet',$info['id']);
if($res){
$info['timeArr']=$res['timeArr'];
$info['timeType']=$res['timeType'];
}
$info['uniacid']=$this->wqData['uniacid'];
$info['storeId']=$result['id'];
$info['loginType']=$sessionData['type'];
return $this->result(1,'成功',$info);
}
$result=axios_request();
$shopInfo=Store::getMainStore($this->wqData['uniacid']);
if(!$shopInfo AND $result['isMain']==2){
return $this->result(2,'请先添加商户信息!');
}
if(!$this->wqData['uniacid']){
return $this->result(2,'数据异常,请退出系统重新登录!');
}
if(!$result['name']){
return $this->result(2,'商家名称不能为空!');
}
if(!$result['icon']){
return $this->result(2,'商家logo不能为空!');
}
if(!$result['storeTel']){
return $this->result(2,'商家电话不能为空!');
}
if(!$result['storeLinkMan']){
return $this->result(2,'商家联系人不能为空!');
}
if(!$result['cityArr']){
return $this->result(2,'商家所在城市不能为空!');
}
if(!$result['address']){
return $this->result(2,'商家详细地址不能为空!');
}
if(!$result['lat'] || !$result['lng']){
return $this->result(2,'商家经纬度不能为空!');
}
$array=array(
'shopId'=>$shopInfo['id'],//商户id
'uniacid'=>$this->wqData['uniacid'],
'name'=>$result['name'],
'sort'=>$result['sort']?:1,
'icon'=>$result['icon'],
'cityId'=>$result['cityArr'][1],
'provinceId'=>$result['cityArr'][0],
'zoneId'=>$result['cityArr'][2],
'lat'=>$result['lat'],
'lng'=>$result['lng'],
'isMain'=>$result['isMain']?:2,
'storeTel'=>$result['storeTel'],
'storeLinkMan'=>$result['storeLinkMan'],
'storeOpen'=>$result['storeOpen'],
'address'=>$result['address'],
'display'=>$result['display']?:1,
'areaId'=>0,
'deleteAt'=>0,
'changeAt'=>0,
'goodsModel'=>$result['goodsModel']?:1
);
if($result['type']){
$array['type']=$result['type'];
}else{
$array['type']=1;
}
//print_R($array);die;
if($result['id']){
if($shopInfo AND $array['isMain']==1 AND $result['id']!=$shopInfo['id']){
return $this->result(2,'商户已存在,不可重复添加!');
}
$shopRes=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid',[':uniacid'=>$this->wqData['uniacid']])
->andwhere('id=:id',[':id'=>$result['id']])->one();
//商品模式只能从模式一切换到模式二
if($shopRes['goodsModel']==1&&$result['goodsModel']>2){
return $this->result(2,'商品模式仅限商品模式一切换到商品模式二!');
}
if($shopRes['goodsModel']>1&&$result['goodsModel']<>$shopRes['goodsModel']){
return $this->result(2,'商品模式仅限商品模式一切换到商品模式二!');
}
$array['changeAt']=time();
if(!$shopInfo['storeNumber']){
$number=storeCode($result['id']);
$shopInfo=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid and storeNumber='.$number,[':uniacid'=>$this->wqData['uniacid']])
->one();
if($shopInfo){
$array['storeNumber']=storeCode($result['id']);
}else{
$array['storeNumber']=$number;
}
}
$re = Yii::$app->db->createCommand()->update('{{%ybwm_store}}', $array, 'id=:id', ['id' =>$result['id']])->execute();
}else{
//获取门店可创建数量
$sysInfo=Config::getSystemSet('sysTopImage',$this->wqData['uniacid']);
if($sysInfo){
$shopNum=$sysInfo['shopNum'];
}else{
$sysInfo=Config::getSystemSet('superPower',$this->wqData['uniacid']);
$shopNum=$sysInfo['shopNum'];
}
if($sysInfo['shopModel']==1||!$sysInfo['shopModel']){
$nowStoreNum= (new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid',[':uniacid'=>$this->wqData['uniacid']])
->count();
if($shopNum>0){
if($shopNum-$nowStoreNum==0){
return $this->result(2,'可创建门店数量已达上限!');
}
}
}
if($shopInfo AND $array['isMain']==1){
return $this->result(2,'商户已存在,不可重复添加!');
}
$array['createdAt']=time();
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_store}}', $array)->execute();
$id=Yii::$app->db->getLastInsertID();
if($array['isMain']!==1&&$result['goodsModel']<3){
//同步总门店的商品
$goodsData=(new \yii\db\Query())
->from('{{%ybwm_core_goods}}')
->where('uniacid=:uniacid AND storeId=:storeId and goodsType=1',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id']])
//->andWhere(['>','stock',0])
->all();
foreach ($goodsData as $v){
$goodOper=array(
'uniacid'=>$this->wqData['uniacid'],
'storeId'=>$id,
'goodsId'=>$v['id'],
'createdAt'=>time(),
'display'=>$v['display'],
'price'=>$v['price'],
'maxPrice'=>$v['maxPrice'],
'stock'=>$v['stock'],
'isSpecs'=>$v['isSpecs'],
'boxMoney'=>$v['boxMoney']
);
$goodOper['data']=[];
$specs=[];
if($v['isSpecs']==1){
//多规格
$specs= (new \yii\db\Query())
->select('id,specsName,SalesPrice,SalesStock,fillType,crossedPrice,goodCode,costPrice,boxMoney')
->from('{{%ybwm_good_specs}}')
->where('uniacid=:uniacid AND storeId=:storeId AND goodId=:goodId',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id'],':goodId'=>$v['id']])
->all();
}
//属性
$attr=(new \yii\db\Query())
->select('id,attrName,attrStr')
->from('{{%ybwm_good_attribute}}')
->where('uniacid=:uniacid AND storeId=:storeId AND goodId=:goodId',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id'],':goodId'=>$v['id']])
->all();
//加料
$materia=(new \yii\db\Query())
->select('id,materialName,SalesPrice,SalesStock,fillType')
->from('{{%ybwm_good_materia}}')
->where('uniacid=:uniacid AND storeId=:storeId AND goodId=:goodId',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id'],':goodId'=>$v['id']])
->all();
$operData=array(
'specs'=>$specs,
'attr'=>$attr,
'materia'=>$materia,
);
$goodOper['data']=json_encode($operData);
if(!$specs&&!$attr&&!$materia){
unset($goodOper['data']);
}
//var_dump($goodOper);
Yii::$app->db->createCommand()->insert('{{%ybwm_store_goods}}', $goodOper)->execute();
}
}
//如果是模式新建模式三门店,将主店的外卖分类及外卖商品全部导入到门店
// if($array['isMain']!==1&&$result['goodsModel']==3){
// $categoryData=(new \yii\db\Query())
// ->from('{{%ybwm_core_category}}')
// ->where('uniacid=:uniacid AND storeId=:storeId and item=6',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id']])
// ->all();
// foreach($categoryData as $va){
// $oldCategory=$va['id'];
// unset($va['id']);
// $va['storeId']=$id;
// Yii::$app->db->createCommand()->insert('{{%ybwm_core_category}}', $va)->execute();
// $newId=Yii::$app->db->getLastInsertID();
// $goodsData=(new \yii\db\Query())
// ->from('{{%ybwm_core_goods}}')
// ->where('uniacid=:uniacid AND storeId=:storeId and typePid=:typePid',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id'],'typePid'=>$oldCategory])
// ->all();
// foreach ($goodsData as $vb){
// unset($vb['id']);
// $vb['typePid']=$newId;
// $vb['storeId']=$id;
// Yii::$app->db->createCommand()->insert('{{%ybwm_core_goods}}', $vb)->execute();
// $newGoodId=Yii::$app->db->getLastInsertID();
// if($vb['isSpecs']==1){
// //多规格
// $specs= (new \yii\db\Query())
// ->from('{{%ybwm_good_specs}}')
// ->where('uniacid=:uniacid AND storeId=:storeId AND goodId=:goodId',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id'],':goodId'=>$vb['id']])
// ->all();
// foreach ($specs as &$vs){
// unset($vs['id']);$vs['storeId']=$id;$vs['goodId']=$newGoodId;
// Yii::$app->db->createCommand()->insert('{{%ybwm_good_specs}}', $vs)->execute();
// }
// }
// //属性
// $attr=(new \yii\db\Query())
// ->from('{{%ybwm_good_attribute}}')
// ->where('uniacid=:uniacid AND storeId=:storeId AND goodId=:goodId',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id'],':goodId'=>$v['id']])
// ->all();
// if($attr){
// foreach ($attr as &$vs){
// unset($vs['id']);$vs['storeId']=$id;$vs['goodId']=$newGoodId;
// Yii::$app->db->createCommand()->insert('{{%ybwm_good_attribute}}', $vs)->execute();
// }
// }
// //加料
// $materia=(new \yii\db\Query())
// ->from('{{%ybwm_good_materia}}')
// ->where('uniacid=:uniacid AND storeId=:storeId AND goodId=:goodId',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$shopInfo['id'],':goodId'=>$v['id']])
// ->all();
// if($materia){
// foreach ($materia as &$vs){
// unset($vs['id']);$vs['storeId']=$id;$vs['goodId']=$newGoodId;
// Yii::$app->db->createCommand()->insert('{{%ybwm_good_materia}}', $vs)->execute();
// }
// }
// }
// }
//
//
//
//
// }
$number=storeCode($id);
$shopInfo=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid and storeNumber='.$number,[':uniacid'=>$this->wqData['uniacid']])
->one();
if($shopInfo){
$number=storeCode($id);
}
Yii::$app->db->createCommand()->update('{{%ybwm_store}}', ['storeNumber'=>$number], 'id=:id', ['id' =>$id])->execute();
}
return $this->result(1,'成功');
}
//修改店铺
public function actionModifyStore(){
$result=axios_request();
if($result['type']==1){
$data['display']=$result['display'];
}
if($result['type']==2){
$data['deleteAt']=time();
}
if($result['type']==3){
$data['deleteAt']=0;
}
if($result['type']==4){
//永久删除
$res = Yii::$app->db->createCommand()->delete('{{%ybwm_store}}', 'id=:id', ['id' =>$result['id']])->execute();
if($res){
Yii::$app->db->createCommand()->delete('{{%ybwm_users}}', 'storeId=:storeId', ['storeId' =>$result['id']])->execute();
return $this->result(1,'成功');
}else{
return $this->result(2,'失败');
}
}
$data['changeAt']=time();
$res = Yii::$app->db->createCommand()->update('{{%ybwm_store}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
if($res){
if($result['type']==2){
Yii::$app->db->createCommand()->update('{{%ybwm_users}}', ['display'=>2,'deleteAt'=>time()], 'storeId=:storeId', ['storeId' =>$result['id']])->execute();
}
if($result['type']==3){
Yii::$app->db->createCommand()->update('{{%ybwm_users}}', ['display'=>1,'deleteAt'=>0], 'storeId=:storeId', ['storeId' =>$result['id']])->execute();
}
return $this->result(1,'成功');
}else{
return $this->result(2,'失败');
}
}
//自提地址
public function actionSelfAddress(){
$shopInfo=Store::getMainStore($this->wqData['uniacid']);
$request = Yii::$app->request;
if ($request->isGet){
$get=Yii::$app->request->get();
if($get['storeId']){
$res=Config::getStoreSet('selfAddress',$get['storeId']);
}elseif($get['storeType']!=2){
$res=Config::getStoreSet('selfAddress',$shopInfo['id']);
}else{
return $this->result(1,'成功',[]);
}
return $this->result(1,'成功',$res);
}
if(!$shopInfo){
return $this->result(2,'请先添加商户信息!');
}
$result=axios_request();
$re=Config::saveStoreSet($result,'selfAddress',$result['storeId']);
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//提现设置
public function actionWithdrawal(){
$shopInfo=Store::getMainStore($this->wqData['uniacid']);
$request = Yii::$app->request;
if ($request->isGet){
$get=Yii::$app->request->get();
if($get['storeId']){
$res=Config::getStoreSet('withdrawal',$get['storeId']);
}elseif($get['storeType']!=2){
$res=Config::getStoreSet('withdrawal',$shopInfo['id']);
}else{
return $this->result(1,'成功',[]);
}
$withdrawal=Config::getSystemSet('withdrawal',$this->wqData['uniacid']);
$res['channel']=$withdrawal['channel'];
$user=(new \yii\db\Query())
->select('userName')
->from('{{%ybwm_member}}')
->where('id=:id AND uniacid=:uniacid',[':id'=>$res['userId'],':uniacid'=>$this->wqData['uniacid']])
->one();
$res['userName']=$user['userName']?:'';
return $this->result(1,'成功',$res);
}
if(!$shopInfo){
return $this->result(2,'请先添加商户信息!');
}
$result=axios_request();
//var_dump($result);die;
$re=Config::saveStoreSet($result,'withdrawal',$result['storeId'],'提现设置');
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//搜索用户
public function actionGetUserInfo() {
$result=axios_request();
$user=(new \yii\db\Query())
->select('userName')
->from('{{%ybwm_member}}')
->where('id=:id AND uniacid=:uniacid',[':id'=>$result['id'],':uniacid'=>$this->wqData['uniacid']])
->one();
if($user){
return $this->result(1,'成功',$user);
}else{
return $this->result(2,'用户不存在');
}
}
//腾讯地址转坐标
public function actionMap() {
$get=Yii::$app->request->get();
$url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" .$get['lat'] . "," . $get['lng'] . "&key=MRKBZ-7KUH4-EICUJ-X33NW-SCU42-UPBI4&get_poi=1";
$res = httpRequest($url);
$res=json_decode($res,true);
$res['result']['address']=$res['result']['address_component']['province'].$res['result']['address_component']['city'].$res['result']['formatted_addresses']['recommend'];
return json_encode($res);
}
//营业信息
public function actionStoreBusiness() {
$request = Yii::$app->request;
if ($request->isGet){
$shopInfo=(new \yii\db\Query())
->select(['id', 'timeType','timeArr','typeId','label','areaId','license','foodRecords','service','environment','mainDishes','perCapita','introduction','uniacid'])
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid',[':uniacid'=>$this->wqData['uniacid']]);
$result=Yii::$app->request->get();
if($result['id']){
$shopInfo->andwhere('id=:id',[':id'=>$result['id']]);
$info=$shopInfo->one()?:[];
}elseif($result['storeType']!=2){
$shopInfo->andwhere('isMain=1');
$info=$shopInfo->one()?:[];
}else{
$info=[];
}
$table=(new \yii\db\Query())
->select(['id', 'name','sort','display'])
->from('{{%ybwm_core_category}}');
$serviceList=$table->where('uniacid=:uniacid AND deleteAt=0 AND item=5',[':uniacid'=>$this->wqData['uniacid']])->all();
$info['timeArr']=json_decode($info['timeArr'],true)?:[];
$info['service']=json_decode($info['service'],true)?:[];
$info['environment']=json_decode($info['environment'],true)?:[];
$info['license']=json_decode($info['license'],true)?:[];
$info['foodRecords']=json_decode($info['foodRecords'],true)?:[];
$data['serviceList']=$serviceList;
$data['info']=$info;
$labelList=$table->where('uniacid=:uniacid AND deleteAt=0 AND item=3',[':uniacid'=>$this->wqData['uniacid']])->all();
$typeList=$table->where('uniacid=:uniacid AND deleteAt=0 AND item=1',[':uniacid'=>$this->wqData['uniacid']])->all();
$arealList=$table->where('uniacid=:uniacid AND deleteAt=0 AND item=2',[':uniacid'=>$this->wqData['uniacid']])->all();
$data['labelList']=$labelList;
$data['arealList']=$arealList;
$data['typeList']=$typeList;
return $this->result(1,'成功',$data);
}
$shopInfo=Store::getMainStore($this->wqData['uniacid']);
if(!$shopInfo){
return $this->result(2,'请先添加商户信息!');
}
$result=axios_request();
if($result['timeType']==2 AND !$result['timeArr']){
return $this->result(2,'商家营业时间不能为空!');
}
$array=array(
'timeType'=>$result['timeType'],
'timeArr'=>json_encode($result['timeArr'])?:'',
'mainDishes'=>$result['mainDishes'],
'perCapita'=>$result['perCapita'],
'introduction'=>$result['introduction'],
'service'=>json_encode($result['service'])?:'',
'environment'=>json_encode($result['environment'])?:'',
'license'=>json_encode($result['license'])?:'',
'foodRecords'=>json_encode($result['foodRecords'])?:'',
'label'=>$result['label'],
'typeId'=>$result['typeId']?:0,
'areaId'=>$result['areaId']?:0,
);
if($result['timeArr']){
for($i=0;$i<count($result['timeArr']);$i++){
if($result['timeArr'][$i]['startTime']==$result['timeArr'][$i]['endTime']){
$array['timeType']=1;
break;
}
}
}
$array['changeAt']=time();
$re = Yii::$app->db->createCommand()->update('{{%ybwm_store}}', $array, 'id=:id', ['id' =>$result['id']])->execute();
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//资质认证
public function actionStoreAuth(){
$request = Yii::$app->request;
if ($request->isGet){
$shopInfo=(new \yii\db\Query())
->select(['id', 'license','foodRecords','label','typeId','areaId'])
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid',[':uniacid'=>$this->wqData['uniacid']]);
$result=Yii::$app->request->get();
if($result['id']){
$shopInfo->andwhere('id=:id',[':id'=>$result['id']]);
$info=$shopInfo->one()?:[];
}elseif($result['storeType']!=2){
$shopInfo->andwhere('isMain=1');
$info=$shopInfo->one()?:[];
}else{
$info=[];
}
$info['areaId']=$info['areaId']?:'';
$info['typeId']=$info['typeId']?:'';
$info['license']=json_decode($info['license'],true)?:[];
$info['foodRecords']=json_decode($info['foodRecords'],true)?:[];
$data['info']=$info;
$table=(new \yii\db\Query())
->select(['id', 'name','sort','display'])
->from('{{%ybwm_core_category}}');
$labelList=$table->where('uniacid=:uniacid AND deleteAt=0 AND item=3',[':uniacid'=>$this->wqData['uniacid']])->all();
$typeList=$table->where('uniacid=:uniacid AND deleteAt=0 AND item=1',[':uniacid'=>$this->wqData['uniacid']])->all();
$arealList=$table->where('uniacid=:uniacid AND deleteAt=0 AND item=2',[':uniacid'=>$this->wqData['uniacid']])->all();
$data['labelList']=$labelList;
$data['arealList']=$arealList;
$data['typeList']=$typeList;
return $this->result(1,'成功',$data);
}
$shopInfo=Store::getMainStore($this->wqData['uniacid']);
if(!$shopInfo){
return $this->result(2,'请先添加商户信息!');
}
$result=axios_request();
if(!$result['license']){
return $this->result(2,'商家商品安全档案不能为空!');
}
if(!$result['foodRecords']){
return $this->result(2,'商家营业执照不能为空!');
}
$array=array(
'label'=>$result['label'],
'typeId'=>$result['typeId'],
'areaId'=>$result['areaId'],
'license'=>json_encode($result['license'])?:'',
'foodRecords'=>json_encode($result['foodRecords'])?:'',
);
$array['changeAt']=time();
$re = Yii::$app->db->createCommand()->update('{{%ybwm_store}}', $array, 'id=:id', ['id' =>$result['id']])->execute();
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//门店分类列表
public function actionStoreCategoryList(){
$item=Yii::$app->request->get('item');
$page=Yii::$app->request->get('page')?:1;
$size=Yii::$app->request->get('size')?:10;
$table=(new \yii\db\Query())
->from('{{%ybwm_core_category}}')
->where('uniacid=:uniacid AND deleteAt=0 AND item=:item',['item'=>$item,':uniacid'=>$this->wqData['uniacid']]);
$count=$table->count();
$res=$table->orderBy('sort asc,id desc')->offset(($page - 1) * $size)->limit($size)->all();
for($i=0;$i<$count;$i++){
$res[$i]['data']=json_decode($res[$i]['data'],true)?:[];
}
return $this->result(1,'成功',$res,$count);
}
//门店分类
public function actionStoreCategory(){
$request = Yii::$app->request;
if ($request->isGet){
$result=Yii::$app->request->get();
$shopInfo=(new \yii\db\Query())
->select(['id', 'name','sort','display'])
->from('{{%ybwm_core_category}}')
->where('uniacid=:uniacid AND id=:id',[':uniacid'=>$this->wqData['uniacid'],':id'=>$result['id']]);
$info=$shopInfo->one()?:[];
$info['data']=json_decode($info['data'],true)?:[];
return $this->result(1,'成功',$info);
}
$result=axios_request();
if(!$result['name']){
return $this->result(2,'名称不能为空!');
}
$array=array(
'item'=>$result['item'],
'name'=>$result['name'],
'uniacid'=>$this->wqData['uniacid'],
'sort'=>$result['sort'],
'display'=>1,
);
if($result['type']){
$array['data']=json_encode(array(
'type'=>$result['type'],
'goodsPlatformProportion'=>$result['goodsPlatformProportion'],
'goodsStoreProportion'=>$result['goodsStoreProportion'],
'goodsDownMoney'=>$result['goodsDownMoney'],
'deliverPlatformProportion'=>$result['deliverPlatformProportion'],
'deliverStoreProportion'=>$result['deliverStoreProportion'],
'deliverDownMoney'=>$result['deliverDownMoney'],
'boxPlatformProportion'=>$result['boxPlatformProportion'],
'boxStoreProportion'=>$result['boxStoreProportion'],
'boxDownMoney'=>$result['boxDownMoney'],
'goodsFixedMoney'=>$result['goodsFixedMoney'],
'deliverFixedMoney'=>$result['deliverFixedMoney'],
'boxFixedMoney'=>$result['boxFixedMoney'],
'cashierPlatformProportion'=>$result['cashierPlatformProportion'],
'cashierStoreProportion'=>$result['cashierStoreProportion'],
'cashierDownMoney'=>$result['cashierDownMoney'],
'cashierFixedMoney'=>$result['cashierFixedMoney'],
'fastPlatformProportion'=>$result['fastPlatformProportion'],
'fastStoreProportion'=>$result['fastStoreProportion'],
'fastDownMoney'=>$result['fastDownMoney'],
'fastFixedMoney'=>$result['fastFixedMoney'],
'inStorePlatformProportion'=>$result['inStorePlatformProportion'],
'inStoreStoreProportion'=>$result['inStoreStoreProportion'],
'inStoreDownMoney'=>$result['inStoreDownMoney'],
'inStoreFixedMoney'=>$result['inStoreFixedMoney'],
));
}
if($result['id']){
$array['changeAt']=time();
$re = Yii::$app->db->createCommand()->update('{{%ybwm_core_category}}', $array, 'id=:id', ['id' =>$result['id']])->execute();
}else{
$array['createdAt']=time();
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_core_category}}', $array)->execute();
}
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//修改分类
public function actionModifyStoreCategory(){
$post=axios_request();
if($post['type']==1){
//显示隐藏
$data['display']=$post['display'];
}
if($post['type']==2){
//删除
$data['deleteAt']=time();
}
$data['changeAt']=time();
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_category}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
if($res){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//门店账号信息
public function actionStoreAccount(){
$request = Yii::$app->request;
if ($request->isGet){
$result=Yii::$app->request->get();
$info=(new \yii\db\Query())
->select(['id', 'userName','passWord','phone','userId merchantId'])
->from('{{%ybwm_users}}')
->where('uniacid=:uniacid and storeId=:storeId and type=3',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$result['id']])
->one()?:[];
$userData=(new \yii\db\Query())
->from('{{%ybwm_users}}')
->where(['>','userId',''])
->all();
$ids=array_column($userData,'userId');
$merchantUser=(new \yii\db\Query())
->select('id,userName,portrait')
->from('{{%ybwm_merchant_member}}')
->where(['>','userName',''])->andWhere(['not in','id',$ids])
->andWhere(['>','portrait',''])
->all();
$res=(new \yii\db\Query())
->select('id,userName')
->from('{{%ybwm_merchant_member}}')->where(['id'=>$info['merchantId']])->all()?:[];
$merchantUser=array_merge($merchantUser,$res);
$info['merchantUser']=$merchantUser;
$res=getSysInfo();
$serviceData=$res['authData']['service'];
$info['app']=true;
if(in_array('app',$serviceData)==false){
$info['app']=false;
}
return $this->result(1,'成功',$info);
}
$shopInfo=Store::getMainStore($this->wqData['uniacid']);
if(!$shopInfo){
return $this->result(2,'请先添加商户信息!');
}
$result=axios_request();
if(!$result['userName']){
return $this->result(2,'商家账号不能为空!');
}
if(!$result['password']){
return $this->result(2,'商家密码不能为空!');
}
if(!$result['bindTel']){
return $this->result(2,'商家绑定手机号不能为空!');
}
if(!$result['id']&&$result['userName']){
return $this->result(2,'请先添加门店信息!');
}
if($result['id']){
$res=(new \yii\db\Query())
->select(['id', 'userName','passWord','phone'])
->from('{{%ybwm_users}}')
->where('uniacid=:uniacid and storeId=:storeId and type=3',[':uniacid'=>$this->wqData['uniacid'],':storeId'=>$result['id']])
->one();
if($res){
if(trim($result['userName'])!==$res['userName']){
$row=(new \yii\db\Query())
->from('{{%ybwm_users}}')
->where('userName=:userName',[':userName'=>trim($result['userName'])])
->one();
if($row){
return $this->result(2,'用户名已存在!');die;
}
}
if($result['password']!==$row['password']){
$salt=randoms(8);
$auth_key=Yii::$app->params['authkey'];
$password=checkPassWord($salt,$auth_key,trim($result['password']));
}else{
$salt=$row['salt'];
$password=$result['password'];
}
$array=array(
'userName'=>$result['userName'],
'passWord'=>$password,
'phone'=>$result['bindTel'],
'salt'=>$salt,
'userId'=>$result['merchantId']
);
$re = Yii::$app->db->createCommand()->update('{{%ybwm_users}}', $array, 'id=:id', ['id' =>$res['id']])->execute();
}else{
$salt=randoms(8);
$auth_key=Yii::$app->params['authkey'];
$password=checkPassWord($salt,$auth_key,trim($result['password']));
$row=(new \yii\db\Query())
->from('{{%ybwm_users}}')
->where('uniacid=:uniacid and userName=:userName',[':uniacid'=>$this->wqData['uniacid'],':userName'=>$result['userName']])
->one();
if($row){
return $this->result(2,'用户名已存在!');die;
}
$array=array(
'userName'=>$result['userName'],
'passWord'=>$password,
'phone'=>$result['bindTel'],
'type'=>3,
'createdAt'=>time(),
'storeId'=>$result['id'],
'uniacid'=>$this->wqData['uniacid'],
'salt'=>$salt,
'userId'=>$result['merchantId']
);
YII::$app->db->createCommand()->insert('{{%ybwm_users}}', $array)->execute();
}
}
return $this->result(1,'成功');
}
//获取城市
public function actionGetCity(){
$type=Yii::$app->request->get('type')?:3;
return $this->result(1,'成功',getCity($type));
}
// public function actionTest(){
// $res=WeChat::getTemplates('');
// print_R($res);die;
// $config = [
// 'app_id' => 'wx2f926923ad50c5e5',
// 'secret' => 'a064de981d2664eed033fb8d85adc4b5',
// 'response_type' => 'array',
//
// 'log' => [
// 'level' => 'debug',
// 'file' => __DIR__.'/wechat.log',
// ],
// ];
//
// $miniProgram = Factory::miniProgram($config);
// $response =$miniProgram->app_code->get('yb_o2o/index/index');
// $dir="web";
// $file='111.jpg';
// if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
// $filename = $response->save($dir,$file);
// //微擎版本
// if(Yii::$app->params['isDev']==true){
// $host=Yii::$app->request->hostInfo.'/addons/'.$this->wqData['module'].'/';
// }else{
// $host=Yii::$app->request->hostInfo.'/';
// }
// return $this->result(1,'成功',$host.$dir."/".$filename);
// }else{
// return $this->result(2,'失败');
// }
//// print_R($filename);die;
//
// }
//------------------------------门店活动
public function actionGetActivityList(){
$page=Yii::$app->request->get('page')?Yii::$app->request->get('page'):1;
$num=($page-1)*10;
$limit=10;
$data= (new \yii\db\Query())
->select('id,type,details,createdAt,from_unixtime(startTime)startTime,from_unixtime(endTime)endTime,display')
->from('{{%ybwm_shop_activity}}')
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid']])
->offset($num)
->limit($limit)
->all();
$count=(new \yii\db\Query()) ->from('{{%ybwm_shop_activity}}')->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid']])->count();
return $this->result(1,'成功',$data,$count);
}
public function actionActivitySave(){
$request = Yii::$app->request;
if($request->isPost){
$result=axios_request();
$data=array(
'sort'=>$result['sort'],
'type'=>$result['type'],
'details'=>$result['details'],
'uniacid'=>$this->wqData['uniacid'],
'startTime'=>strtotime($result['startTime']),
'endTime'=>strtotime($result['endTime']),
);
$data=filter_array($data);
if($result['id']){
$re = YII::$app->db->createCommand()->update('{{%ybwm_shop_activity}}', $data, ['id'=>$result['id']])->execute();
}else{
$data['createdAt']=time();
//dd($data);die;
$re = YII::$app->db->createCommand()->insert('{{%ybwm_shop_activity}}', $data)->execute();
}
return $this->result(1,'成功');
}
}
public function actionChangeActivity(){
$request = Yii::$app->request;
if($request->isPost){
$result=axios_request();
$id=$result['id'];
if(is_array($id)){
$re = YII::$app->db->createCommand()->update('{{%ybwm_shop_activity}}', ['display'=>$result['display']], ['in','id',$id])->execute();
}else{
$re = YII::$app->db->createCommand()->update('{{%ybwm_shop_activity}}', ['display'=>$result['display']], ['id'=>$id])->execute();
}
return $this->result(1,'成功');
}
}
public function actionActivityDel(){
$request = Yii::$app->request;
if($request->isPost){
$id=axios_request()['id'];
if(is_array($id)){
$re = YII::$app->db->createCommand()->update('{{%ybwm_shop_activity}}', ['deleteAt'=>time()], ['in','id',$id])->execute();
}else{
$re = YII::$app->db->createCommand()->update('{{%ybwm_shop_activity}}', ['deleteAt'=>time()], ['id'=>$id])->execute();
}
return $this->result(1,'成功');
}
}
//-----------------------------------------商户概况
public function actionRealProfit(){
$request = Yii::$app->request;
if ($request->isGet){
$result=axios_request();
$orginArr=[1,2];
$uniacid=$this->wqData['uniacid'];
/**
* 判断平台到期状态提前7天提示
*/
$expireStatus=1;
if(Yii::$app->params['dev']==true){
$applyInfo=(new \yii\db\Query())
->from('{{%ims_account}}')->where(['id'=>$uniacid])
->one();
$endTime=$applyInfo['endtime'];
}else{
$applyInfo=(new \yii\db\Query())
->from('{{%ybwm_apply}}')->where(['id'=>$uniacid])
->one();
$endTime=strtotime($applyInfo['end_time']);
}
if($endTime<=(time()+7*24*60*60)&&$endTime>0){
$expireStatus=2;
}
//dd($this->getShopId($uniacid));die;
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
$shopInfo=(new \yii\db\Query())
->select('id,name,icon,storeOpen,receiveStatus,storeNumber')
->from('{{%ybwm_store}}')
->where(['id'=>$storeId])
->one()?:[];
//打印机
$printCount=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->count()?:0;
}
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//当天时间内的数据
$time=strtotime(date('Y-m-d',time()));
$todayArr=(new \yii\db\Query())
->select(new Expression("from_unixtime(createdAt,'%H') as hours,sum(money)money"))
->from('{{%ybwm_bill}}')
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
// ->andWhere(['in','origin',Statistics::origin()])
->andWhere('refundMoney=0 or refundMoney is null')
->groupBy(new Expression("from_unixtime(createdAt,'%H')"))
->orderBy(new Expression("from_unixtime(createdAt,'%H')"))
->all();
foreach ($todayArr as $k=>$v){
$todayArr[$k]['hours']=$v['hours']+1;
}
//dd($todayArr);die;
$todayArr=CreatQuery(1,$todayArr);
//$todayArr=$this->TimeQuery(1,$sql);
$todayTotal=array_sum(array_column($todayArr,'money'));
$todayTotal=sprintf("%.2f",$todayTotal);
$yesTime=strtotime(date('Y-m-d',time()-24*60*60));
$yesterdayArr=(new \yii\db\Query())
->select(new Expression("from_unixtime(createdAt,'%H') as hours,sum(money)money"))
->from('{{%ybwm_bill}}')
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
->andWhere(['>=','createdAt',$beginYesterday])
->andWhere(['<','createdAt',$endYesterday])
//->andWhere(['in','origin',Statistics::origin()])
->andWhere('refundMoney=0 or refundMoney is null')
->groupBy(new Expression("from_unixtime(createdAt,'%H')"))
->orderBy(new Expression("from_unixtime(createdAt,'%H')"))
->all();
foreach ($yesterdayArr as $k=>$v){
$yesterdayArr[$k]['hours']=$v['hours']+1;
}
$yesterdayArr=CreatQuery(1,$yesterdayArr);
$yesterdayTotal=number_format(array_sum(array_column($yesterdayArr,'money')),2);
//预计收入
$yujiSum=Financial::getIncome($beginToday,$endToday,$uniacid,$storeId,[]);
// var_dump($yujiSum);die;
$yesterSum=Financial::getIncome($beginYesterday,$endYesterday,$uniacid,$storeId,[]);
//有效订单
$payCount=Financial::getEffective($beginToday,$endToday,$uniacid,$storeId,[]);
$yesPayCount=Financial::getEffective($beginYesterday,$endYesterday,$uniacid,$storeId,[]);
//付款人数
$userCount=Statistics::getPayPeople($uniacid,$storeId,$beginToday,$endToday);
//昨日付款人数
$yesuserCount=Statistics::getPayPeople($uniacid,$storeId,$beginYesterday,$endYesterday);
//浏览量
$visitCount=(new \yii\db\Query())
->from('{{%ybwm_visit_list}}')
->where(['uniacid'=>$uniacid])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->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;
//待处理订单
$peedCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0,'state'=>2])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
//->andWhere(['in','state',[2,3,4,9]])
->count()?:0;
//var_dump(ddSql($peedCount));die;
$peedOkCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0,'state'=>2])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
//->andWhere(['in','state',[2,3,4,9]])
->andWhere(['appointment'=>2])
->count()?:0;
$dePeedCount=$peedCount-$peedOkCount;
//待配送订单
$deliveredCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['state'=>3])
->count()?:0;
$deliveredOkCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['state'=>3])
->andWhere(['appointment'=>2])
->count()?:0;
$bedeliveredCount=$deliveredCount-$deliveredOkCount;
//配送中
$peiCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['state'=>4])
->andWhere(['<>','deliveryMode',10])
->count()?:0;
$peiOkCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['state'=>4])
->andWhere(['<>','deliveryMode',10])
->count()?:0;
$peiErrorCount=$peiCount-$peiOkCount;
//待自提订单
$raisedCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['deliveryMode'=>10])
->andWhere(['appointment'=>2])
->andWhere(['state'=>4])
->count()?:0;
$raisedOkCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['deliveryMode'=>10])
->andWhere(['appointment'=>2])
->andWhere(['state'=>4])
->count()?:0;
$beraisedCount=$raisedCount-$raisedOkCount;
//待完成订单
$completedCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['in','state',[2,3,4]])
->count()?:0;
$completedOkCount=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['in','state',[2,3,4]])
->andWhere(['appointment'=>2])
->count()?:0;
$becompletedCount=$completedCount-$completedOkCount;
//售后/维权订单
$safeCount=(new \yii\db\Query())
->from('{{%ybwm_bill}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['>','refundMoney',''])
->count()?:0;
$yesSafeCount=(new \yii\db\Query())
->from('{{%ybwm_bill}}')
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'deleteAt'=>0])
->andWhere(['>=','createdAt',$beginYesterday])
->andWhere(['<','createdAt',$endYesterday])
->andWhere(['>','refundMoney',''])
->count()?:0;
//$beSafeCount=$safeCount-$safeOkCount;
$beSafeCount=0;
//流量看板
$visitArr=(new \yii\db\Query())
->select(new Expression("from_unixtime(createdAt,'%H') as hours,count(*) money"))
->from('{{%ybwm_visit_list}}')
->where(['uniacid'=>$uniacid])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['in','modelname',[1,2]])
->groupBy(new Expression("from_unixtime(createdAt,'%H')"))
->orderBy(new Expression("from_unixtime(createdAt,'%H')"))
->all();
//var_dump(ddSql($visitArr));die;
$visitArr=CreatQuery(1,$visitArr);
//dd($visitArr);die;
$visitGroup=(new \yii\db\Query())
->select(new Expression("from_unixtime(createdAt,'%H') as hours,count(DISTINCT userId)money"))
->from('{{%ybwm_visit_list}}')
->where(['uniacid'=>$uniacid])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday])
->andWhere(['in','modelname',[1,2]])
->groupBy(new Expression("from_unixtime(createdAt,'%H')"))
->orderBy(new Expression("from_unixtime(createdAt,'%H')"))
->all();
//var_dump(ddSql($visitGroup));die;
$visitGroupArr=CreatQuery(1,$visitGroup);
//$visitTotal=array_sum(array_column($visitArr,'money'));
//访客量
$visitTodayCount=Statistics::getVisitCount($uniacid,$storeId,$beginToday,$endToday,1);
//var_dump(ddSql($visitTodayCount));die;
// $visitYesCount=Statistics::getVisitCount($uniacid,$storeId,$beginYesterday,$endYesterday);
$visitSumCount=Statistics::getVisitCount($uniacid,$storeId,$beginYesterday,$endYesterday,1);
//商品销量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')
->leftJoin('{{%ybwm_takeout_order}} as c','a.orderId=c.id')
->where(['a.uniacid'=>$uniacid,'a.storeId'=>$storeId,'a.item'=>1])
->andWhere(['<','a.createdAt',$endToday])
->andWhere(['>','a.createdAt',$beginToday])
->andWhere(['in','c.state',[2,3,4,5,6,9]])
->groupBy('goodsId')
->orderBy('num desc')
->limit(10)->all()?:[];
foreach ($goodsData as $key=>$v){
$goodsData[$key]['id']=$key+1;
}
//支付TOP10商品
$orderData=(new \yii\db\Query())
->select('b.name,sum(a.num)num,sum(a.money*a.num) totalMoney')
->from('{{%ybwm_order_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->leftJoin('{{%ybwm_takeout_order}} as c','a.orderId=c.id')
->where(['a.uniacid'=>$uniacid,'a.storeId'=>$storeId,'a.item'=>1])
->andWhere(['<','a.createdAt',$endToday])
->andWhere(['>','a.createdAt',$beginToday])
->andWhere(['in','c.state',[2,3,4,5,6,9]])
->groupBy('goodsId')
->orderBy('totalMoney desc')
->limit(10)
->all()?:[];
foreach ($orderData as $key=>$v){
$orderData[$key]['id']=$key+1;
}
$informationData= (new \yii\db\Query())
->select('introduction,from_unixtime(createdAt)createdAt,body,title')
->from('{{%ybwm_information}} a')
->where(['deleteAt'=>0,'uniacid'=>$uniacid,'type'=>2,'display'=>1])
->orderBy('id desc')
->limit(6)
->all()?:[];
$noticeData= (new \yii\db\Query())
->select('title,introduction,from_unixtime(createdAt)createdAt')
->from('{{%ybwm_notice}}')
->where(['deleteAt'=>0,'uniacid'=>$uniacid,'noticeType'=>2,'display'=>1])
->orderBy('id desc')
->limit(3)
->all()?:[];
//营业时间段
$shopConfig=Config::getStoreSet('takeOutSet',$storeId);
// dd($shopConfig);die;
$storeOpen=Store::getStoreOutBusiness($storeId);
$shopInfoArr=array(
'timeType'=>$shopConfig['timeType'],
'timeArr'=>$shopConfig['timeArr'],
'storeOpen'=>$storeOpen
);
//下单转换率
$conversion=Statistics::getConversion($uniacid,$storeId,$beginToday,$endToday);
$yesConversion=Statistics::getConversion($uniacid,$storeId,$beginYesterday,$endYesterday);
$payQuery=(new \yii\db\Query())
->from('{{%ybwm_bill}}')
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
->andWhere(['>=','createdAt',$beginToday])
->andWhere(['<','createdAt',$endToday]);
//外卖有效订单
$outCount=(clone $payQuery)->andWhere(['origin'=>1])->andWhere('refundMoney=0 or refundMoney is null')->count();
//外卖营业金额
$outMoney=(clone $payQuery)->andWhere(['origin'=>1])->andWhere('refundMoney=0 or refundMoney is null')->sum('money');
//外卖退款售后订单
$outRefundMoney=(clone $payQuery)->andWhere(['origin'=>1])->andWhere(['>','refundMoney',0])->sum('money');
//堂食有效订单
$inCount=(clone $payQuery)->andWhere(['origin'=>7])->andWhere('refundMoney=0 or refundMoney is null')->count();
//堂食营业金额
$inMoney=(clone $payQuery)->andWhere(['origin'=>7])->andWhere('refundMoney=0 or refundMoney is null')->sum('money');
//堂食退款售后订单
$inRefundMoney=(clone $payQuery)->andWhere(['origin'=>1])->andWhere(['>','refundMoney',0])->sum('money');
//快餐有效订单
$fastCount=(clone $payQuery)->andWhere(['origin'=>6])->andWhere('refundMoney=0 or refundMoney is null')->count();
//快餐营业金额
$fastMoney=(clone $payQuery)->andWhere(['origin'=>6])->andWhere('refundMoney=0 or refundMoney is null')->sum('money');
//快餐退款售后订单
$fastRefundMoney=(clone $payQuery)->andWhere(['origin'=>6])->andWhere(['>','refundMoney',0])->sum('money');
//当面付有效订单
$payFaceCount=(clone $payQuery)->andWhere(['origin'=>5])->andWhere('refundMoney=0 or refundMoney is null')->count();
//当面付营业金额
$payFaceMoney=(clone $payQuery)->andWhere(['origin'=>5])->andWhere('refundMoney=0 or refundMoney is null')->sum('money');
//当面付退款售后订单
$payFaceRefundMoney=(clone $payQuery)->andWhere(['origin'=>5])->andWhere(['>','refundMoney',0])->sum('money');
//其他订单
$otherCount=number_format($payCount-$outCount-$inCount-$fastCount-$payFaceCount);
//其他订单营业金额
$otherMoney=number_format($todayTotal-$outMoney-$inMoney-$fastMoney-$payFaceMoney,2);
//微信支付金额
$wxPayMoney=(clone $payQuery)->andWhere(['payMode'=>1])->sum('money');
//支付宝支付金额
$aliPayMoney=(clone $payQuery)->andWhere(['payMode'=>2])->sum('money');
//余额支付金额
$balanceMoney=(clone $payQuery)->andWhere(['payMode'=>5])->sum('money');
//货到付款支付金额
$deliveryMoney=(clone $payQuery)->andWhere(['payMode'=>10])->sum('money');
//线下支付金额
$offlineMoney=(clone $payQuery)->andWhere(['payMode'=>6])->sum('money');
echo json_encode(array(
'code'=>1,
'msg'=>'成功',
'data'=>array(
'shopData'=>$shopInfo,
'printCount'=>$printCount?:0,
'todayChar'=>$todayArr,
'yesterChar'=>$yesterdayArr,
'todayTotal'=>$todayTotal?:0.00,
'yesterdayTotal'=>$yesterdayTotal?:0.00,
'yujiSum'=>$yujiSum?:0.00,
'yesterSum'=>$yesterSum?:0.00,
'payCount'=>$payCount?:0,
'yesPayCount'=>$yesPayCount?:0,
'userCount'=>$userCount?:0,
'yesuserCount'=>$yesuserCount?:0,
'visitCount'=>$visitCount?:0,
'yesVisitCount'=>$yesVisitCount?:0,
'peedCount'=>$peedCount?:0,
'peedOkCount'=>$peedOkCount?:0,
'dePeedCount'=>$dePeedCount?:0,
'deliveredCount'=>$deliveredCount?:0,
'deliveredOkCount'=>$deliveredOkCount?:0,
'bedeliveredCount'=>$bedeliveredCount?:0,
'raisedCount'=>$raisedCount?:0,
'raisedOkCount'=>$raisedOkCount?:0,
'beraisedCount'=>$beraisedCount?:0,
'completedCount'=>$completedCount?:0,
'completedOkCount'=>$completedOkCount?:0,
'becompletedCount'=>$becompletedCount?:0,
'safeCount'=>$safeCount?:0,
'beSafeCount'=>$beSafeCount?:0,
'visitArr'=>$visitArr,
'visitGroupArr'=>$visitGroupArr,
'visitTotal'=>$visitCount?:0,
'totalVisitCount'=>$visitTodayCount?:0,
'visitYesCount'=>$yesVisitCount?:0,
'visitSumCount'=>$visitSumCount?:0,
'goodsData'=>$goodsData,
'orderData'=>$orderData,
'informationData'=>$informationData,
'noticeData'=>$noticeData,
'shopInfoArr'=>$shopInfoArr,
'peiCount'=>$peiCount?:0,
'peiOkCount'=>$peiOkCount?:0,
'peiErrorCount'=>$peiErrorCount?:0,
'expireStatus'=>$expireStatus,
'conversion'=>$conversion,
'yesConversion'=>$yesConversion,
'outCount'=>$outCount?:0,
'outMoney'=>$outMoney?:0.00,
'outRefundMoney'=>$outRefundMoney?:0.00,
'inCount'=>$inCount?:0,
'inMoney'=>$inMoney?:0.00,
'inRefundMoney'=>$inRefundMoney?:0.00,
'fastCount'=>$fastCount?:0,
'fastMoney'=>$fastMoney?:0,
'fastRefundMoney'=>$fastRefundMoney?:0.00,
'payFaceCount'=>$payFaceCount?:0,
'payFaceMoney'=>$payFaceMoney?:0.00,
'payFaceRefundMoney'=>$payFaceRefundMoney?:0.00,
'otherCount'=>$otherCount?:0,
'otherMoney'=>$otherMoney?:0.00,
'wxPayMoney'=>$wxPayMoney?:0.00,
'aliPayMoney'=>$aliPayMoney?:0.00,
'balanceMoneyy'=>$balanceMoney?:0.00,
'deliveryMoney'=>$deliveryMoney?:0.00,
'offlineMoney'=>$offlineMoney?:0.00,
'yesSafeCount'=>$yesSafeCount?:0
),
));die;
}
//营业状态 自动接单 type
public function actionChangeShopStatus(){
$request = Yii::$app->request;
$result=axios_request();
$uniacid=$this->wqData['uniacid'];
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
if ($request->isGet){
$receiveStatus=(new \yii\db\Query())
->select('receiveStatus')
->from('{{%ybwm_store}}')
->where(['uniacid'=>$uniacid,'id'=>$storeId])
->one()['receiveStatus']?:2;
$data['receiveStatus']=$receiveStatus;
return $this->result(1,'成功',$data);
}
if ($request->isPost){
if($result['type']==1){
YII::$app->db->createCommand()->update('{{%ybwm_store}}', ['storeOpen'=>$result['storeOpen']], ['id'=>$storeId])->execute();
}elseif($result['type']==2){
YII::$app->db->createCommand()->update('{{%ybwm_store}}', ['receiveStatus'=>$result['receiveStatus']], ['id'=>$storeId])->execute();
}
return $this->result(1,'成功');
}
}
//查看商家
public function actionSelectStore(){
$res=(new \yii\db\Query())
->select(['id', 'name'])
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid AND deleteAt=0',[':uniacid'=>$this->wqData['uniacid']])
->orderBy('isMain asc,sort asc,id desc')->all();
return $this->result(1,'成功',$res);
}
//获取当前经纬度
public function actionGetCoordinate(){
$result=Store::location($this->wqData['uniacid']);
return $this->result(1,'成功',$result);
}
//门店概况
public function actionShopSurvey(){
$query=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where(['uniacid'=>$this->wqData['uniacid'],'deleteAt'=>0]);
$shopNum=$query->count();
$zhiShopNum=(clone $query)->andWhere(['type'=>1])->count();
$jiaShopNum=(clone $query)->andWhere(['type'=>2])->count();
$money=(new \yii\db\Query())
->from('{{%ybwm_store_finance}}')
->where(['uniacid'=>$this->wqData['uniacid'],'deleteAt'=>0,'state'=>1])->sum('money');
$start_time=strtotime(date("Y-m-d",time()));
$end_time=$start_time+60*60*24;
$moneyArr=Statistics::getShopMoneyChart($this->wqData['uniacid'],$this->wqData['storeId'],$start_time,$end_time);
$moneyResult=CreatQuery(1,$moneyArr);
$payArr=Statistics::getShopPayChart($this->wqData['uniacid'],$this->wqData['storeId'],$start_time,$end_time);
$payResult=CreatQuery(1,$payArr);
$shopData=Statistics::shopPayAsc($this->wqData['uniacid'],$this->wqData['storeId'],$start_time,$end_time);
if($shopData){
foreach ($shopData as $k=>$v){
$shopData[$k]['visit']=Statistics::getViews($this->wqData['uniacid'],$v['storeId'],$start_time,$end_time);
}
}
$data=array(
'shopNum'=>$shopNum,
'zhiShopNum'=>$zhiShopNum,
'jiaShopNum'=>$jiaShopNum,
'money'=>$money,
'moneyResult'=>$moneyResult,
'payResult'=>$payResult,
'shopData'=>$shopData,
);
return $this->result(1,'成功',$data);
}
//门店选择商品模式
/*模式一:商品同步 同步总店商品名称 价格 库存 门店只能上下架操作
模式二:商品不同步 子门店 只能修改库存和价格 以及上下架操作
模式三:超级权限 子门店 可以添加分类和商品,以及修改商品库存和价格、上下架操作*/
// public function actionChangeGoodsModel(){
// $request = Yii::$app->request;
// if ($request->isPost) {
// $result = axios_request();
// $uniacid=$this->wqData['uniacid'];
// $goodData = (new \yii\db\Query())
// ->from('{{%ybwm_core_goods}}')
// ->where(['uniacid'=>$uniacid,'storeId'=>$this->shop_id])
// ->all();
// if ($result['storeId']) {
// //门店切换商品模式
// $res = (new \yii\db\Query())
// ->select('goodsModel,isMain')
// ->from('{{%ybwm_store}}')
// ->where('uniacid=:uniacid AND id=:id and deleteAt=0', [':uniacid' =>$uniacid, 'id' => $result['storeId']])
// ->one();
// switch ($res['goodsModel']) {
// case 1;
// YII::$app->db->createCommand()->delete('{{%ybwm_store_goods}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// break;
// case 2;
// YII::$app->db->createCommand()->delete('{{%ybwm_store_goods}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// break;
// case 3;
// YII::$app->db->createCommand()->delete('{{%ybwm_core_goods}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// YII::$app->db->createCommand()->delete('{{%ybwm_good_specs}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// YII::$app->db->createCommand()->delete('{{%ybwm_store_goods}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// YII::$app->db->createCommand()->delete('{{%ybwm_good_attribute}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// YII::$app->db->createCommand()->delete('{{%ybwm_good_materia}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// YII::$app->db->createCommand()->delete('{{%ybwm_good_hours}}', ['uniacid' =>$uniacid, 'storeId' => $result['storeId']])->execute();
// break;
// }
// $goodData = (new \yii\db\Query())
// ->from('{{%ybwm_core_goods}}')
// ->where(['uniacid'=>$uniacid,'storeId'=>$this->shop_id])
// ->all();
//
// if ($res['isMain']==2){
// foreach ($goodData as $v) {
// $subArray = array(
// 'goodsId' =>$v['id'],
// 'display' => 3,
// 'stock' => $v['stock'],
// 'price' => $v['price'],
// 'storeId' => $result['storeId'],
// 'uniacid' => $this->wqData['uniacid'],
// 'createdAt' => time(),
// 'isRecommend'=>$v['isRecommend'],
// 'maxPrice'=>$v['maxPrice']
// );
// $spcesUpData= (new \yii\db\Query())
// ->select('id,goodId,specsName,boxMoney,crossedPrice,SalesPrice,SalesStock,costPrice,fillType')
// ->from('{{%ybwm_good_specs}}')
// ->where(['goodId' =>$v['id']])
// ->all();
// if($spcesUpData){
// $subArray['data']=json_encode(array('specs'=>$spcesUpData));
// }
// Yii::$app->db->createCommand()->insert('{{%ybwm_store_goods}}', $subArray)->execute();
// }
// }
// if($result['goodsModel']==3){
// foreach ($goodData as $v) {
// $list = [];
// $list = $v;
// $list['goodsPid']=$v['id'];
// $list['display'] = 3;
// $list['storeId'] = $result['storeId'];
// unset($list['id']);
// Yii::$app->db->createCommand()->insert('{{%ybwm_core_goods}}', $list)->execute();
// $id = Yii::$app->db->getLastInsertID();
// //多规格的导入
// if($v['isSpecs']){
// $specsData = (new \yii\db\Query())
// ->from('{{%ybwm_good_specs}}')
// ->where(['uniacid'=>$uniacid,'storeId'=>$this->shop_id,'goodId'=>$list['id']])
// ->all();
// foreach ($specsData as $v){
// $list = [];
// $list = $v;
// $list['goodId']=$id;
// $list['storeId'] =$result['storeId'];
// $list['createdAt'] =time();
// unset($list['id']);
// Yii::$app->db->createCommand()->insert('{{%ybwm_good_specs}}', $list)->execute();
// }
// }
// //属性的导入
// if($v['isAttr']){
// $attrData = (new \yii\db\Query())
// ->from('{{%ybwm_good_attribute}}')
// ->where(['uniacid'=>$uniacid,'storeId'=>$this->shop_id,'goodId'=>$list['id']])
// ->all();
// if($attrData){
// foreach ($attrData as $v){
// $list = [];
// $list = $v;
// $list['goodId']=$id;
// $list['storeId'] =$result['storeId'];
// $list['createdAt'] =time();
// unset($list['id']);
// Yii::$app->db->createCommand()->insert('{{%ybwm_good_attribute}}', $list)->execute();
// }
// }
//
// }
// //加料的导入
// if($v['isMaterial']){
// $materialData = (new \yii\db\Query())
// ->from('{{%ybwm_good_materia}}')
// ->where(['uniacid'=>$uniacid,'storeId'=>$this->shop_id,'goodId'=>$list['id']])
// ->all();
// if($materialData){
// foreach ($materialData as $v){
// $list = [];
// $list = $v;
// $list['goodId']=$id;
// $list['storeId'] =$result['storeId'];
// $list['createdAt'] =time();
// unset($list['id']);
// Yii::$app->db->createCommand()->insert('{{%ybwm_good_materia}}', $list)->execute();
// }
// }
//
// }
// if($v['salesType']==2){
// $salesData = (new \yii\db\Query())
// ->from('{{%ybwm_good_hours}}')
// ->where(['uniacid'=>$uniacid,'storeId'=>$this->shop_id,'goodId'=>$list['id']])
// ->all();
// if($salesData){
// foreach ($materialData as $v){
// $list = [];
// $list = $v;
// $list['goodId']=$id;
// $list['storeId'] =$result['storeId'];
// unset($list['id']);
// Yii::$app->db->createCommand()->insert('{{%ybwm_good_hours}}', $list)->execute();
// }
// }
// }
// }
// }
// $re = YII::$app->db->createCommand()->update('{{%ybwm_store}}', ['changeAt' => time(), 'goodsModel' => $result['goodsModel']], ['uniacid' => $this->wqData['uniacid'], 'id' => $result['storeId']])->execute();
// return $this->result(1, '成功');
// }
// }
// return $this->result(2,'请求异常');
// }
//提现列表
public function actionWithdrawalList(){
$result=axios_request();
$uniacid=$this->wqData['uniacid'];
$keyword=$result['keyword'];
$startTime=strtotime($result['startTime']);
$endTime=strtotime($result['endTime']);
$state=$result['state'];
$page=$result['page']?:1;
$num=($page-1)*10;
$limit=10;
$table=(new \yii\db\Query())
->select('a.id,s.name as storeName,a.type,a.money,a.charge,a.actualMoney,a.state,a.account,from_unixtime(a.createdAt) createdAt')
->from('{{%ybwm_store_finance}} as a')
->join('LEFT JOIN', '{{%ybwm_store}} as s', 's.id = a.storeId')
->where(['a.uniacid'=>$uniacid]);
if($keyword){
$table->andWhere(['like','s.name',$keyword]);
}
if($state){
$table->andWhere('state='.$state);
}
if($startTime AND $endTime){
$table->andWhere('a.createdAt>:startTime AND a.createdAt<:endTime',[':startTime'=>$startTime,':endTime'=>$endTime]);
}
$list=$table->offset($num)
->limit($limit)->orderBy('a.id desc')->all();
$count=$table->count();
for($i=0;$i<count($list);$i++){
$list[$i]['account']=json_decode($list[$i]['account'],true)?:[];
$list[$i]['account']['userName']='';
$user=(new \yii\db\Query())
->select('userName')
->from('{{%ybwm_member}}')
->where(['id'=>$list[$i]['account']['userId']])->one();
$list[$i]['account']['userName']=$user['userName'];
}
return $this->result(1, '成功',$list,$count);
}
//审核提现
public function actionModifyWithdrawal(){
$post=axios_request();
$finance=(new \yii\db\Query())
->from('{{%ybwm_store_finance}}')
->where(['id'=>$post['id']])->one();
if(!$finance || $finance['state']!=1){
return $this->result(2,'数据异常');
}
$type=$post['type'];
if($type=='makeAdopt' AND $finance['type']==1){
$account=json_decode($finance['account'],true);
$user=(new \yii\db\Query())
->select('openId')
->from('{{%ybwm_member}}')
->where(['id'=>$account['userId']])->one();
$weres=WeChat::toBalance($finance['uniacid'],$finance['outTradeNo'],$user['openId'],$finance['actualMoney'],'商家提现');
if($weres['result_code']=='FAIL'){
return $this->result(2,$weres['err_code_des']);
}
$data['state']=2;
}
if($type=='adopt'){
$data['state']=2;
}
if ($type == 'reject') {
$data['state'] = 3;
}
$res = Yii::$app->db->createCommand()->update('{{%ybwm_store_finance}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
if($res){
if($data['state'] == 3){
Bill::saveStoreBill($finance['uniacid'],$finance['storeId'],$finance['money'],1,7,'提现拒绝',time(),$finance['outTradeNo']);
}
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
/**
* 获取锁
* @param String $key 锁标识
* @param Int $expire 锁过期时间
* @return Boolean
*/
public function lock($key, $expire=5){
$is_lock = Yii::$app->redis->setnx($key, time()+$expire);
// 不能获取锁
if(!$is_lock){
// 判断锁是否过期
$lock_time = Yii::$app->redis->get($key);
// 锁已过期,删除锁,重新获取
if(time()>$lock_time){
$this->unlock($key);
$is_lock = Yii::$app->redis->setnx($key, time()+$expire);
}
}
return $is_lock? true : false;
}
/**
* 释放锁
* @param String $key 锁标识
* @return Boolean
*/
public function unlock($key){
return Yii::$app->redis->del($key);
}
/**
* 判断平台到期状态提前7天提示
*/
public function actionExpire(){
$uniacid=$this->wqData['uniacid'];
$data['status']=1;
if(Yii::$app->params['dev']==true){
$applyInfo=(new \yii\db\Query())
->from('{{%ims_account}}')->where(['id'=>$uniacid])
->one();
$endTime=$applyInfo['endtime'];
}else{
$applyInfo=(new \yii\db\Query())
->from('{{%ybwm_apply}}')->where(['id'=>$uniacid])
->one();
$endTime=strtotime($applyInfo['end_time']);
}
if($endTime<=(time()+7*24*60*60)&&$endTime>0){
$data['status']=2;
}
}
public function actionGetMerchantUser(){
$info=getSysInfo();
$userData=(new \yii\db\Query())
->from('{{%ybwm_users}}')
->where(['>','userId',''])
->all();
$ids=array_column($userData,'userId');
$merchantUser=(new \yii\db\Query())
->select('id,userName')
->from('{{%ybwm_merchant_member}}')
->where(['>','userName',''])->andWhere(['not in','id',$ids])
->all();
$serviceData=$info['authData']['service']?true:false;
$data['merchantUser']=$merchantUser;
$data['app']=$serviceData;
return $this->result(1,'成功',$data);
}
//商家端小程序信息保存
public function actionMerchantConfig(){
$request = Yii::$app->request;
$result=axios_request();
if($request->isGet){
$uniacid=0;
$data=(new \yii\db\Query())
->from('{{%ybwm_core_system}}')
->where(['ident'=>'merchantConfig','uniacid'=>$uniacid])->one();
$data=json_decode($data['data'],'true');
return $this->result(1,'成功',$data);
}
if($request->isPost){
$re=Config::getSystemSet('merchantConfig',0);
$re['uniacid']=$result['uniacid']?:0;
$re['miniName']=$result['miniName'];
$re['miniAppId']=$result['miniAppId'];
$re['miniOriginal']=$result['miniOriginal'];
$re['miniSecret']=$result['miniSecret'];
Config::saveSystemSet($re,'merchantConfig',0,'商家端小程序信息');
return $this->result(1,'成功');
}
}
public function actionTest(){
$res=getMonth(strtotime('2021-07'));
print_R($res);
}
}