zhaojs
2023-07-11 4c80cd7365316a09ebebb28a904ee70608e5d898
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace app\api\logic;
 
use app\common\logic\Basic as BasicLogic;
use think\Db;
class ActivityInfo extends BasicLogic
{
    /**
     * 参加活动
     * 
     */
    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()<strtotime($res[0]['start_time']))
        {
            return false;
        }
        //插入活动表
        $recruitid=$actid.'u'.$userid;
        $inser=Db::execute('insert ignore into t_recruit_act (id,user_id,act_id,create_time) values(?,?,?,?)',[$recruitid,$userid,$actid,time()]);
        return true;
    }
 
    /**
     * 更新获取已邀请人数
     */
    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]);
        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;
    }
}