1129 lines
48 KiB
PHP
1129 lines
48 KiB
PHP
<?php
|
||
namespace app\controllers\channel;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Yii;
|
||
use yii\web\Controller;
|
||
use yii\web\UploadedFile;
|
||
use app\models\common\Statistics;
|
||
use app\models\common\Store;
|
||
use app\models\common\Member;
|
||
use app\models\common\Export;
|
||
use yii\db\Expression;
|
||
class MemberController extends CommonController{
|
||
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;
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
if(!$this->shop_id){
|
||
return $this->result(3,'无效的门店,请先添加商店');die;
|
||
}
|
||
}
|
||
|
||
}
|
||
//客户概况
|
||
public function actionIndex(){
|
||
//支付金额
|
||
$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;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$where=['uniacid'=>$uniacid,'deleteAt'=>0];
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
if($result['storeId']!=='all'){
|
||
$where['storeId']=$storeId;
|
||
}
|
||
//今日新增用户
|
||
$todayUser=(new \yii\db\Query())
|
||
->from('{{%ybwm_member_bind}} a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where(['a.uniacid'=>$uniacid,'a.storeId'=>$storeId])
|
||
->andwhere('a.createdAt>=:startTime AND a.createdAt<=:endTime and b.portrait is not null',['startTime'=>$beginToday,'endTime'=>$endToday])
|
||
->count();
|
||
//昨日新增用户
|
||
$yesUser=(new \yii\db\Query())
|
||
->from('{{%ybwm_member_bind}} a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where(['a.uniacid'=>$uniacid,'a.storeId'=>$storeId])
|
||
->andwhere('a.createdAt>=:startTime AND a.createdAt<=:endTime and b.portrait is not null',['startTime'=>$beginYesterday,'endTime'=>$endYesterday])
|
||
->count();
|
||
//较前一日新增用户
|
||
if($todayUser){
|
||
$deUser=round(($todayUser-$yesUser)/$todayUser*100,2);
|
||
}else{
|
||
$deUser=0;
|
||
}
|
||
//今日付费用户
|
||
$payUser=Statistics::getPayPeople($uniacid,$storeId,$beginToday,$endToday);
|
||
//昨日付费用户
|
||
$yesPayUser=Statistics::getPayPeople($uniacid,$storeId,$beginYesterday,$endYesterday);
|
||
//较前一天付费用户
|
||
if($payUser){
|
||
$dePay=round(($payUser-$yesPayUser)/$payUser*100,2);
|
||
}else{
|
||
$dePay=0;
|
||
}
|
||
//累计用户
|
||
$userSum=(new \yii\db\Query())
|
||
->from('{{%ybwm_member_bind}} a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where(['a.uniacid'=>$uniacid,'a.storeId'=>$storeId])->andWhere('b.portrait is not null')
|
||
->count();
|
||
//客单价
|
||
$userPrice=Statistics::getUnitPrice($uniacid,$storeId,$beginToday,$endToday);
|
||
$oldPrice=Statistics::getUnitPrice($uniacid,$storeId,$beginYesterday,$endYesterday);
|
||
//累计付费用户
|
||
$payUserCount=Statistics::getPayPeople($uniacid,$storeId);
|
||
//会员用户
|
||
$userCardRecordCount=(new \yii\db\Query())
|
||
->from('{{%ybwm_user_card_record}}')
|
||
->where(['uniacid'=>$uniacid])
|
||
->andWhere(['>=','createdAt',$beginToday])->andWhere(['<=','createdAt',$endToday])
|
||
->count();
|
||
$yesUserCardRecordCount=(new \yii\db\Query())
|
||
->from('{{%ybwm_user_card_record}}')
|
||
->where(['uniacid'=>$uniacid])
|
||
->andWhere(['>=','createdAt',$beginYesterday])->andWhere(['<=','createdAt',$endYesterday])
|
||
->count();
|
||
$data=array(
|
||
'todayUser'=>$todayUser,//今日新增用户
|
||
'yesUser'=>$yesUser,//昨日新增用户
|
||
'deUser'=>$deUser,//较前一日新增用户
|
||
'payUser'=>$payUser,//今日付费用户
|
||
'yesPayUser'=>$yesPayUser,//昨日付费用户
|
||
'dePay'=>$dePay,//较前一日付费用户
|
||
'userSum'=>$userSum,//累计用户
|
||
'payUserCount'=>$payUserCount,//客单价
|
||
'userPrice'=>$userPrice,//客单价
|
||
'oldPrice'=>$oldPrice,//客单价
|
||
'userCardRecordCount'=>$userCardRecordCount,
|
||
'yesUserCardRecordCount'=>$yesUserCardRecordCount,
|
||
);
|
||
foreach ($data as $k=>$v){
|
||
if(is_nan($v)||!$v){
|
||
$data[$k]=0;
|
||
}
|
||
}
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
|
||
//用户概况
|
||
public function actionGetUserData(){
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
if($result['startTime']&&$result['endTime']){
|
||
$fromTime=strtotime($result['startTime']);
|
||
$endTime=strtotime($result['endTime']);;
|
||
}else{
|
||
$fromTime=strtotime(date('Y-m-d')." 00:00:00 -14day");
|
||
$endTime=strtotime(date('Y-m-d 23:59:59',strtotime($result['endTime'])));
|
||
}
|
||
$query=(new \yii\db\Query())
|
||
->from('{{%ybwm_member_bind}} a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where(['a.uniacid'=>$uniacid,'a.storeId'=>$storeId]);
|
||
$userSum=(clone $query)->andWhere('a.createdAt<=:endTime and b.portrait is not null',[':endTime'=>$endTime])
|
||
->andWhere('a.createdAt>=:startTime',[':startTime'=>$fromTime]);
|
||
|
||
//小程序用户
|
||
$miniSum=(clone $query)->andWhere(['a.bindType'=>1])
|
||
->andWhere('a.createdAt<=:endTime and b.portrait is not null',[':endTime'=>$endTime])
|
||
->andWhere('a.createdAt>=:startTime',[':startTime'=>$fromTime])
|
||
->count();
|
||
//支付宝用户
|
||
$aliSum=(clone $query)->andWhere(['a.bindType'=>3])
|
||
->andWhere('a.createdAt<=:endTime and b.portrait is not null',[':endTime'=>$endTime])
|
||
->andWhere('a.createdAt>=:startTime',[':startTime'=>$fromTime])
|
||
->count();
|
||
//会员用户
|
||
$vipSUm=(new \yii\db\Query())
|
||
->from('{{%ybwm_user_card_record}}')->where(['uniacid'=>$uniacid])
|
||
->andWhere(['<=','createdAt',$endTime])
|
||
->andWhere(['>=','createdAt',$fromTime])
|
||
->count();
|
||
//普通用户
|
||
$userPlain=bcsub($userSum,$vipSUm);
|
||
//付费用户
|
||
$all= (new \yii\db\Query())
|
||
->select('count(id) as count')
|
||
->from('{{%ybwm_user_vip_order}}')
|
||
->where('uniacid=:uniacid AND state=2',[':uniacid'=>$uniacid])->andWhere('payAt>=:startTime AND payAt<=:endTime',[':startTime'=>$fromTime,':endTime'=>$endTime])->one();
|
||
$vipNum=$all['count']?:0;//总数量
|
||
//未付费用户
|
||
$noPayNum=bcsub($userSum,$vipNum);
|
||
//用户总览
|
||
//新增用户char
|
||
$newUserChar= (new \yii\db\Query())
|
||
->select(new Expression("from_unixtime(a.createdAt,'%Y-%m-%d') as hours,count(*)money"))
|
||
->from('{{%ybwm_member_bind}} a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where(['a.deleteAt' => 0,'a.uniacid'=>$uniacid,'a.storeId'=>$storeId])
|
||
->andWhere('a.createdAt>=:starTime AND a.createdAt<=:endTime and b.portrait is not null',[':starTime'=>$fromTime,':endTime'=>$endTime])
|
||
->groupBy(new Expression("from_unixtime(a.createdAt,'%Y-%m-%d')"))
|
||
->all();
|
||
|
||
$userChar=dataByTime($newUserChar,$result['endTime']);
|
||
//var_dump($userChar);die;
|
||
|
||
|
||
//付费用户char
|
||
$OrderChar= (new \yii\db\Query())
|
||
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,count(DISTINCT userId)money"))
|
||
->from('{{%ybwm_bill}}')
|
||
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
|
||
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$fromTime,':endTime'=>$endTime])
|
||
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
||
->all();
|
||
//var_dump($OrderChar);die;
|
||
$OrderChar=dataByTime($OrderChar,$result['endTime']);
|
||
$data=array(
|
||
'miniSum'=>$miniSum,
|
||
'userChar'=>$userChar,
|
||
'aliSum'=>$aliSum,
|
||
'vipSUm'=>$vipSUm,
|
||
'userPlain'=>$userPlain,
|
||
'vipNum'=>$vipNum,
|
||
'noPayNum'=>$noPayNum,
|
||
'OrderChar'=>$OrderChar
|
||
);
|
||
|
||
foreach ($data as $k=>$v){
|
||
if(is_nan($v)||!$v||$v==-INF){
|
||
$data[$k]=0;
|
||
}
|
||
}
|
||
//dd($data);die;
|
||
//dd(json_encode($data));die;
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
//客户列表
|
||
public function actionGetMemberList(){
|
||
$result=axios_request();
|
||
$keyword=trim($result['keyword']);
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
$page=$result['page']?:1;
|
||
$num=($page-1)*10;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$limit=10;
|
||
$sql="SELECT
|
||
`b`.`id`,
|
||
`b`.`openId`,
|
||
`b`.`status`,
|
||
`b`.`userName`,
|
||
`b`.`level`,
|
||
`b`.`userTel`,
|
||
`b`.`portrait`,
|
||
IFNULL(`b`.`balance`, 0)balance,
|
||
IFNULL(`b`.`integral`,0)integral,
|
||
`b`.`isBlack`,
|
||
`b`.`bindType`,
|
||
from_unixtime(b.createdAt) createdAt,
|
||
(select IFNULL(sum(money),0) from {{%ybwm_bill}} c where c.userId=b.id and c.storeId=$storeId and uniacid=$uniacid and refundMoney is null)payMoney,
|
||
(select IFNULL(count(*),0) from {{%ybwm_bill}} c where c.userId=b.id and c.storeId=$storeId and uniacid=$uniacid and (refundMoney=0 or refundMoney is null))payNum,
|
||
a.vipLabel
|
||
FROM
|
||
{{%ybwm_member_bind}} `a`
|
||
left join {{%ybwm_member}} `b` on a.userId=b.id
|
||
WHERE
|
||
a.uniacid = $uniacid and storeId=$storeId
|
||
AND b.portrait IS NOT NULL";
|
||
|
||
if($result['vipLabel']){
|
||
$sql.=" and a.vipLabel=".$result['vipLabel'];
|
||
}
|
||
if($result['isBlack']){
|
||
$sql.=" and b.isBlack=".$result['isBlack'];
|
||
}
|
||
if($result['userChannel']){
|
||
$sql.=" and b.bindType=".$result['userChannel'];
|
||
}
|
||
if($result['startTime']&&$result['endTime']){
|
||
$sql.=" and a.createdAt>=".strtotime($result['startTime'])." and a.createdAt<=".strtotime($result['endTime']);
|
||
}
|
||
|
||
if($keyword){
|
||
$sql.=" and (b.userName like '%$keyword%' or b.userTel like '%$keyword%' or b.realName like '%$keyword%')";
|
||
}
|
||
|
||
if($result['idArr']){
|
||
$sql.=" and a.id not in (".implode(",",$result['idArr']).")";
|
||
}
|
||
|
||
$row=Yii::$app->db->createCommand($sql." group by a.id")->queryAll();
|
||
if($result['export']==1){
|
||
Export::UserExport($row);
|
||
}
|
||
$count=count($row);
|
||
$sql.=" group by a.userId order by a.userId desc limit $num,$limit";
|
||
|
||
$res=Yii::$app->db->createCommand($sql)->queryAll();
|
||
|
||
return $this->result(1,'成功',$res,$count);
|
||
|
||
}
|
||
//拉黑,删除会员
|
||
public function actionChangeStatus(){
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
if(is_array($result['id'])){
|
||
$id=$result['id'];
|
||
}else{
|
||
$id=[$result['id']];
|
||
}
|
||
if($result['isBlack']){
|
||
//拉黑
|
||
$res = YII::$app->db->createCommand()->update('{{%ybwm_member}}', ['isBlack'=>$result['isBlack']], ['in','id',$id])->execute();
|
||
}
|
||
if($result['status']==1){
|
||
//删除
|
||
YII::$app->db->createCommand()->delete('{{%ybwm_member}}',['in','id',$id])->execute();
|
||
YII::$app->db->createCommand()->delete('{{%ybwm_member_bind}}',['in','userId',$id])->execute();
|
||
}
|
||
return $this->result(1,'成功');
|
||
}
|
||
}
|
||
//批量修改余额,积分
|
||
public function actionChangeInfo(){
|
||
$result=axios_request();
|
||
$request = Yii::$app->request;
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$note=$result['note'];
|
||
$type=$result['type'];
|
||
$id=$result['id'];
|
||
$changeIntegral=$result['integral'];
|
||
$changeBalance=$result['balance'];
|
||
$user=(new \yii\db\Query())
|
||
->select('balance,integral')
|
||
->from('{{%ybwm_member}}')->where(['id'=>$id])->one();
|
||
if($request->isPost){
|
||
if($result['balance']){
|
||
if($type==3){
|
||
if($user['balance']>$result['balance']){
|
||
$changeBalance=bcsub($user['balance'],$result['balance'],2);
|
||
$type=2;
|
||
}
|
||
if($user['balance']<$result['balance']){
|
||
$type=1;
|
||
$changeBalance=bcsub($result['balance'],$user['balance'],2);
|
||
}
|
||
}
|
||
//修改余额
|
||
Member::saveBalance($id,1,$changeBalance,$type,$note,$uniacid,$this->userData['id']);
|
||
}
|
||
if($result['integral']){
|
||
if($type==3){
|
||
if($user['integral']>$result['integral']){
|
||
$changeIntegral=bcsub($user['integral'],$result['integral'],2);
|
||
$type=2;
|
||
}
|
||
if($user['integral']<$result['integral']){
|
||
$type=1;
|
||
$changeIntegral=bcsub($result['integral'],$user['integral'],2);
|
||
}
|
||
}
|
||
Member::saveIntegral($id,1,$changeIntegral,$type,$note,$uniacid,'',$this->userData['id']);
|
||
//修改积分
|
||
}
|
||
return $this->result(1,'成功');
|
||
|
||
}
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
//用户详情
|
||
public function actionGetMemberInfo(){
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$userId=$result['id'];
|
||
$data=(new \yii\db\Query())
|
||
->select(['level','id','portrait','realName','userName','userTel','balance','integral',
|
||
'from_unixtime(createdAt) createdAt','openId','from_unixtime(birthday) birthday','growth',
|
||
'level','(select IFNULL(count(*),0) from {{%ybwm_user_coupon}} where userId='.$userId.' and storeId='.$storeId.' and state=2)cardNum'])
|
||
->from('{{%ybwm_member}}')
|
||
->where(['id'=>$userId])
|
||
->one();
|
||
$data['level']=$data['level']?:'';
|
||
$userBind=(new \yii\db\Query())
|
||
->from('{{%ybwm_member_bind}}')
|
||
->where('userId=:userId AND storeId=:storeId AND uniacid=:uniacid',[':userId'=>$result['id'],':storeId'=>$storeId,'uniacid'=>$uniacid])->one();
|
||
//var_dump(ddSql($userBind));die;
|
||
$data['vipLabel']=$userBind['vipLabel']?:'';
|
||
$data['balance']=$userBind['balance']?:0;
|
||
$data['integral']=$userBind['integral']?:0;
|
||
$money=(new \yii\db\Query())
|
||
->from('{{%ybwm_bill}}')
|
||
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'userId'=>$result['id']])
|
||
->andWhere('refundMoney=0 or refundMoney is null')
|
||
->sum('money');
|
||
$count=(new \yii\db\Query())
|
||
->from('{{%ybwm_bill}}')
|
||
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'userId'=>$result['id']])
|
||
->andWhere('refundMoney=0 or refundMoney is null')
|
||
->count();
|
||
// $weicount=(new \yii\db\Query())
|
||
// ->from('{{%ybwm_takeout_order}}')
|
||
// ->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'userId'=>$result['id']])
|
||
// ->andWhere('refundMoney>0')
|
||
// ->count();
|
||
$reund=(new \yii\db\Query())
|
||
->select('sum(refundMoney) as money,count(id) as count')
|
||
->from('{{%ybwm_bill}}')
|
||
->where(['uniacid'=>$uniacid,'storeId'=>$storeId,'userId'=>$result['id']])
|
||
->andWhere('refundMoney>0')
|
||
->one();
|
||
$data['money']=$money;
|
||
$data['count']=$count;
|
||
$data['weicount']=$reund['count'];
|
||
$data['reundcount']=$reund['money'];
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
return $this->result(2,'请求异常');
|
||
}
|
||
//单个用户信息保存
|
||
public function actionMemberInfoSave(){
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
$data=array(
|
||
'realName'=>$result['realName'],
|
||
'userTel'=>$result['userTel'],
|
||
'level'=>$result['level'],
|
||
'birthday'=>strtotime($result['birthday']),
|
||
);
|
||
$data=filter_array($data);
|
||
if($data){
|
||
$res=YII::$app->db->createCommand()->update('{{%ybwm_member}}',$data, 'id=:id', [':id' =>$result['id']])->execute();
|
||
}
|
||
|
||
$vipData=array(
|
||
'vipLabel'=>$result['vipLabel'],
|
||
);
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
if($vipData){
|
||
YII::$app->db->createCommand()->update('{{%ybwm_member_bind}}',$vipData, 'userId=:userId and storeId=:storeId and uniacid=:uniacid', [':uniacid'=>$this->wqData['uniacid'],':userId' =>$result['id'],':storeId'=>$storeId])->execute();
|
||
}
|
||
return $this->result(1,'成功');
|
||
}
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
//会员标签保存修改
|
||
public function actionMemberLabelSave(){
|
||
$result=axios_request();
|
||
$request = Yii::$app->request;
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
$data=array(
|
||
'labelName'=>$result['labelName'],
|
||
'sort'=>$result['sort'],
|
||
'uniacid'=>$this->wqData['uniacid'],
|
||
'storeId'=>$storeId,
|
||
'display'=>1
|
||
);
|
||
if($result['id']){
|
||
$res = YII::$app->db->createCommand()->update('{{%ybwm_member_label}}',$data, ['id'=>$result['id']])->execute();
|
||
}else{
|
||
$data['createdAt']=time();
|
||
$res = YII::$app->db->createCommand()->insert('{{%ybwm_member_label}}',$data)->execute();
|
||
}
|
||
if($res!==false){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
|
||
}
|
||
}
|
||
//会员标签列表
|
||
public function actionGetMemberLabel(){
|
||
$request = Yii::$app->request;
|
||
if ($request->isGet){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?:$this->shop_id;
|
||
$data=(new \yii\db\Query())
|
||
->from('{{%ybwm_member_label}}')
|
||
->where(['status'=>1,'deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId])
|
||
->orderBy('sort asc')
|
||
->all();
|
||
}
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
//修改客户标签/删除客户标签
|
||
public function actionChangeMemberLabel(){
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
$id=$result['id'];
|
||
if($result['status']){
|
||
//删除
|
||
$res = YII::$app->db->createCommand()->update('{{%ybwm_member_label}}', ['status'=>2,'deleteAt'=>time()], ['id'=>$id])->execute();
|
||
}
|
||
if($result['display']){
|
||
//修改状态
|
||
$res = YII::$app->db->createCommand()->update('{{%ybwm_member_label}}', ['display'=>$result['display']], ['id'=>$id])->execute();
|
||
}
|
||
if($res!==false){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
}
|
||
|
||
public function actionMemberInput(){
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
|
||
$file = UploadedFile::getInstanceByName('file'); //获取上传的文件实例
|
||
|
||
if($file->type== 'application/vnd.ms-excel') {
|
||
$excelFile = $file->tempName;//获取文件名
|
||
//这里就是导入PHPExcel包了,要用的时候就加这么两句,方便吧
|
||
// Yii::$enableIncludePath = false;
|
||
// Yii::import('application.extensions.PHPExcel.PHPExcel', 1);
|
||
// $phpexcel = new PHPExcel;
|
||
$excelReader = \PHPExcel_IOFactory::createReader('Excel5');
|
||
$phpexcel = $excelReader->load($excelFile)->getSheet(0);//载入文件并获取第一个sheet
|
||
|
||
$total_line = $phpexcel->getHighestRow();
|
||
|
||
$total_column = $phpexcel->getHighestColumn();
|
||
var_dump($total_line);var_dump($total_column);die;
|
||
$arr=[];
|
||
for ($row = 2; $row <= $total_line; $row++) {
|
||
$data = array();
|
||
|
||
for ($column = 'A'; $column <= $total_column; $column++){
|
||
if(strlen($column.$row)==2){
|
||
$data[] = trim($phpexcel->getCell($column.$row)->getValue());
|
||
}
|
||
|
||
|
||
}
|
||
$arr=[];
|
||
$arr=array(
|
||
'openId'=>$data[0],
|
||
'userName'=>$data[1],
|
||
'realName'=>$data[2],
|
||
'rankId'=>$data[6],
|
||
'birthday'=>strtotime($data[7]),
|
||
'userTel'=>$data[3],
|
||
'sex'=>$data['sex'],
|
||
'sourceType'=>2,
|
||
'createdAt'=>time(),
|
||
'uniacid'=>$this->wqData['uniacid'],
|
||
'balance'=>$data[4],
|
||
'integral'=>$data[5],
|
||
'vipLabel'=>$result['vipLabel'],
|
||
);
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
$info=Yii::$app->db->createCommand()->insert('{{%ybwm_member}}', $arr)->execute();
|
||
$id=Yii::$app->db->getLastInsertID();
|
||
$newArr['createdAt']=time();
|
||
$newArr['uniacid']=$this->wqData['uniacid'];
|
||
$newArr['storeId']=$storeId;
|
||
$newArr['sourceType']=2;
|
||
$newArr['userId']=$id;
|
||
$newArr['vipLabel']=$result['vipLabel'];
|
||
//一行行的插入数据库操作
|
||
$infos=Yii::$app->db->createCommand()->insert('{{%ybwm_member_bind}}', $newArr)->execute();
|
||
if ($info&&$infos) {
|
||
$ok = 1;
|
||
}else{
|
||
$ok = 0;
|
||
}
|
||
}
|
||
}
|
||
if($ok){
|
||
echo json_encode(['code'=>1,'msg'=>'会员信息录入成功']);die;
|
||
}else{
|
||
echo json_encode(['code'=>2,'msg'=>'网络异常,请稍后再试']);die;
|
||
}
|
||
}
|
||
}
|
||
|
||
//客户导入记录
|
||
public function actionMemberExcelList(){
|
||
$request = Yii::$app->request;
|
||
if ($request->isGet){
|
||
$result=axios_request();
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
$data=(new \yii\db\Query())
|
||
->from('{{%ybwm_member_bind}}')
|
||
->select('count(*)count,from_unixtime(max(createdAt))time')
|
||
->where(['sourceType'=>2,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId])
|
||
->orderBy('id desc')
|
||
->all();
|
||
return $this->result(1,'成功',$data);
|
||
}
|
||
}
|
||
|
||
//下载上传示例
|
||
public function actionExcelDown(){
|
||
header('Content-Disposition: attachment; filename=会员信息录入.xls');
|
||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||
header('Content-Length: '.filesize('./web/会员信息录入.xls'));
|
||
header('Content-Transfer-Encoding: binary');
|
||
header('Cache-Control: must-revalidate');
|
||
header('Pragma: public');
|
||
readfile('./web/会员信息录入.xls');
|
||
}
|
||
|
||
|
||
|
||
//------------------------储值设置部分-------------------------------------------------------
|
||
public function actionGetDepositOrder(){
|
||
$result=axios_request();
|
||
$page = Yii::$app->request->get('page') ? Yii::$app->request->get('page') : 1;
|
||
$num = ($page - 1) * 10;
|
||
$limit = 10;
|
||
$keyword=trim($result['keyword']);
|
||
$where=array(
|
||
'a.uniacid'=>$this->wqData['uniacid'],
|
||
'a.state'=>2
|
||
);
|
||
|
||
$table = (new \yii\db\Query())
|
||
->select('a.id,a.userId,b.userName,b.bindType,b.portrait,a.money,a.giveMoney,a.giveGrow,a.giveScore,from_unixtime(a.createdAt)createdAt,a.outTradeNo,a.num')
|
||
->from('{{%ybwm_user_balance_order}} as a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where($where);
|
||
if($keyword){
|
||
$table->andWhere(['or', ['like', 'userName', $keyword], ['like', 'userTel', $keyword], ['like', 'realName', $keyword]]);
|
||
}
|
||
if($result['startTime']&&$result['endTime']){
|
||
$table->andWhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',[':startTime'=>$result['startTime'],':endTime'=>$result['endTime']]);
|
||
}
|
||
if($result['export']==1){
|
||
Export::RechargeExport($table->all());
|
||
}
|
||
$re =$table->offset($num)
|
||
->limit($limit)
|
||
->orderBy('id desc')
|
||
->all();
|
||
for($i=0;$i<count($re);$i++){
|
||
$re[$i]['num']=0;
|
||
if($re[$i]['couponId']){
|
||
$couponId=json_decode($re[$i]['couponId'],true);
|
||
$re[$i]['num']=count($couponId)?:0;
|
||
}
|
||
}
|
||
$count=$table->count();
|
||
return $this->result(1,'成功',$re,$count);
|
||
}
|
||
|
||
public function actionDepositSave(){
|
||
$result=axios_request();
|
||
$request = Yii::$app->request;
|
||
if($request->isGet){
|
||
$info=(new \yii\db\Query())
|
||
->from('{{%ybwm_user_wallet}}')
|
||
->where('id=:id',[':id'=>$result['id']])->one();
|
||
$info['couponId']=json_decode($info['couponId'],true);
|
||
return $this->result(1, '成功',$info);
|
||
}
|
||
if(!$result['name']){
|
||
return $this->result(2,'名称不能为空!');
|
||
}
|
||
if(!$result['money']){
|
||
return $this->result(2,'金额不能为空!');
|
||
}
|
||
$data=array(
|
||
'sort'=>$result['sort'],
|
||
'name'=>$result['name'],
|
||
'uniacid'=>$this->wqData['uniacid'],
|
||
'money'=>$result['money'],
|
||
'giveMoney'=>$result['giveMoney'],
|
||
'integral'=>$result['integral'],
|
||
'giveGrow'=>$result['giveGrow'],
|
||
'moneyOpen'=>$result['moneyOpen'],
|
||
'integralOpen'=>$result['integralOpen'],
|
||
'couponOpen'=>$result['couponOpen'],
|
||
'growOpen'=>$result['growOpen'],
|
||
'couponId'=>json_encode($result['couponId']),
|
||
);
|
||
if($result['id']){
|
||
$data['changeAt']=time();
|
||
$re = Yii::$app->db->createCommand()->update('{{%ybwm_user_wallet}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
||
}else{
|
||
$data['uniacid']=$this->wqData['uniacid'];
|
||
$data['createdAt']=time();
|
||
// print_R($data);die;
|
||
$re = Yii::$app->db->createCommand()->insert('{{%ybwm_user_wallet}}', $data)->execute();
|
||
|
||
}
|
||
if($re){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
//储值规则列表
|
||
public function actionGetDepositList(){
|
||
$page = Yii::$app->request->get('page') ? Yii::$app->request->get('page') : 1;
|
||
$num = ($page - 1) * 10;
|
||
$limit = 10;
|
||
$re = (new \yii\db\Query())
|
||
->select('id, sort,name,money,giveMoney,integral,number,giveGrow,display,moneyOpen,integralOpen,couponOpen,growOpen')
|
||
->from('{{%ybwm_user_wallet}}')
|
||
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid']])
|
||
->offset($num)
|
||
->limit($limit)
|
||
->all();
|
||
for($i=0;$i<count($re);$i++){
|
||
$re[$i]['number']=(new \yii\db\Query())
|
||
->from('{{%ybwm_user_balance_order}}')
|
||
->where('giveId=:giveId AND state=2',['giveId'=>$re[$i]['id']])
|
||
->count();
|
||
}
|
||
return $this->result(1,'成功',$re);
|
||
|
||
}
|
||
//修改充值规则
|
||
public function actionModifyDeposit(){
|
||
$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_user_wallet}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
||
if($res){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
//充值统计
|
||
public function actionRechargeStatistics(){
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$startTime=strtotime(date("Y-m-d")." 00:00:00");
|
||
$endTime=strtotime(date("Y-m-d")." 23:59:59");
|
||
$table=(new \yii\db\Query())
|
||
->select('sum(money) money,sum(giveMoney) giveMoney')
|
||
->from('{{%ybwm_user_balance_order}}');
|
||
$allMoney=$table->where('uniacid=:uniacid AND state=2',[':uniacid'=>$uniacid])->one();//累计充值金额
|
||
$todayMoney=$table->where('uniacid=:uniacid AND state=2 AND payAt>=:startTime AND payAt<=:endTime',[':startTime'=>$startTime,':endTime'=>$endTime,':uniacid'=>$uniacid])
|
||
->one();//今日充值金额
|
||
$people=(new \yii\db\Query())
|
||
->select('sum(money) money,sum(giveMoney) giveMoney')
|
||
->from('{{%ybwm_user_balance_order}}');
|
||
$data['people']=$people->where('uniacid=:uniacid AND state=2',[':uniacid'=>$uniacid])
|
||
->groupBy('userId')->count();//累计充值人数
|
||
$yesterdayPeople=$people->where('uniacid=:uniacid AND state=2 AND payAt<=:endTime',[':endTime'=>$endTime-86400,':uniacid'=>$uniacid])
|
||
->groupBy('userId')->count();//截止昨天充值人数
|
||
$data['surplus']=(new \yii\db\Query())
|
||
->from('{{%ybwm_member}}')
|
||
->where('uniacid=:uniacid',[':uniacid'=>$uniacid])
|
||
->sum('balance');//剩余余额
|
||
$data['consume']=(new \yii\db\Query())
|
||
->from('{{%ybwm_user_balance}}')
|
||
->where('uniacid=:uniacid AND type=2 AND origin=2 AND createdAt>=:startTime AND createdAt<=:endTime',[':startTime'=>$startTime,':endTime'=>$endTime,':uniacid'=>$uniacid])
|
||
->sum('money')?:0;//消耗余额
|
||
$data['comparePeople']=bcsub($data['people'],$yesterdayPeople,0);//今天较昨天
|
||
$data['todayMoney']=$todayMoney['money']?:0;//今日充值金额
|
||
$data['todayGiveMoney']=$todayMoney['giveMoney']?:0;//今日赠送金额
|
||
$data['allMoney']=$allMoney['money'];//累计赠送金额
|
||
$data['allGiveMoney']=$allMoney['giveMoney'];//累计赠送金额
|
||
return $this->result(1,'成功',$data);
|
||
|
||
|
||
|
||
}
|
||
//---------------------------------积分部分-------------------------------
|
||
//积分列表查询
|
||
public function actionGetIntegralList(){
|
||
$request = Yii::$app->request;
|
||
if ($request->isGet){
|
||
$result=axios_request();
|
||
$page = Yii::$app->request->get('page') ? Yii::$app->request->get('page') : 1;
|
||
$num = ($page - 1) * 10;
|
||
$limit = 10;
|
||
$keyword=trim($result['keyword']);
|
||
$where=array(
|
||
'a.uniacid'=>$this->wqData['uniacid']
|
||
);
|
||
if($keyword){
|
||
$where[]=['or', ['like', 'userName', $keyword], ['like', 'userTel', $keyword], ['like', 'realName', $keyword]];
|
||
}
|
||
if($result['startTime']&&$result['endTime']){
|
||
$where[]=['>=','a.createdAt',$result['startTime']];
|
||
$where[]=['<=','a.createdAt',$result['endTime']];
|
||
}
|
||
$re = (new \yii\db\Query())
|
||
->select('a.id,b.userName,b.bindType,a.integral,a.type,a.note,b.integral,from_unixtime(a.createdAt)createdAt')
|
||
->from('{{%ybwm_user_integral}} as a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where($where)
|
||
->offset($num)
|
||
->limit($limit)
|
||
->all();
|
||
return $this->result(1,'成功',$re);
|
||
}
|
||
}
|
||
//获取积分设置信息
|
||
public function actionGetIntegralInfo(){
|
||
$request = Yii::$app->request;
|
||
if ($request->isGet){
|
||
$re = (new \yii\db\Query())
|
||
->from('{{%ybwm_core_system}}')
|
||
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'ident'=>'integral'])
|
||
->one();
|
||
return $this->result(1,'成功',$re);
|
||
}
|
||
}
|
||
//积分设置
|
||
public function actionIntegralSet(){
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
$data=array(
|
||
'data'=>json_encode(array(
|
||
'IntegralName'=>$result['IntegralName'],
|
||
'rewardType'=>$result['rewardType'],
|
||
'IntegralReward'=>$result['IntegralReward'],
|
||
'ratio'=>$result['ratio'],
|
||
'commentReward'=>$result['commentReward'],
|
||
)),
|
||
'ident'=>'integral',
|
||
'uniacid'=>$this->wqData['uniacid']
|
||
);
|
||
if($result['id']){
|
||
$data['changeAt']=time();
|
||
$res = YII::$app->db->createCommand()->update('{{%ybwm_core_system}}',$data, ['id'=>$result['id']])->execute();
|
||
}else{
|
||
$data['createdAt']=time();
|
||
$res = YII::$app->db->createCommand()->insert('{{%ybwm_core_system}}',$data)->execute();
|
||
}
|
||
if($res!==false){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//---------------------客户设置
|
||
public function actionMemberSet(){
|
||
$request = Yii::$app->request;
|
||
if($request->isPost){
|
||
$result=axios_request();
|
||
$data=array(
|
||
'data'=>json_encode(array(
|
||
'payType'=>$result['payType'],
|
||
'loginType'=>$result['loginType'],
|
||
)),
|
||
'ident'=>'member',
|
||
'uniacid'=>$this->wqData['uniacid']
|
||
);
|
||
if($result['id']){
|
||
$data['changeAt']=time();
|
||
$res = YII::$app->db->createCommand()->update('{{%ybwm_core_system}}',$data, ['id'=>$result['id']])->execute();
|
||
}else{
|
||
$data['createdAt']=time();
|
||
$res = YII::$app->db->createCommand()->insert('{{%ybwm_core_system}}',$data)->execute();
|
||
}
|
||
if($res!==false){
|
||
return $this->result(1,'成功');
|
||
}else{
|
||
return $this->result(2,'网络异常,请稍后再试');
|
||
}
|
||
}
|
||
}
|
||
//获取客户下单登陆设置手机必须设置
|
||
public function actionGetMemberSetInfo(){
|
||
$request = Yii::$app->request;
|
||
$re = (new \yii\db\Query())
|
||
->from('{{%ybwm_core_system}}')
|
||
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'ident'=>'member'])
|
||
->one();
|
||
$re['payType']=json_decode($re['data'],true)['payType'];
|
||
$re['loginType']=json_decode($re['data'],true)['loginType'];
|
||
unset($re['data']);
|
||
return $this->result(1,'成功',$re);
|
||
}
|
||
//余额明细
|
||
public function actionBalanceDetailed(){
|
||
$result=axios_request();
|
||
$page = $result['page'] ?: 1;
|
||
$num = ($page - 1) * 10;
|
||
$limit = 10;
|
||
$keyword=trim($result['keyword']);
|
||
$where=array(
|
||
'a.uniacid'=>$this->wqData['uniacid']
|
||
);
|
||
|
||
$table = (new \yii\db\Query())
|
||
->select('a.id,a.userId,b.portrait,b.userName,a.money,a.type,a.note,b.balance,from_unixtime(a.createdAt)createdAt')
|
||
->from('{{%ybwm_user_balance}} as a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where($where);
|
||
if($keyword){
|
||
$table->andWhere(['or', ['like', 'userName', $keyword], ['like', 'userTel', $keyword], ['like', 'realName', $keyword]]);
|
||
}
|
||
if($result['startTime']&&$result['endTime']){
|
||
$table->andWhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',[':startTime'=>strtotime($result['startTime']),':endTime'=>strtotime($result['endTime'])]);
|
||
}
|
||
$count=$table->count();
|
||
$res=$table->offset($num)
|
||
->limit($limit)
|
||
->orderBy('id desc')->all();
|
||
return $this->result(1,'成功',$res,$count);
|
||
}
|
||
//积分明细
|
||
public function actionIntegralDetailed(){
|
||
$result=axios_request();
|
||
$page = $result['page']?: 1;
|
||
$num = ($page - 1) * 10;
|
||
$limit = 10;
|
||
$keyword=trim($result['keyword']);
|
||
$where=array(
|
||
'a.uniacid'=>$this->wqData['uniacid']
|
||
);
|
||
|
||
$table = (new \yii\db\Query())
|
||
->select('a.id,a.userId,b.portrait,b.userName,a.integral,a.type,a.note,b.integral as userIntegral,from_unixtime(a.createdAt)createdAt')
|
||
->from('{{%ybwm_user_integral}} as a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where($where);
|
||
if($keyword){
|
||
$table->andWhere(['or', ['like', 'userName', $keyword], ['like', 'userTel', $keyword], ['like', 'realName', $keyword]]);
|
||
}
|
||
if($result['startTime']&&$result['endTime']){
|
||
$table->andWhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',[':startTime'=>strtotime($result['startTime']),':endTime'=>strtotime($result['endTime'])]);
|
||
}
|
||
$count=$table->count();
|
||
$res=$table->offset($num)
|
||
->limit($limit)
|
||
->orderBy('id desc')
|
||
->all();
|
||
return $this->result(1,'成功',$res,$count);
|
||
}
|
||
|
||
//审核提现
|
||
public function actionModifyWithdrawal(){
|
||
$post=axios_request();
|
||
$finance=(new \yii\db\Query())
|
||
->from('{{%ybwm_bonus_withdrawal}}')
|
||
->where(['id'=>$post['id']])->one();
|
||
if(!$finance || $finance['state']!=1){
|
||
return $this->result(2,'数据异常');
|
||
}
|
||
$type=$post['type'];
|
||
if($type=='makeAdopt' AND $finance['type']==1){
|
||
$user=(new \yii\db\Query())
|
||
->select('openId')
|
||
->from('{{%ybwm_member}}')
|
||
->where(['id'=>$finance['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;
|
||
}
|
||
$transaction = Yii::$app->db->beginTransaction(); //开始事务
|
||
$res = Yii::$app->db->createCommand()->update('{{%ybwm_bonus_withdrawal}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
||
if(!$res){
|
||
$transaction->rollBack();
|
||
return $this->result(2,'失败');
|
||
}
|
||
if($type=='adopt' AND $finance['type']==4){
|
||
if($finance['item']==1){
|
||
$balance=Member::saveBalance($finance['userId'], 2, $finance['actualMoney'], 1, '奖励金提现', $finance['uniacid']);
|
||
}else{
|
||
$balance=Member::saveBalance($finance['userId'], 2, $finance['actualMoney'], 1, '分销佣金提现', $finance['uniacid']);
|
||
}
|
||
|
||
if(!$balance){
|
||
$transaction->rollBack();
|
||
return $this->result(2,'失败');
|
||
}
|
||
}
|
||
if ($type == 'reject') {
|
||
if($finance['item']==1) {
|
||
$userRes = Member::saveBonus($finance['userId'], 2, $finance['money'], 1, '奖励金提现拒绝', $finance['uniacid']);
|
||
}else{
|
||
$userRes = Member::saveBonus($finance['userId'], 2, $finance['money'], 1, '分销佣金提现拒绝', $finance['uniacid'],2);
|
||
}
|
||
if(!$userRes){
|
||
$transaction->rollBack();
|
||
return $this->result(2,'失败');
|
||
}
|
||
}
|
||
$transaction->commit();
|
||
return $this->result(1,'成功');
|
||
}
|
||
//提现列表
|
||
public function actionWithdrawalList(){
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$item=$result['item'];
|
||
$userId=$result['userId'];
|
||
$page=$result['page']?:1;
|
||
$num=($page-1)*10;
|
||
$limit=10;
|
||
$state=$result['state'];
|
||
$startTime=strtotime($result['startTime']);
|
||
$endTime=strtotime($result['endTime']);
|
||
$table=(new \yii\db\Query())
|
||
->select('a.*,b.userName,b.portrait')
|
||
->from('{{%ybwm_bonus_withdrawal}} as a')
|
||
->leftJoin('{{%ybwm_member}} as b', 'a.userId = b.id')
|
||
->where(['a.uniacid'=>$uniacid,'a.item'=>$item]);
|
||
if($state){
|
||
$table->andWhere('a.state='.$state);
|
||
}
|
||
if($userId){
|
||
$table->andWhere('a.userId='.$userId);
|
||
}
|
||
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]['createdAt']=date("Y-m-d H:i:s",$list[$i]['createdAt']);
|
||
}
|
||
return $this->result(1, '成功',$list,$count);
|
||
}
|
||
|
||
|
||
//获取用户的优惠券详情
|
||
public function actionGetCouponList(){
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
$userId=$result['userId'];
|
||
$state=$result['state']?:2;
|
||
$page = Yii::$app->request->get('page') ? Yii::$app->request->get('page') : 1;
|
||
$data=Member::couponList($userId,$storeId,$page,$state);
|
||
return $this->result(1, '成功',$data['data'],$data['count']);
|
||
}
|
||
|
||
|
||
public function actionStoreCouponList(){
|
||
$result=axios_request();
|
||
$keyword=$result['keyword'];
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
$page = Yii::$app->request->get('page') ? Yii::$app->request->get('page') : 1;
|
||
$data=Member::storeCoupon($storeId,$keyword,$page);
|
||
return $this->result(1, '成功',$data['data'],$data['count']);
|
||
}
|
||
|
||
public function actionSendCoupon(){
|
||
$result=axios_request();
|
||
$uniacid=$this->wqData['uniacid'];
|
||
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
||
$userId=$result['userId'];
|
||
$couponId=$result['couponId'];
|
||
if(!$couponId||!$userId){
|
||
echo json_encode(['code'=>2,'msg'=>'参数确实优惠券Id或用户Id']);die;
|
||
}
|
||
$transaction = Yii::$app->db->beginTransaction(); //开始事务
|
||
try{
|
||
if(is_array($couponId)){
|
||
$couponRes=(new \yii\db\Query())
|
||
->from('{{%ybwm_coupon}}')->where(['in','id',$couponId])->all();
|
||
foreach ($couponRes as &$v){
|
||
$data=[];
|
||
$data=array(
|
||
'userId'=>$userId,
|
||
'couponId'=>$v['id'],
|
||
'type'=>$v['type'],
|
||
'couponName'=>$v['name'],
|
||
'couponDetails'=>$v['details'],
|
||
'money'=>$v['money']?:0.00,
|
||
'fullMoney'=>$v['fullMoney'],
|
||
'discount'=>$v['discount'],
|
||
'useType'=>$v['useType'],
|
||
'storeType'=>$v['storeType'],
|
||
'storeArr'=>$v['storeArr'],
|
||
'goodsType'=>$v['goodsType'],
|
||
'goodsArr'=>$v['goodsArr'],
|
||
'state'=>2,
|
||
'uniacid'=>$uniacid,
|
||
'createdAt'=>time(),
|
||
'receiveType'=>15,
|
||
'storeId'=>$storeId,
|
||
'subsidy'=>$v['subsidy'],
|
||
'memberType'=>$v['memberType'],
|
||
'memberLabel'=>$v['memberLabel'],
|
||
);
|
||
//var_dump($couponRes);die;
|
||
if($v['timeType']==1){
|
||
$data['useStartTime']=$v['useStartTime'];
|
||
$data['useEndTime']=$v['useEndTime'];
|
||
}else{
|
||
$data['useStartTime']=time();
|
||
$data['useEndTime']=time()+$v['day']*24*60*60;
|
||
}
|
||
$res = YII::$app->db->createCommand()->insert('{{%ybwm_user_coupon}}',$data)->execute();
|
||
}
|
||
|
||
}
|
||
if(is_string($couponId)){
|
||
$couponRes=(new \yii\db\Query())
|
||
->from('{{%ybwm_coupon}}')->where(['id'=>$couponId])->one();
|
||
$data=array(
|
||
'userId'=>$userId,
|
||
'couponId'=>$couponId,
|
||
'type'=>$couponRes['type'],
|
||
'couponName'=>$couponRes['name'],
|
||
'couponDetails'=>$couponRes['details'],
|
||
'money'=>$couponRes['money']?:0.00,
|
||
'fullMoney'=>$couponRes['fullMoney'],
|
||
'discount'=>$couponRes['discount'],
|
||
'useType'=>$couponRes['useType'],
|
||
'storeType'=>$couponRes['storeType'],
|
||
'storeArr'=>$couponRes['storeArr'],
|
||
'goodsType'=>$couponRes['goodsType'],
|
||
'goodsArr'=>$couponRes['goodsArr'],
|
||
'state'=>2,
|
||
'uniacid'=>$uniacid,
|
||
'createdAt'=>time(),
|
||
'receiveType'=>15,
|
||
'storeId'=>$storeId,
|
||
'subsidy'=>$couponRes['subsidy'],
|
||
'memberType'=>$couponRes['memberType'],
|
||
'memberLabel'=>$couponRes['memberLabel'],
|
||
);
|
||
if($couponRes['timeType']==1){
|
||
$data['useStartTime']=$couponRes['useStartTime'];
|
||
$data['useEndTime']=$couponRes['useEndTime'];
|
||
}else{
|
||
$data['useStartTime']=time();
|
||
$data['useEndTime']=time()+$couponRes['day']*24*60*60;
|
||
}
|
||
$res = YII::$app->db->createCommand()->insert('{{%ybwm_user_coupon}}',$data)->execute();
|
||
}
|
||
$transaction->commit();//提交事务
|
||
}catch(\Exception $e){// 如果有一条查询失败,则会抛出异常
|
||
echo $e->getMessage();die;
|
||
$transaction->rollBack();//事务回滚
|
||
}
|
||
return $this->result(1, '成功');
|
||
}
|
||
}
|