211 lines
9.2 KiB
PHP
211 lines
9.2 KiB
PHP
![]() |
<?php
|
||
|
namespace app\controllers\channelApi;
|
||
|
use Illuminate\Support\Facades\DB;
|
||
|
use Yii;
|
||
|
use app\models\common\Config;
|
||
|
use app\models\common\Power;
|
||
|
class PayVipController extends CommonController{
|
||
|
public $enableCsrfValidation = false;
|
||
|
function init(){
|
||
|
parent::init();
|
||
|
$power=Power::getPayPower($this->wqData['uniacid'],'payVip');
|
||
|
if(!$power){
|
||
|
echo json_encode(['code'=>2,'msg'=>'暂无权限']);die;
|
||
|
}
|
||
|
}
|
||
|
//会员下订单
|
||
|
public function actionVipOrder()
|
||
|
{
|
||
|
$request = Yii::$app->request;
|
||
|
$result=axios_request();
|
||
|
$userId=$this->wqData['userId'];
|
||
|
$uniacid=$this->wqData['uniacid'];
|
||
|
if($request->isGet){
|
||
|
return $this->result(2,'请求异常');
|
||
|
}
|
||
|
$first=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_user_vip_order}}')
|
||
|
->where('userId=:userId AND state=2',[':userId'=>$userId])->one();
|
||
|
if($first){
|
||
|
$data['first'] = 2;
|
||
|
}else{
|
||
|
$data['first'] = 1;
|
||
|
}
|
||
|
$set=Config::getSystemSet('payVip',$uniacid);
|
||
|
$dayArr=$set['dayArr'];
|
||
|
for($i=0;$i<count($dayArr);$i++){
|
||
|
if($dayArr[$i]['day']==$result['day']){
|
||
|
if($data['first']==1 AND $dayArr[$i]['first']==1){
|
||
|
$money=$dayArr[$i]['firstMoney'];
|
||
|
}else{
|
||
|
$money=$dayArr[$i]['money'];
|
||
|
}
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
if(!isset($money)){
|
||
|
return $this->result(2, '参数有误');
|
||
|
}
|
||
|
|
||
|
$data['userId'] = $userId;
|
||
|
$data['money'] = $money;
|
||
|
$data['day'] = $result['day'];
|
||
|
$data['outTradeNo'] = date("YmdHis") . rand(111111, 999999);
|
||
|
$data['state'] = 1;
|
||
|
$data['createdAt'] = time();
|
||
|
$data['uniacid'] = $uniacid;
|
||
|
|
||
|
$order = Yii::$app->db->createCommand()->insert('{{%ybwm_user_vip_order}}', $data)->execute();
|
||
|
$orderId = Yii::$app->db->getLastInsertID();
|
||
|
if ($order) {
|
||
|
return $this->result(1, '成功', $orderId);
|
||
|
} else {
|
||
|
return $this->result(2, '失败');
|
||
|
}
|
||
|
}
|
||
|
//购买记录
|
||
|
public function actionMyOrder(){
|
||
|
$userId=$this->wqData['userId'];
|
||
|
$result=axios_request();
|
||
|
$page=$result['page']?:1;
|
||
|
$size=$result['size']?:10;
|
||
|
$table=(new \yii\db\Query())
|
||
|
->select('day,money,outTradeNo')
|
||
|
->from('{{%ybwm_user_vip_order}}')
|
||
|
->where('userId=:userId AND state=2',[':userId'=>$userId]);
|
||
|
$table->offset(($page - 1) * $size)->limit($size);
|
||
|
$res=$table->orderby('id desc')->all();
|
||
|
for($i=0;$i<count($res);$i++){
|
||
|
$res[$i]['payModeName']=$this->payMode[$res[$i]['payMode']];
|
||
|
}
|
||
|
return $this->result(1, '成功', $res);
|
||
|
}
|
||
|
//权益列表
|
||
|
public function actionRightsList(){
|
||
|
$table=(new \yii\db\Query())
|
||
|
->select('id,name,icon')
|
||
|
->from('{{%ybwm_core_category}}')
|
||
|
->where(['deleteAt'=>0,'display'=>1,'uniacid'=>$this->wqData['uniacid'],'item'=>11]);
|
||
|
$list=$table
|
||
|
->orderBy('sort asc,id desc')
|
||
|
->all();
|
||
|
return $this->result(1, '成功',$list);
|
||
|
}
|
||
|
//会员详情
|
||
|
public function actionVipInfo(){
|
||
|
$uniacid=$this->wqData['uniacid'];
|
||
|
$userId=$this->wqData['userId'];
|
||
|
$user = (new \yii\db\Query())
|
||
|
->from('{{%ybwm_member}}')
|
||
|
->where('id=:id',[':id'=>$this->wqData['userId']])->one();
|
||
|
$data['vipEndTime']=$user['vipEndTime'];
|
||
|
if($user['vipEndTime']==0){
|
||
|
$data['state']=1;
|
||
|
}
|
||
|
if($user['vipEndTime']>time()){
|
||
|
$data['state']=2;
|
||
|
}
|
||
|
if($user['vipEndTime']<time() AND $user['vipEndTime']!=0){
|
||
|
$data['state']=3;
|
||
|
}
|
||
|
$payVipRebate=Config::getSystemSet('payVipRebate',$uniacid);
|
||
|
$data['payVipRebate']=$payVipRebate;
|
||
|
$payVipRebateCoupon=$payVipRebate['couponArr'];
|
||
|
$payVipRebateCouponInfo=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_coupon}}')
|
||
|
->where(['in','id',$payVipRebateCoupon])->all();
|
||
|
for($i=0;$i<count($payVipRebateCouponInfo);$i++){
|
||
|
$payVipRebateCouponInfo[$i]['explain']='';
|
||
|
if($payVipRebateCouponInfo[$i]['storeType']==1){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='单店可用,';
|
||
|
}elseif($payVipRebateCouponInfo[$i]['storeType']==2){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='全部门店可用,';
|
||
|
}else{
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='部分门店可用,';
|
||
|
}
|
||
|
if($payVipRebateCouponInfo[$i]['goodsType']==1){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='全部商品可用,';
|
||
|
}elseif($payVipRebateCouponInfo[$i]['goodsType']==2){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='指定商品可用,';
|
||
|
}elseif($payVipRebateCouponInfo[$i]['goodsType']==3){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='指定商品不可用,';
|
||
|
}else{
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='指定分类商品可用,';
|
||
|
}
|
||
|
$useType=json_decode($payVipRebateCouponInfo[$i]['useType'],true);
|
||
|
if(in_array('1',$useType)){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='外卖可用';
|
||
|
}
|
||
|
if(in_array('2',$useType)){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='堂食可用';
|
||
|
}
|
||
|
if(in_array('3',$useType)){
|
||
|
$payVipRebateCouponInfo[$i]['explain'] .='快餐可用';
|
||
|
}
|
||
|
}
|
||
|
$data['payVipRebate']['couponInfo']=$payVipRebateCouponInfo;
|
||
|
$couponMoney = (new \yii\db\Query())
|
||
|
->from('{{%ybwm_coupon}}')
|
||
|
->where(['in','id',$payVipRebateCoupon])->sum('money');
|
||
|
$payVipCycleRebate=Config::getSystemSet('payVipCycleRebate',$uniacid);
|
||
|
$data['payVipCycleRebate']=$payVipCycleRebate;
|
||
|
if($payVipCycleRebate['open']==1){
|
||
|
$payVipCycleRebateCoupon=$payVipCycleRebate['couponArr'];
|
||
|
$payVipCycleRebateCouponInfo=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_coupon}}')
|
||
|
->where(['in','id',$payVipCycleRebateCoupon])->all();
|
||
|
|
||
|
for($i=0;$i<count($payVipCycleRebateCouponInfo);$i++){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain']='';
|
||
|
if($payVipCycleRebateCouponInfo[$i]['storeType']==1){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='单店可用,';
|
||
|
}elseif($payVipCycleRebateCouponInfo[$i]['storeType']==2){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='全部门店可用,';
|
||
|
}else{
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='部分门店可用,';
|
||
|
}
|
||
|
if($payVipCycleRebateCouponInfo[$i]['goodsType']==1){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='全部商品可用,';
|
||
|
}elseif($payVipCycleRebateCouponInfo[$i]['goodsType']==2){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='指定商品可用,';
|
||
|
}elseif($payVipCycleRebateCouponInfo[$i]['goodsType']==3){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='指定商品不可用,';
|
||
|
}else{
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='指定分类商品可用,';
|
||
|
}
|
||
|
$useType=json_decode($payVipCycleRebateCouponInfo[$i]['useType'],true);
|
||
|
if(in_array('1',$useType)){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='外卖可用';
|
||
|
}
|
||
|
if(in_array('2',$useType)){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='堂食可用';
|
||
|
}
|
||
|
if(in_array('3',$useType)){
|
||
|
$payVipCycleRebateCouponInfo[$i]['explain'] .='快餐可用';
|
||
|
}
|
||
|
}
|
||
|
$data['payVipCycleRebate']['couponInfo']=$payVipCycleRebateCouponInfo;
|
||
|
|
||
|
$couponMoney += (new \yii\db\Query())
|
||
|
->from('{{%ybwm_coupon}}')
|
||
|
->where(['in','id',$payVipCycleRebateCoupon])->sum('money');
|
||
|
}
|
||
|
$data['economizeMoney']=$couponMoney?:0;
|
||
|
$data['cumulative']=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_user_coupon}}')
|
||
|
->where('userId=:userId AND receiveType=13',[':userId'=>$userId])->sum('money')?:0;//累计节省
|
||
|
$wait=(new \yii\db\Query())
|
||
|
->select('count(id) as count,sum(money) as money')
|
||
|
->from('{{%ybwm_user_coupon}}')
|
||
|
->where('userId=:userId AND receiveType=13 AND state=2 AND useEndTime>'.time(),[':userId'=>$userId])->one();
|
||
|
$data['waitNum']=$wait['count']?:0;//待使用数量
|
||
|
$data['waitMoney']=$wait['money']?:0;//可节省金额
|
||
|
$use=(new \yii\db\Query())
|
||
|
->select('count(id) as count,sum(money) as money')
|
||
|
->from('{{%ybwm_user_coupon}}')
|
||
|
->where('userId=:userId AND receiveType=13 AND state=1',[':userId'=>$userId])->one();
|
||
|
$data['alreadyNum']=$use['count']?:0;//已使用数量
|
||
|
$data['alreadyMoney']=$use['money']?:0;//已经节省金额
|
||
|
return $this->result(1, '成功',$data);
|
||
|
}
|
||
|
}
|