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]['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; } /** * 参加活动 * */ public function attendAct($actid,$userid) { //查询活动是否存在 $res=Db::query('SELECT * FROM t_activity_manage WHERE id=?',[$actid]); if(empty($res)){ return false; } if($res[0]['act_status']==0||time()>strtotime($res[0]['end_time'])||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 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; } 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 0; } return $count[0]['recruit_count']; } /** * 获取排名 */ 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_encode($act['act_json']); foreach($cusList as $cus) {//循环参与活动的会员 $yqCount=Db::query('select count(1) as count from t_user where invitation_id=? and invite_bind_time>=? and invite_bind_time<=?',[$cus['user_id'],$cus['create_time'],$actEndTime]); if(empty($yqCount)) { continue; } //计算应得金额 $price=0; switch($rewardRule['act_type']) { case 'step_all'://阶梯完成后赠送 $this->stepAllRule($rewardRule['rule'],$yqCount['count']); break; default: continue; break; } $tradeId=$act['id'].$cus['user_id']; //插入聚推客的订单 $tradeHas=Db::query('select id from t_jtk_union_order_commission where trade_parent_id=?',[$tradeId]); if(!empty($tradeHas)) {//已经有订单 continue; } $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)values(?,?,?,?,1,?,?,?,?,?,?,?,?)',[$tradeId,$tradeId,$cus['user_id'],$cus['user_id'],$price,$price,$act['act_name'].'-活动奖励',$act['id'],0,time(),time(),time()]); if($tradeRes==1) {//修改计算状态 Db::execute('update t_recruit_act set settlement_status=?,settlement_time=? where id=?',[1,time(),$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) { $currentStep=$rule->where('c_count','<=',$yqCount)->max('c_count'); } }