diff --git a/application/api/controller/Activities.php b/application/api/controller/Activities.php index f75147c..b44819f 100644 --- a/application/api/controller/Activities.php +++ b/application/api/controller/Activities.php @@ -198,4 +198,145 @@ class Activities extends BaseCom return V($reslut['code'],$reslut['msg'], $reslut['data']); } + //新人好礼 + public function new_charge_gift() + { + //活动信息 + $activities_id = 7; + $activities_title = DB::name('vs_activities')->where(['id'=>$activities_id,'status'=>1,'delete_time'=>0])->value('title'); + //礼包 + $gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->select(); + $data = []; + $data['name'] = $activities_title??""; + $data['gift_bag'] = []; + foreach ($gift_bag as $k=>$v){ + $data['gift_bag'][$k]['name'] = $v['title']??""; + $ext = json_decode($v['ext'],true); + $data['gift_bag'][$k]['title1'] = $ext['title1']??""; + $data['gift_bag'][$k]['title2'] = $ext['title2']??""; + $data['gift_bag'][$k]['money'] = $ext['money']; + $data['gift_bag'][$k]['gift_list'] = []; + $detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$v['id']])->select(); + $list = []; + foreach ($detail as $kk=>$vv){ + if($vv['type'] == 1){ + $list[$kk]['gift_name'] = "金币"; + $list[$kk]['num'] = $vv['quantity']; + $list[$kk]['gift_price'] = $vv['gold']; + $list[$kk]['type'] = 1; + $list[$kk]['base_image'] = localpath_to_netpath("static/image/icon/gold.png"); + }elseif ($vv['type'] == 2) { + $gift = DB::name('vs_gift')->where(['gid'=>$vv['foreign_id']])->find(); + if($gift){ + $list[$kk]['gift_name'] = $gift['gift_name']; + $list[$kk]['num'] = $vv['quantity']; + $list[$kk]['gift_price'] = $gift['gift_price']; + $list[$kk]['type'] =2; + $list[$kk]['base_image'] = $gift['base_image']; + } + } elseif ($vv['type'] == 3) { + $decorate_price = DB::name('vs_decorate_price')->where(['id'=>$vv['foreign_id']])->find(); + if($decorate_price){ + $gift = DB::name('vs_decorate')->where(['did'=>$decorate_price['did']])->find(); + $list[$kk]['gift_name'] = $gift['title']??""; //装扮名称 + $list[$kk]['num'] = $decorate_price['day']??0; //天数 + $list[$kk]['gift_price'] = $decorate_price['price']??0; //价格 + $list[$kk]['type'] =3; + $list[$kk]['base_image'] = $gift['base_image'] ?? ""; + } + + }elseif ($vv['type'] == 4) { + $list[$kk]['gift_name'] = "钻石"; + $list[$kk]['num'] = $vv['quantity']; + $list[$kk]['gift_price'] = $vv['gold']; + $list[$kk]['type'] = 4; + $list[$kk]['base_image'] = localpath_to_netpath("static/image/icon/diamond.png"); + } + } + $data['gift_bag'][$k]['gift_list'] = array_values($list); + $bag_receive_log = DB::name('vs_gift_bag_receive_log')->where(['gift_bag_id'=>$v['id'],'user_id'=>$this->uid])->find(); + if($bag_receive_log){ + $data['gift_bag'][$k]['status'] = 0; + } else { + $data['gift_bag'][$k]['status'] = 1; + } + } + + return V(1,'操作成功', $data); + } + + //新人好礼发放 + public function new_charge_gift_receive() + { + $uid = input('uid',$this->uid); + $money = input('money',0); + $reslut = model('Activities')->new_charge_gift_send($uid,$money); + return V($reslut['code'],$reslut['msg'], $reslut['data']); + + } + + /* + * 活动权限 + */ + public function activities_permission(){ + $system = request()->header('system'); + $app_version = request()->header('App-Version'); + if(!$app_version){ + $app_version = input('App-Version'); + } + $api_version = 0; + if ($system == 'iOS') { + $api_versions = db::name('version')->where(['type' => 2, 'status' => 1])->order('id', 'desc')->find(); + $result = version_compare($api_versions['oldversion'],$app_version); + if ($result < 0) { + $api_version = 1; + } + } + //首充 + $activities_id = 1; + $uid = input('uid',$this->uid); + $first_charge_permission = 1; + //查询是否首充 + $is_first_charge = db::name('vs_user_money_log')->where('user_id',$uid)->where('change_type',2)->where('money_type',1)->count(); + $permission = DB::name('vs_activities_receive')->where(['activities_id'=>$activities_id,'user_id'=>$uid])->find(); + if($is_first_charge > 0){ + $first_charge_permission = 0; + } + if($permission){ + $first_charge_permission = 0; + } + //天降好礼 + $gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>3,'status'=>1])->find(); + $day_drop_permission = 0; + if($gift_bag){ + $ext = json_decode($gift_bag['ext'],true); + if(strtotime($ext['activity_end_time']) >= time()){ + $day_drop_permission = 1; + } + } + //新人充值好礼 + $activities = DB::name('vs_activities')->where(['id'=>7,'status'=>1,'delete_time'=>0])->find(); + $bag_data = DB::name('vs_gift_bag')->where(['activities_id'=>7,'status'=>1,'delete_time'=>0])->select(); + $bag_receive_log = DB::name('vs_gift_bag_receive_log')->where(['gift_bag_id'=>['in',array_column($bag_data,'id')],'user_id'=>$uid])->select(); + $new_permission = 0; + $user_info = DB::name('user')->where(['id'=>$uid])->find(); + if($user_info['createtime'] + $activities['effective_time'] >= time()){ + $new_permission = 1; + } + $gift_bag_log_ids = array_column($bag_receive_log,'gift_bag_id'); + if(in_array(17,$gift_bag_log_ids)){ + $new_permission = 0; + }else{ + $gift_bag_log_ids = array_intersect([14,15,16],$gift_bag_log_ids); + if(count($gift_bag_log_ids) == 3){ + $new_permission = 0; + } + } + return V(1,'操作成功',[ + 'first_charge_permission'=>$first_charge_permission, + 'day_drop_permission'=>$day_drop_permission, + 'new_permission'=>$new_permission + ],$api_version); + } + } diff --git a/application/api/model/Activities.php b/application/api/model/Activities.php index 11d055d..c279db4 100644 --- a/application/api/model/Activities.php +++ b/application/api/model/Activities.php @@ -171,4 +171,85 @@ class Activities extends Model return ['code' => 0, 'msg' => "请重试", 'data' => null]; } } + + /* + * 新人好礼发放 + */ + public static function new_charge_gift_send($user_id,$money=0) + { + //礼包 + $activities_id = 7; + $gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1,'delete_time'=>0,'money'=>$money])->order('money desc')->find(); + $gift_bag_id = $gift_bag['id'] ?? 0; + if (!$gift_bag_id) { + return ['code' => 0, 'msg' => '礼包不存在','data' => null]; + } + $gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select(); + if (!$gift_bag_detail) { + return ['code' => 0, 'msg' => '礼包未配置','data' => null]; + } + Db::startTrans(); + try { + foreach ($gift_bag_detail as $k=>$v){ + $gift_id =0; + $gift_price = 0; + $gift_num = $v['quantity']; + switch ($v['type']) { + case 1: //金币 方法1:直接添加到用户钱包 + $gift_price = $v['quantity']; + $res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::NEW_USER_CHARGE_GIFT,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::NEW_USER_CHARGE_GIFT)); + break; + case 2: //礼物 方法2:添加到用户礼物背包 + $gift_id = $v['foreign_id']; + $res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::NEW_CHARGE_GIFT,"新人好礼获得礼物"); + break; + case 3: //坐骑 方法3:添加到用户装扮 + $gift_id = $v['foreign_id']; + $decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find(); + if(empty($decorate_price_info)){ + break; + } + $gift_price = $decorate_price_info['price']; + $res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],8); + break; + case 4: //道具 方法5:钻石 + $gift_price = $v['quantity']; + $res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::NEW_USER_CHARGE_GIFT,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::NEW_USER_CHARGE_GIFT)); + default: + break; + } + if ($res['code'] != 1) { + Db::rollback(); + return ['code' => 0, 'msg' => $res['msg'], 'data' => null]; + } + // 记录日志 + //添加礼盒记录 + $reslut = Db::name('vs_gift_bag_receive_log')->insert([ + 'user_id' => $user_id, + 'gift_bag_id' => $gift_bag_id, + 'parent_id' => $v['id'], + 'gift_id'=> $v['foreign_id'], + 'num' => $v['quantity'], + 'bag_price' => $gift_bag['money'], + 'gift_price' => $v['gold'], + 'createtime' => time(), + 'updatetime' => time() + ]); + } + // 添加活动记录 + $reslut = Db::name('vs_activities_receive')->insert([ + 'user_id' => $user_id, + 'activities_id' => 1, + 'createtime' => time(), + 'updatetime' => time() + ]); + Db::commit(); + return ['code' => 1, 'msg' => '操作成功','data' => null]; + }catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return ['code' => 0, 'msg' => "请重试", 'data' => null]; + } + } + } diff --git a/application/api/model/Decorate.php b/application/api/model/Decorate.php index 878a129..34b4753 100644 --- a/application/api/model/Decorate.php +++ b/application/api/model/Decorate.php @@ -17,7 +17,7 @@ class Decorate extends Model protected $updateTime = 'updatetime'; // 定义字段类型 1头像框 2坐骑 3麦圈 6个人靓号 7房间靓号 8公会靓号 public $TypeArray = [1=>'头像框',2=>'坐骑',3=>'麦圈',6=>'个人靓号',7=>'房间靓号',8=>'公会靓号']; - protected $FromType = [1=>'购买',2=>'后台赠送',3=>'礼盒开奖',4=>'好友赠送',5=>'首充赠送',6=>'天降好礼获得',7=>'财富等级特权赠送']; + protected $FromType = [1=>'购买',2=>'后台赠送',3=>'礼盒开奖',4=>'好友赠送',5=>'首充赠送',6=>'天降好礼获得',7=>'财富等级特权赠送',8=>'新人充值好礼']; public function __construct($data = []) { parent::__construct($data); diff --git a/application/api/model/UserGiftPack.php b/application/api/model/UserGiftPack.php index f32c500..8e9251a 100644 --- a/application/api/model/UserGiftPack.php +++ b/application/api/model/UserGiftPack.php @@ -36,6 +36,8 @@ class UserGiftPack extends Model const XLH_DRAW_GIFT_GET = 8; //小时榜获得 const HOUR_RANK_GET = 9; + //新人充值好礼 + const NEW_CHARGE_GIFT = 10; public static function init() { @@ -54,7 +56,8 @@ class UserGiftPack extends Model self::FIRST_CHARGE => '首充获得', self::DRAW_GIFT => '天降好礼获得', self::XLH_DRAW_GIFT_GET => '巡乐会抽奖所得', - self::HOUR_RANK_GET => '小时榜获得' + self::HOUR_RANK_GET => '小时榜获得', + self::NEW_CHARGE_GIFT => '新人充值好礼' ]; } diff --git a/application/common/model/UserWallet.php b/application/common/model/UserWallet.php index 1fa0136..df565cd 100644 --- a/application/common/model/UserWallet.php +++ b/application/common/model/UserWallet.php @@ -75,6 +75,8 @@ class UserWallet extends Model const RECEIVE_COIN = 26; //小时榜获得金币 const HOUR_RANK_COIN = 27; + //新人充值好礼 + const NEW_USER_CHARGE_GIFT = 28; //金币支出类型数组 @@ -138,7 +140,8 @@ class UserWallet extends Model self::DELETE_RELATION_COIN => '删除关系扣金币', self::TRANSFER_COIN => '赠送好友金币', self::RECEIVE_COIN => '好友转赠所得金币', - self::HOUR_RANK_COIN => '小时榜获得金币' + self::HOUR_RANK_COIN => '小时榜获得金币', + self::NEW_USER_CHARGE_GIFT => '新人充值好礼' ]; return $status[$type] ?? ''; }