From 8dcfae4fff98fbbb19ff46bd9750f25bc56801a9 Mon Sep 17 00:00:00 2001 From: zhaojs <349234519@qq.com> Date: 星期一, 31 七月 2023 10:42:20 +0800 Subject: [PATCH] Merge branch 'release/v1.1.5发布' --- application/api/logic/ActivityInfo.php | 253 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 239 insertions(+), 14 deletions(-) diff --git a/application/api/logic/ActivityInfo.php b/application/api/logic/ActivityInfo.php index a1b2c4e..b09270d 100644 --- a/application/api/logic/ActivityInfo.php +++ b/application/api/logic/ActivityInfo.php @@ -2,9 +2,58 @@ namespace app\api\logic; use app\common\logic\Basic as BasicLogic; +use think\console\output\descriptor\Console; use think\Db; +use app\common\model\User as ModelUser; +use app\api\logic\SettlementRecord as LogicSettlementRecord; +use app\api\logic\UserBrowse as LogicUserBrowse; + class ActivityInfo extends BasicLogic { + + + /** + * 鑾峰彇娲诲姩淇℃伅 + */ + public function getActInfo($actid,$userid) + { + $res=Db::query('SELECT * FROM t_activity_manage WHERE id=?',[$actid]); + $response=[ + 'actstatus'=>1, + 'joinstatus'=>0 + ]; + if(empty($res)){ + $response['actstatus']=0;//涓嶅瓨鍦� + return $response; + } + if($res[0]['act_status']==0) + { + $response['actstatus']=-1;//宸茬粨鏉� + return $response; + } + if(time()<strtotime($res[0]['start_time'])) + { + $response['actstatus']= -2;//鏈紑濮� + return $response; + } + if(time()>strtotime($res[0]['end_time'])) + { + $response['actstatus']= -3;//宸茬粨鏉� + return $response; + } + //鏄惁宸插弬鍔犳椿鍔� + $recruitid=$actid.'u'.$userid; + $canjia=Db::query('select id from t_recruit_act where id=?',[$recruitid]); + if(empty($canjia)) + { + $response['joinstatus']=0;//鏈弬鍔� + } + else{ + $response['joinstatus']=1;//宸插弬鍔� + } + return $response; + } + /** * 鍙傚姞娲诲姩 * @@ -31,22 +80,198 @@ */ public function updateRecruitCount($userid) { - //鏌ヨ杩涜涓殑鎷涘嫙娲诲姩 - $nowTime=time(); - $actList=Db::query('select id from t_activity_manage where act_status=1 and start_time<=? and end_time>=? limit 1',[$nowTime,$nowTime]); + try{ + //鏌ヨ杩涜涓殑鎷涘嫙娲诲姩 + $nowTime= date("Y-m-d H:i:s", time()); + $actList=Db::query('select id,end_time from t_activity_manage where act_status=1 and start_time<=? and end_time>=? and act_type=0 limit 1',[$nowTime,$nowTime]); + if(empty($actList)) + {//娌℃湁杩涜涓殑娲诲姩锛屼笉鐢ㄥ鐞� + return true; + } + + //鏌ヨ鏄惁鍙傚姞浜嗘嫑鍕熸椿鍔� + $recruitid=$actList[0]['id'].'u'.$userid; + $actReinfo=Db::query('select id,create_time from t_recruit_act where id=? and user_t=0 and settlement_status=0',[$recruitid]); + if(empty($actReinfo)) + {//娌℃湁鍙傚姞娲诲姩锛屼笉鐢ㄥ鐞� + return true; + } + //鑾峰彇宸查個璇蜂汉鏁� + $actEndTime=strtotime($actList[0]['end_time']);//娲诲姩缁撴潫鏃堕棿 + $yqCount=Db::query('select count(DISTINCT(login_deviceid)) as count from t_user where invitation_id=? and status=? and invite_bind_time>=? and invite_bind_time<=?',[$userid,'normal',$actReinfo[0]['create_time'],$actEndTime]); + $count=0; + if(!empty($yqCount)) + { + $count=$yqCount[0]['count']; + } + //澧炲姞count + $countres=Db::execute('update t_recruit_act set recruit_count=? where id=?',[$count,$recruitid]); + return $countres==1; + } + catch(\Exception $e) + { + + } + } + + /** + * 鑾峰彇宸查個璇蜂汉鏁� + */ + public function getActRecruitCount($actid,$userid) + { + $recruitid=$actid.'u'.$userid; + $count=Db::query('select recruit_count from t_recruit_act where id=?',[$recruitid]); + if(empty($count)) + { + return [ + 'membercount'=>0, + 'award'=>0 + ]; + } + //鑾峰彇閲戦淇℃伅 + $actList=Db::query('select * from t_activity_manage where id=? and count_status=0 and act_type=0 and act_status=1',[$actid]); + $rewardRule=json_decode($actList[0]['act_json']); + $award=$this->stepAllRule($rewardRule->rule,$count[0]['recruit_count']); + return [ + 'membercount'=>$count[0]['recruit_count'], + 'award'=>$award + ]; + } + + /** + * 鑾峰彇鎺掑悕 + */ + public function getRankingList($actid,$userid) + { + $rList=Db::query('SELECT a.id,a.nickname,a.avatar,b.recruit_count from t_recruit_act b left join t_user a on a.id =b.user_id where b.act_id=? and b.recruit_count>0 order by b.recruit_count desc limit 7',[$actid]); + if(empty($rList)) + { + return []; + } + return $rList; + } + + + /** + * 璁$畻鎷涘嫙娲诲姩閲戦 + * + */ + public function run_countRecruitAct() + { + //鍏堟煡璇㈡嫑鍕熸椿鍔� + $actList=Db::query('select * from t_activity_manage where count_status=0 and act_type=0 and act_status=1'); if(empty($actList)) - {//娌℃湁杩涜涓殑娲诲姩锛屼笉鐢ㄥ鐞� + { + return '娌℃湁绗﹀悎鐨勬椿鍔�'; + } + + foreach($actList as $act) + {//寰幆娲诲姩锛岃绠楅噾棰� + //淇敼娲诲姩璁$畻鐘舵�� + $this->run_UpdateActCount($act['id'],1); + $actEndTime=strtotime($act['end_time']);//娲诲姩缁撴潫鏃堕棿 + //鏌ヨ鎵�鏈夊弬涓庢椿鍔ㄧ殑浼氬憳 + $cusList=Db::query('select * from t_recruit_act where act_id=? and settlement_status=0 and user_t=0',[$act['id']]); + if(empty($cusList)) + { + $this->run_UpdateActCount($act['id'],2); + continue; + } + //娲诲姩瑙勫垯 + $rewardRule=json_decode($act['act_json']); + foreach($cusList as $cus) + {//寰幆鍙備笌娲诲姩鐨勪細鍛� + $tradeId=$act['id'].'u'.$cus['user_id']; + $yqCount=Db::query('select count(DISTINCT(login_deviceid)) as count from t_user where invitation_id=? and status=? and invite_bind_time>=? and invite_bind_time<=?',[$cus['user_id'],'normal',$cus['create_time'],$actEndTime]); + if(empty($yqCount)) + { + Db::execute('update t_recruit_act set settlement_status=?,settlement_time=?,act_count=0,act_award=0 where id=?',[1, date("Y-m-d H:i:s", time()),$tradeId]); + continue; + } + //璁$畻搴斿緱閲戦 + $price=0; + switch($rewardRule->act_type) + { + case 'step_all'://闃舵瀹屾垚鍚庤禒閫� + $price=$this->stepAllRule($rewardRule->rule,$yqCount[0]['count']); + break; + default: + break; + } + if($price<=0) + { + Db::execute('update t_recruit_act set settlement_status=?,settlement_time=?,act_count=?,act_award=0 where id=?',[1, date("Y-m-d H:i:s", time()),$yqCount[0]['count'],$tradeId]); + continue; + } + //鎻掑叆鑱氭帹瀹㈢殑璁㈠崟 + $tradeHas=Db::query('select id from t_jtk_union_order_commission where trade_parent_id=?',[$tradeId]); + if(!empty($tradeHas)) + {//宸茬粡鏈夎鍗� + continue; + } + //璁$畻璁㈠崟鏀剁泭 + $title = $act['act_name'].'-娲诲姩濂栧姳缁撶畻'; + ModelUser::money('inc',$price,$cus['user_id'],$title); + LogicSettlementRecord::writeLog('jtk',$price,$cus['user_id'],$title); + $tradeRes=Db::execute('insert into t_jtk_union_order_commission (trade_parent_id,trade_id,member_id,buy_member_id,is_own,alipay_total_price,pub_share_pre_fee,item_title,item_id,is_settle,tb_paid_time,create_time,update_time,tk_status,tk_earning_time,pub_share_fee)values(?,?,?,?,1,?,?,?,?,?,?,?,?,?,?,?)',[$tradeId,$tradeId,$cus['user_id'],$cus['user_id'],$price,$price,$act['act_name'].'-娲诲姩濂栧姳',$act['id'],1,date("Y-m-d H:i:s", time()),time(),time(),3,time(),$price]); + if($tradeRes==1) + {//淇敼璁$畻鐘舵�� + Db::execute('update t_recruit_act set settlement_status=?,settlement_time=?,act_count=?,act_award=? where id=?',[1, date("Y-m-d H:i:s", time()),$yqCount[0]['count'],$price,$tradeId]); + } + } + $this->run_UpdateActCount($act['id'],2); + } + return '鎵ц-success'; + } + + public function run_UpdateActCount($actid,$countStatus) + { + if($countStatus==1) + { + Db::execute('update t_activity_manage set count_status=? where id=?',[$countStatus,$actid]); + } + else{ + Db::execute('update t_activity_manage set count_status=?,count_time=? where id=?',[$countStatus,time(),$actid]); + } + } + + /** + * step_all瑙勫垯 + * + */ + public function stepAllRule($rule,$yqCount) + { + $maxReward=0; + foreach($rule as $r_item) + { + if($r_item->c_count>$yqCount) + { + continue; + } + if($maxReward<$r_item->reward) + { + $maxReward=$r_item->reward; + } + } + return $maxReward; + } + + /** + * 鑷畾涔夊脊绐�-0鍏冭喘 + */ + public function popupcus_freebuy($userInfo) + { + $LogicUserBrowse = new LogicUserBrowse(); + $res = $LogicUserBrowse->checkIsFirstFree($userInfo->id); + if($res === false) + { + return false; + } + if(empty($res)) + { return true; } - //鏌ヨ鏄惁鍙傚姞浜嗘嫑鍕熸椿鍔� - $recruitid=$actList[0]['id'].'u'.$userid; - $actReinfo=Db::query('select id from t_recruit_act where id=? and settlement_status=0',[$recruitid]); - if(empty($actReinfo)) - {//娌℃湁鍙傚姞娲诲姩锛屼笉鐢ㄥ鐞� - return true; - } - //澧炲姞count - $countres=Db::execute('update t_recruit_act set recruit_count=recruit_count+1 where id=?',[$recruitid]); - return $countres==1; + return false; } + } \ No newline at end of file -- Gitblit v1.9.3