368 lines
16 KiB
PHP
368 lines
16 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\BaseCom;
|
|
use think\Controller;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 活动:
|
|
* 1.首充好礼
|
|
*
|
|
*/
|
|
class Activities extends BaseCom
|
|
{
|
|
//初始化
|
|
protected function initialize()
|
|
{
|
|
//允许跨域
|
|
header('Access-Control-Allow-Origin: *');
|
|
}
|
|
|
|
//首充好礼
|
|
public function first_charge_gift()
|
|
{
|
|
//活动信息
|
|
$activities_id = 1;//首充
|
|
$activities_title = DB::name('vs_activities')->where(['id'=>$activities_id,'status'=>1])->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]['gift_bag_id'] = $v['id']??0;
|
|
$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);
|
|
}
|
|
|
|
return V(1,'操作成功', $data);
|
|
}
|
|
//首充好礼权限
|
|
public function first_charge_gift_permission()
|
|
{
|
|
$activities_id = 1;//首充
|
|
$uid = input('uid',$this->uid);
|
|
$permission_status = 1;
|
|
//查询是否首充
|
|
$is_first_charge = db::name('vs_user_money_log')->where('user_id',$uid)->where('change_type',2)->where('money_type',1)->where(['createtime'=>['>=',"1760666400"]])->count();
|
|
$permission = DB::name('vs_activities_receive')->where(['activities_id'=>$activities_id,'user_id'=>$uid])->where(['createtime'=>['>=',"1760666400"]])->find();
|
|
$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;
|
|
}
|
|
}
|
|
if($is_first_charge > 0){
|
|
$permission_status = 0;
|
|
}
|
|
if($permission){
|
|
$permission_status = 0;
|
|
}
|
|
return V(1,'操作成功', ['permission'=>$permission_status],$api_version);
|
|
|
|
}
|
|
//首充好礼发放
|
|
public function first_charge_gift_receive()
|
|
{
|
|
$uid = input('uid',$this->uid);
|
|
$money = input('money',0);
|
|
$reslut = model('Activities')->first_charge_gift_send($uid,$money);
|
|
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
|
|
|
}
|
|
|
|
//天降好礼
|
|
public function day_drop_gift()
|
|
{
|
|
$activities_id = 3;//天降好礼
|
|
$activities = DB::name('vs_activities')->where(['id'=>$activities_id,'status'=>1])->find();
|
|
//礼包
|
|
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->find();
|
|
$data = [];
|
|
$data['gift_bag_id'] = $gift_bag['id']??0;
|
|
$data['name'] = $activities['title']??"";
|
|
$data['bag_name'] = $gift_bag['title']??"";
|
|
$data['effective_time'] = $activities['effective_time']??"";
|
|
//规则
|
|
$data['rule'] = get_system_config_value('web_site')."/api/Page/page_show?id=13";
|
|
$ext = json_decode($gift_bag['ext'],true);
|
|
$data['money'] = $gift_bag['money'];
|
|
$data['counter'] = $ext['counter'];
|
|
$data['money_str'] = $ext['money_str'];
|
|
$data['diamond'] = $ext['diamond'];
|
|
$data['effective_time'] = $ext['activity_end_time']??"";
|
|
if(strtotime($ext['activity_end_time']) < time()){
|
|
return V(0,'活动已结束!',null);
|
|
}
|
|
$detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag['id']])->select();
|
|
$data['gift_list'] = [];
|
|
foreach ($detail as $k=>$v){
|
|
if($v['type'] == 1){
|
|
$list[$k]['gift_name'] = "金币";
|
|
$list[$k]['num'] = $v['gold'];
|
|
$list[$k]['gift_price'] = $v['gold'];
|
|
$list[$k]['type'] = 1;
|
|
$list[$k]['base_image'] = localpath_to_netpath("static/image/icon/gold.png");
|
|
}elseif($v['type'] == 2) {
|
|
$gift = DB::name('vs_gift')->where(['gid'=>$v['foreign_id']])->find();
|
|
$list[$k]['gift_name'] = $gift['gift_name'];
|
|
$list[$k]['num'] = $v['quantity'];
|
|
$list[$k]['gift_price'] = $gift['gift_price'];
|
|
$list[$k]['type'] =2;
|
|
$list[$k]['base_image'] = $gift['base_image'];
|
|
} elseif($v['type'] == 3) {
|
|
$decorate_price = DB::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
|
$gift = DB::name('vs_decorate')->where(['did'=>$decorate_price['did']])->find();
|
|
$list[$k]['gift_name'] = $gift['title']; //装扮名称
|
|
$list[$k]['num'] = $decorate_price['day']; //天数
|
|
$list[$k]['gift_price'] = $decorate_price['price']; //价格
|
|
$list[$k]['type'] =3;
|
|
$list[$k]['base_image'] = $gift['base_image'];
|
|
}elseif($v['type'] == 4) {
|
|
$list[$k]['gift_name'] = "钻石";
|
|
$list[$k]['num'] = $v['quantity'];
|
|
$list[$k]['gift_price'] = $v['gold'];
|
|
$list[$k]['type'] = 4;
|
|
$list[$k]['base_image'] = localpath_to_netpath("static/image/icon/gold.png");
|
|
}
|
|
}
|
|
$data['gift_list'] = $list;
|
|
return V(1,'操作成功', $data);
|
|
}
|
|
//天降好礼权限
|
|
public function day_drop_gift_permission()
|
|
{
|
|
$activities_id = 3;//天降好礼
|
|
$uid = input('uid',$this->uid);
|
|
//礼包
|
|
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>3,'status'=>1])->find();
|
|
$permission = 0;
|
|
if($gift_bag){
|
|
$ext = json_decode($gift_bag['ext'],true);
|
|
if($ext['activity_end_time'] <= time()){
|
|
$permission = 1;
|
|
}
|
|
}
|
|
return V(1,'操作成功', ['permission'=>$permission]);
|
|
}
|
|
//天降好礼发放
|
|
public function drop_gift_send()
|
|
{
|
|
$uid = input('uid',$this->uid);
|
|
$reslut = model('Activities')->drop_gift_send($uid);
|
|
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'] = [];
|
|
//一键领取
|
|
$bag_receive_all = DB::name('vs_gift_bag_receive_log')->where(['gift_bag_id'=>17,'user_id'=>$this->uid])->find();
|
|
foreach ($gift_bag as $k=>$v){
|
|
$data['gift_bag'][$k]['gift_bag_id'] = $v['id']??0;
|
|
$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);
|
|
if($bag_receive_all){
|
|
$data['gift_bag'][$k]['status'] = 0;
|
|
}else{
|
|
if($v['id']!=17){
|
|
$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)->where(['createtime'=>['>=',"1760666400"]])->count();
|
|
$permission = DB::name('vs_activities_receive')->where(['activities_id'=>$activities_id,'user_id'=>$uid])->where(['createtime'=>['>=',"1760666400"]])->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();
|
|
if($activities){
|
|
$effective_time = $activities['effective_time'];
|
|
}else{
|
|
$effective_time = 0;
|
|
}
|
|
$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']<"1760666400"){
|
|
$user_info['createtime'] = 1760666400;
|
|
}
|
|
if($user_info['createtime'] + $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,
|
|
'n_people_permission'=>$new_permission
|
|
],$api_version);
|
|
}
|
|
|
|
}
|