226 lines
9.1 KiB
PHP
226 lines
9.1 KiB
PHP
<?php
|
|
namespace app\controllers\merchant;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use yii\web\Session;
|
|
use yii\web\Cookie;
|
|
use app\models\common\File;
|
|
use app\models\common\Config;
|
|
class CommonController extends Controller{
|
|
protected $wqData=[];
|
|
private $typeInfo = array(
|
|
'mini' => 1,
|
|
'weChat' => 2,
|
|
'ali' => 3,
|
|
'baidu' => 4,
|
|
'h5' => 5,
|
|
'pc' => 6,
|
|
'toutiao' => 7,
|
|
'apk'=>8
|
|
);
|
|
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' => '收银台',
|
|
);
|
|
public function result($code=1,$msg='成功',$data=[]){
|
|
return json_encode([
|
|
'code'=>$code,
|
|
'msg'=>$msg,
|
|
'data'=>$data,
|
|
]);
|
|
}
|
|
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;
|
|
}
|
|
protected $timeArr=[];
|
|
function init(){
|
|
parent::init();
|
|
|
|
$dominUrl=Yii::$app->request->hostInfo;
|
|
$dominUrl =preg_replace('#^(http(s?))?(://)#','', $dominUrl);
|
|
$data=array(
|
|
'domain_url'=>$dominUrl,
|
|
'auth_type'=>1,
|
|
);
|
|
$url=Yii::$app->params['domain_url'].'/cloud/auth/checkDomain';
|
|
$file_arr=json_decode(httpRequest($url,$data),true);
|
|
if($file_arr['code']==2){
|
|
echo json_encode(['code'=>2,'msg'=>$file_arr['msg']]);exit();
|
|
}
|
|
$result=axios_request();
|
|
$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->wqData['uniacid'] = Yii::$app->request->headers->get('uniacid');
|
|
$this->wqData['storeId'] = Yii::$app->request->headers->get('storeId');
|
|
$this->wqData['appType'] = $this->typeInfo[Yii::$app->request->headers->get('appType')];//应用类型
|
|
$this->wqData['userId'] = Yii::$app->request->headers->get('userId');//用户ID
|
|
$this->wqData['module']='yb_wm';
|
|
if(!$this->wqData['uniacid'] || !$this->wqData['appType']|| !$this->wqData['storeId']|| !$this->wqData['userId']) {
|
|
echo json_encode(['code'=>2,'msg'=>'非法请求']);exit();
|
|
}
|
|
}
|
|
//上传图片
|
|
public function actionUpload(){
|
|
//var_dump($_FILES);die;
|
|
$this->wqData['module']=$this->wqData['module']?:'yb_wm';
|
|
$config=Config::getSystemSet('storage',$this->wqData['uniacid']);
|
|
if($config['type']==1){
|
|
$fname=File::qiniuUpload('file',$this->wqData['module'],$this->wqData['uniacid'],$config);
|
|
}elseif($config['type']==2){
|
|
$fname=File::aliUpload('file',$this->wqData['module'],$this->wqData['uniacid'],$config);
|
|
}elseif($config['type']==3){
|
|
$fname=File::txyUpload('file',$this->wqData['module'],$this->wqData['uniacid'],$config);
|
|
}else{
|
|
$fname=File::channelUploadImage('file','',$this->wqData['module'],$this->wqData['uniacid']);
|
|
}
|
|
if(is_string($fname)){
|
|
$data['categoryId'] =0;
|
|
$data['url'] = $fname;
|
|
$data['name'] = $_FILES['file']['name'];
|
|
$data['storeId'] =$this->wqData['storeId'];
|
|
$data['createdAt'] = time();
|
|
$data['deleteAt'] = 0;
|
|
$data['uniacid'] = $this->wqData['uniacid'];
|
|
Yii::$app->db->createCommand()->insert('{{%ybwm_core_file}}', $data)->execute();
|
|
return $fname;
|
|
}
|
|
if(is_array($fname)){
|
|
return json_encode($fname);die;
|
|
}
|
|
}
|
|
|
|
|
|
public function actionCheckStore(){
|
|
if($this->wqData['storeId']){
|
|
echo json_encode([
|
|
'code' => 1,
|
|
'msg' => '成功'
|
|
]);die;
|
|
}else{
|
|
echo json_encode([
|
|
'code' => 2,
|
|
'msg' => '请添加商户信息'
|
|
]);die;
|
|
}
|
|
}
|
|
|
|
public function actionSaveRegistration(){
|
|
$result=axios_request();
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$this->wqData['storeId'];
|
|
$id=Yii::$app->session->get('memberInfo')['id'];
|
|
if($result['registrationId']){
|
|
$registraInfo=(new \yii\db\Query())
|
|
->from('{{%ybwm_registralist}}')
|
|
->where(['userId'=>$id,'registrationId'=>$result['registrationId']])->one();
|
|
if(!$registraInfo){
|
|
YII::$app->db->createCommand()->insert('{{%ybwm_registralist}}', ['registrationId'=>$result['registrationId'],'userId'=>$id,'createdAt'=>time(),'uniacid'=>$uniacid,
|
|
'storeId'=>$storeId])->execute();
|
|
}
|
|
// YII::$app->db->createCommand()->update('{{%ybwm_users}}', ['registrationId'=>$result['registrationId']],'id=:id', ['id' =>$res['id']])->execute();
|
|
}
|
|
echo json_encode(['code' => 1,'msg' => '成功']);die;
|
|
}
|
|
public function actionUpgradeInfo(){
|
|
$request = Yii::$app->request;
|
|
$result=axios_request();
|
|
$data=array(
|
|
'domain_url'=>$result['domain_url'],
|
|
'version'=>$result['version'],
|
|
'appType'=>2
|
|
);
|
|
$url=Yii::$app->params['domain_url'].'/cloud/upgraded/appUpgradeInfo';
|
|
$file_arr=httpRequest($url,$data);
|
|
echo $file_arr;die;
|
|
}
|
|
|
|
public function actionCheckDomain(){
|
|
$dominUrl=Yii::$app->request->hostInfo;
|
|
$dominUrl =preg_replace('#^(http(s?))?(://)#','', $dominUrl);
|
|
$data=array(
|
|
'domain_url'=>$dominUrl,
|
|
'auth_type'=>1,
|
|
);
|
|
$url=Yii::$app->params['domain_url'].'/cloud/auth/checkDomain';
|
|
$file_arr=httpRequest($url,$data);
|
|
echo $file_arr;die;
|
|
}
|
|
public function actionNewOrderInfo(){
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$this->wqData['storeId'];
|
|
$data=[];
|
|
$storeInfo=(new \yii\db\Query())->select('receiveStatus')->from('{{%ybwm_store}}')->where(['id'=>$storeId])->one();
|
|
//if($storeInfo['receiveStatus']==1){
|
|
$data=(new \yii\db\Query())
|
|
->select(['a.refundType','a.id','a.platformCouponPreferential','a.preferentialMoney','a.newMoney','a.deliveryPreferential','a.couponPreferential','(a.preferentialMoney+a.newMoney+a.deliveryPreferential+IFNULL(a.platformCouponPreferential,0)+IFNULL(a.couponPreferential,0)) discount','a.mealOutState','a.mealOutTime','a.selfCode','a.appointment', 'a.serviceAt','a.outTradeNo','a.takeNo','a.money','a.boxMoney','a.originMoney','a.deliveryMoney','a.receivedName','a.receivedAddress','a.receivedTel','a.lat','a.lng','a.deliveryMode','a.payMode','from_unixtime(a.createdAt)createdAt','a.num','a.state','a.userNote','a.receiptAt','b.storeActualMoney','(select count(*) from {{%ybwm_takeout_order}} d where d.state not in (1,7) and a.userId=d.userId and d.storeId='.$storeId.') as payNum','a.receivedAddress'])
|
|
->from('{{%ybwm_takeout_order}} as a')
|
|
->join('LEFT JOIN', '{{%ybwm_bill}} as b', 'b.outTradeNo = a.outTradeNo')
|
|
->where('a.uniacid=:uniacid AND a.deleteAt=0 AND a.storeId=:storeId AND a.state not in(1,7)',[':uniacid'=>$uniacid,':storeId'=>$storeId])
|
|
->andwhere(['in','a.state',[2,3]])
|
|
->orderBY('a.id desc')->one();
|
|
$goods=(new \yii\db\Query())
|
|
->from('{{%ybwm_order_goods}}')
|
|
->where('orderId=:orderId AND item=1',[':orderId'=>$data['id']])->all();
|
|
$data['goodsArr']=$goods;
|
|
//}
|
|
$data['receiveStatus']=$storeInfo['receiveStatus'];
|
|
$cacheData=json_decode(Yii::$app->cache->get('orderData'),true);
|
|
//dd($cacheData);die;
|
|
if($cacheData&&$cacheData['id']==$data['id']){
|
|
$data=[];
|
|
}else{
|
|
Yii::$app->cache->set('orderData',json_encode($data));
|
|
}
|
|
return $this->result(1,'成功',$data);
|
|
}
|
|
}
|