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

160 lines
6.9 KiB
PHP

<?php
namespace app\controllers\channel;
use Yii;
class DividendController extends CommonController{
public $enableCsrfValidation = false;
//瓜分红包活动列表
public function actionDividendList(){
$result=axios_request();
$page=$result['page']?:1;
$num=($page-1)*10;
$limit=10;
$table=(new \yii\db\Query())
->from('{{%ybwm_dividend}}')
->select('id,name,from_unixtime(createdAt) createdAt,display,from_unixtime(startTime) startTime,from_unixtime(endTime) endTime,receiveNum')
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid']]);
$list=$table->offset($num)
->limit($limit)->orderBy('id desc')->all();
$count=$table->count();
return $this->result(1, '成功',$list,$count);
}
//保存瓜分红包
public function actionSaveDividend(){
$result=axios_request();
$request = Yii::$app->request;
if($request->isGet){
$info=(new \yii\db\Query())
->from('{{%ybwm_dividend}}')
->where('id=:id',[':id'=>$result['id']])->one();
$info['useType']=json_decode($info['useType'],true);
$info['startTime']=date("Y-m-d H:i:s",$info['startTime']);
$info['endTime']=date("Y-m-d H:i:s",$info['endTime']);
$info['couponEndAt']=date("Y-m-d H:i:s",$info['couponEndAt']);
$info['couponStartAt']=date("Y-m-d H:i:s",$info['couponStartAt']);
return $this->result(1, '成功',$info);
}
if(!$result['name']){
return $this->result(2,'活动名称不能为空!');
}
$data['name']=$result['name'];
$data['startTime']=strtotime($result['startTime']);
$data['endTime']=strtotime($result['endTime']);
$data['payMoney']=$result['payMoney'];
$data['couponName']=$result['couponName'];
$data['couponStartAt']=strtotime($result['couponStartAt']);
$data['couponEndAt']=strtotime($result['couponEndAt']);
$data['orFullMoney']=$result['orFullMoney'];
$data['orReduce']=$result['orReduce'];
$data['opFullMoney']=$result['opFullMoney'];
$data['opReduce']=$result['opReduce'];
$data['useDay']=$result['useDay'];
$data['useType']=json_encode($result['useType'])?:'';
$data['receiveNum']=$result['receiveNum'];
$data['luck']=$result['luck'];
$data['shareImg']=$result['shareImg'];
$data['shareTitle']=$result['shareTitle'];
$data['details']=$result['details'];
if($result['id']){
$info=(new \yii\db\Query())
->from('{{%ybwm_dividend}}')
->where('id!=:id AND deleteAt=0 AND uniacid=:uniacid AND (startTime<=:endTime AND endTime>=:startTime)',[':id'=>$result['id'],':endTime'=>strtotime($result['endTime']),':startTime'=>strtotime($result['startTime']),':uniacid'=>$this->wqData['uniacid']])->one();
if($info){
return $this->result(2,'同一时间段只能创建一个活动!');
}
$data['changeAt']=time();
$re = Yii::$app->db->createCommand()->update('{{%ybwm_dividend}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
}else{
$info=(new \yii\db\Query())
->from('{{%ybwm_dividend}}')
->where('uniacid=:uniacid AND deleteAt=0 AND (startTime<=:endTime AND endTime>=:startTime)',[':endTime'=>strtotime($result['endTime']),':startTime'=>strtotime($result['startTime']),':uniacid'=>$this->wqData['uniacid']])->one();
if($info){
return $this->result(2,'同一时间段只能创建一个活动!');
}
$data['uniacid']=$this->wqData['uniacid'];
$data['createdAt']=time();
// print_R($data);die;
try{
$re = Yii::$app->db->createCommand()->insert('{{%ybwm_dividend}}', $data)->execute();
}catch (\Exception $e){
print_R($e);die;
}
}
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//修改配送活动
public function actionModifyDividend(){
$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_dividend}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
if($res){
return $this->result(1,'成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
//瓜分明细
public function actionJoinList(){
$result=axios_request();
$page=$result['page']?:1;
$divideId=$result['divideId'];
$keyword=$result['keyword'];
$num=($page-1)*10;
$limit=10;
$table=(new \yii\db\Query())
->select('a.userId,a.id,a.divideName,from_unixtime(a.createdAt) createdAt,a.totalNum,a.surplusNum,b.userName,b.portrait')
->from('{{%ybwm_dividend_join}} as a')
->leftJoin('{{%ybwm_member}} as b','a.userId=b.id')
->where(['a.uniacid'=>$this->wqData['uniacid']]);
if($divideId){
$table->andWhere('a.divideId='.$divideId);
}
if($keyword){
$table->andWhere(['or',['like','a.divideName',$keyword],['like','b.userName',$keyword]]);
}
$list=$table->offset($num)
->limit($limit)->orderBy('a.id desc')->all();
$count=$table->count();
return $this->result(1, '成功',$list,$count);
}
//领取明细
public function actionReceiveList(){
$result=axios_request();
$page=$result['page']?:1;
$joinId=$result['joinId'];
$keyword=$result['keyword'];
$num=($page-1)*10;
$limit=10;
$table=(new \yii\db\Query())
->select('a.id,j.divideName,from_unixtime(a.createdAt) createdAt,a.fullMoney,a.money,a.lucky,b.userName,b.portrait,m.userName as sponsorUserName,m.portrait as sponsorPortrait')
->from('{{%ybwm_dividend_receive}} as a')
->leftJoin('{{%ybwm_member}} as b','a.userId=b.id')
->leftJoin('{{%ybwm_dividend_join}} as j','a.joinId=j.id')
->leftJoin('{{%ybwm_member}} as m','j.userId=m.id')
->where(['a.uniacid'=>$this->wqData['uniacid']]);
if($joinId){
$table->andWhere('a.joinId='.$joinId);
}
if($keyword){
$table->andWhere(['or',['like','j.divideName',$keyword],['like','b.userName',$keyword],['like','m.userName',$keyword]]);
}
$list=$table->offset($num)
->limit($limit)->orderBy('a.id desc')->all();
$count=$table->count();
return $this->result(1, '成功',$list,$count);
}
}