2025-12-10 18:44:16 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\api\model;
|
|
|
|
|
|
use think\Model;
|
|
|
|
|
|
use think\Session;
|
|
|
|
|
|
use think\Db;
|
|
|
|
|
|
|
|
|
|
|
|
class Tasks extends Model
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// 开启自动写入时间戳字段
|
|
|
|
|
|
protected $autoWriteTimestamp = 'int';
|
|
|
|
|
|
// 定义时间戳字段名
|
|
|
|
|
|
protected $createTime = 'createtime';
|
|
|
|
|
|
protected $updateTime = 'updatetime';
|
|
|
|
|
|
protected $table;
|
|
|
|
|
|
//任务类型枚举
|
|
|
|
|
|
public $task_type = [
|
|
|
|
|
|
'1' => '新手任务',
|
|
|
|
|
|
'2' => '每日任务',
|
2025-12-11 18:30:33 +08:00
|
|
|
|
'3' => '情侣任务',
|
|
|
|
|
|
'4' => '师徒任务',
|
2025-12-10 18:44:16 +08:00
|
|
|
|
];
|
|
|
|
|
|
//每日任务类型枚举
|
|
|
|
|
|
public $processing_type_str = [
|
|
|
|
|
|
1 => '登录',
|
|
|
|
|
|
2 => '去观看',
|
|
|
|
|
|
3 => '去完成',
|
|
|
|
|
|
4 => '去送礼',
|
|
|
|
|
|
5 => '去邀请',
|
|
|
|
|
|
6 => '去充值',
|
|
|
|
|
|
7 => '去发布',
|
|
|
|
|
|
8 => '签到',
|
|
|
|
|
|
9 => '自动完成',
|
|
|
|
|
|
];
|
|
|
|
|
|
//任务跳转类型:
|
|
|
|
|
|
public $jump_type = [
|
|
|
|
|
|
0 => '不跳转',
|
|
|
|
|
|
1 => '跳转实名',
|
|
|
|
|
|
2 => '跳转我的相册',
|
|
|
|
|
|
3 => '跳转绑定管理',
|
|
|
|
|
|
4 => '跳转房间',
|
|
|
|
|
|
5 => '跳转申请加入公会',
|
|
|
|
|
|
6 => '跳转充值',
|
2025-12-16 17:40:34 +08:00
|
|
|
|
7 => '跳转创建房间',
|
2025-12-10 18:44:16 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($data = [])
|
|
|
|
|
|
{
|
|
|
|
|
|
$prefix = config('database.prefix');
|
|
|
|
|
|
$this->table = $prefix . 'vs_tasks';
|
|
|
|
|
|
parent::__construct($data);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//每日任务列表
|
|
|
|
|
|
public function dailyTasksList($user_id=''){
|
|
|
|
|
|
$reslut = [];
|
|
|
|
|
|
//用户今日充值金币数量
|
|
|
|
|
|
$user_gold = Db::name('vs_user_money_log')->where(['user_id'=>$user_id,'change_type'=>2,'money_type'=>1])
|
|
|
|
|
|
->whereTime('createtime', 'today')
|
|
|
|
|
|
->sum('change_value');
|
|
|
|
|
|
$reslut['user_gold'] = $user_gold ? $user_gold : 0;
|
|
|
|
|
|
//礼盒列表
|
|
|
|
|
|
$gift_box = Db::name('vs_gift_bag')->where('status',1)->where('activities_id',2)->select();
|
|
|
|
|
|
$reslut['gift_box_list'] = [];
|
|
|
|
|
|
foreach ($this->task_type as $key => $value) {
|
|
|
|
|
|
$reslut['tasks'][$key-1]['task_type_id'] = $key;
|
|
|
|
|
|
$reslut['tasks'][$key-1]['task_type_name'] = $value;
|
2025-12-16 10:57:25 +08:00
|
|
|
|
$reslut['tasks'][$key-1]['is_lock'] = 0;
|
2025-12-11 17:34:27 +08:00
|
|
|
|
$reslut['tasks'][$key-1]['task_list'] = [];
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
foreach ($gift_box as $key => $val) {
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['id'] = $val['id'];
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['name'] = $val['name'];
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['title'] = $val['title'];
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['icon'] = localpath_to_netpath($val['icon']);
|
|
|
|
|
|
$ext = json_decode($val['ext'],true);
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['highest_gain'] = $ext['highest_gain'];
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['meet'] = $ext['meet'] ? $ext['meet'] : 0;
|
|
|
|
|
|
//解锁进度
|
|
|
|
|
|
if($ext['meet']){
|
|
|
|
|
|
if($user_gold > $ext['meet']){
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['unlock_progress'] = 1;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['unlock_progress'] = round(( $user_gold / $ext['meet']),2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['unlock_progress'] = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
//今日可抽奖次数
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['all_number'] = $ext['num'] ? $ext['num'] : 0;
|
|
|
|
|
|
//今日已抽奖次数
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['taday_number'] = Db::name('vs_gift_bag_receive_log')->where('user_id',$user_id)->where('gift_bag_id',$val['id'])->whereTime('createtime', 'today')->count();
|
|
|
|
|
|
//今日剩余抽奖次数
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['taday_number_left'] = $ext['num'] - $reslut['gift_box_list'][$key]['taday_number'];
|
|
|
|
|
|
//状态
|
|
|
|
|
|
if ($user_gold < $ext['meet']) {
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['status'] = 0;
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['status_str'] = '未解锁';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['status'] = 1;
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['status_str'] = '已解锁('.$reslut['gift_box_list'][$key]['taday_number'].'/'.$ext['num'].')';
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($reslut['gift_box_list'][$key]['taday_number']>=$ext['num']) {
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['status'] = 2;
|
|
|
|
|
|
$reslut['gift_box_list'][$key]['status_str'] = '已用完('.$reslut['gift_box_list'][$key]['taday_number'].'/'.$ext['num'].')';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-30 16:45:30 +08:00
|
|
|
|
//判断用户是否实名认证,并查询用户手机号下的用户
|
|
|
|
|
|
$is_real = model('UserData')->real_name_info($user_id);
|
|
|
|
|
|
if($is_real['code']==1){
|
|
|
|
|
|
if($is_real['data']['is_real'] ==1){
|
2025-12-30 22:14:42 +08:00
|
|
|
|
$user_ids = db::name('user')->where('mobile',$is_real['data']['mobile'])->column('id');
|
2025-12-30 16:45:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-10 18:44:16 +08:00
|
|
|
|
//任务列表
|
|
|
|
|
|
$data = db::name('vs_tasks')
|
|
|
|
|
|
->field('id as task_id,icon,task_name,target_quantity,task_type,jump_type,tasks_bag_id')
|
|
|
|
|
|
->where('delete_time',0)
|
|
|
|
|
|
->where('is_active',1)
|
2025-12-12 10:32:25 +08:00
|
|
|
|
->order('sort desc,id asc')->select();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
|
|
//完成进度
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$v['from_id'] = 0;
|
|
|
|
|
|
$v['is_time'] = 0;
|
|
|
|
|
|
//奖励详情
|
|
|
|
|
|
$v['reward_str'] = "";
|
2025-12-12 15:23:20 +08:00
|
|
|
|
if($v['task_id'] != 1){
|
|
|
|
|
|
$reward_info = db::name('vs_gift_bag_detail')->where('gift_bag_id',$v['tasks_bag_id'])->select();
|
|
|
|
|
|
foreach ($reward_info as $key => $value) {
|
|
|
|
|
|
if($value['type'] == 1){
|
|
|
|
|
|
$reward_name = $value['quantity'].$value['name'];
|
|
|
|
|
|
}elseif($value['type'] == 2){
|
|
|
|
|
|
$reward_name = $value['name'].'x'.$value['quantity'];
|
|
|
|
|
|
}elseif($value['type'] == 3){
|
|
|
|
|
|
$reward_name = $value['name'].'x'.$value['days'].'天';
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$reward_name = $value['quantity'].$value['name'];
|
|
|
|
|
|
}
|
|
|
|
|
|
$v['reward_str'] =$v['reward_str'].$reward_name." ";
|
2025-12-11 17:12:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-11 18:30:33 +08:00
|
|
|
|
if($v['task_type'] == 2){
|
2025-12-10 18:44:16 +08:00
|
|
|
|
//今日完成进度
|
|
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')
|
|
|
|
|
|
->where('user_id',$user_id)
|
|
|
|
|
|
->where('task_id',$v['task_id'])
|
|
|
|
|
|
->whereTime('createtime', 'today')
|
|
|
|
|
|
->find();
|
2025-12-11 18:30:33 +08:00
|
|
|
|
}else{
|
2025-12-30 18:05:07 +08:00
|
|
|
|
if(isset($user_ids) && $v['task_type'] == 1 && count($user_ids)>1){
|
2025-12-30 16:45:30 +08:00
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->whereIn('user_id',$user_ids)->where('task_id',$v['task_id'])->find();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->where('user_id',$user_id)->where('task_id',$v['task_id'])->find();
|
|
|
|
|
|
}
|
2025-12-11 18:30:33 +08:00
|
|
|
|
if($v['jump_type']==4){
|
|
|
|
|
|
//跳转的房间路径
|
|
|
|
|
|
$v['from_id'] = model('api/Room')->task_jump_room_recommend($v['task_id']);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(in_array($v['task_id'],[21,22,23])){
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$sign_student_list = [];
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$first_sign_student_list = db::name('vs_tasks_student')
|
|
|
|
|
|
->where('user_id',$user_id)
|
|
|
|
|
|
->where('task_id',$v['task_id'])
|
|
|
|
|
|
->where('delete_time', 0)
|
|
|
|
|
|
->select();
|
|
|
|
|
|
if(empty($first_sign_student_list)){
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
//徒弟列表
|
|
|
|
|
|
foreach ($first_sign_student_list as $key => $value) {
|
2025-12-11 18:30:33 +08:00
|
|
|
|
if($v['task_id'] == 21){
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$title = "拍卖房停留({$value['value']} / {$v['target_quantity']})分钟";
|
2025-12-11 18:30:33 +08:00
|
|
|
|
}elseif($v['task_id'] == 22){
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$title = "点唱房点歌({$value['value']} / {$v['target_quantity']})首";
|
2025-12-11 18:30:33 +08:00
|
|
|
|
}elseif($v['task_id'] == 23){
|
2025-12-12 19:09:21 +08:00
|
|
|
|
$title = "互娱房停留({$value['value']} / {$v['target_quantity']})分钟";
|
2025-12-11 17:12:15 +08:00
|
|
|
|
}
|
2025-12-11 18:30:33 +08:00
|
|
|
|
$sign_student_list[$i]['task_id'] = $v['task_id'];
|
|
|
|
|
|
$sign_student_list[$i]['icon'] = "";
|
|
|
|
|
|
$sign_student_list[$i]['target_quantity'] = $v['target_quantity'];
|
|
|
|
|
|
$sign_student_list[$i]['task_type'] = $v['task_type'];
|
|
|
|
|
|
$sign_student_list[$i]['jump_type'] = $v['jump_type'];
|
|
|
|
|
|
$sign_student_list[$i]['tasks_bag_id'] = $v['tasks_bag_id'];
|
|
|
|
|
|
$sign_student_list[$i]['student_id'] = $value['student_id'];
|
|
|
|
|
|
$student_nickname = db::name('user')->where('id',$value['student_id'])->value('nickname');
|
2025-12-12 14:24:38 +08:00
|
|
|
|
$sign_student_list[$i]['task_name'] = '邀请 '.$student_nickname." 徒弟在 {$title},并送给徒弟特殊礼物";
|
2025-12-11 18:30:33 +08:00
|
|
|
|
$sign_student_list[$i]['reward_str'] = $v['reward_str'];
|
|
|
|
|
|
$sign_student_list[$i]['from_id'] = model('api/Room')->task_jump_room_recommend($v['task_id'],$value['student_id']);
|
2025-12-11 18:41:01 +08:00
|
|
|
|
if($value['status']==0){
|
2025-12-11 18:39:11 +08:00
|
|
|
|
$sign_student_list[$i]['task_status'] = 1;
|
|
|
|
|
|
$sign_student_list[$i]['task_type_str'] = "去完成";
|
2025-12-11 18:41:01 +08:00
|
|
|
|
}elseif($value['status']==1){
|
|
|
|
|
|
$sign_student_list[$i]['task_status'] = 2;
|
|
|
|
|
|
$sign_student_list[$i]['task_type_str'] = "领取奖励";
|
|
|
|
|
|
}else{
|
2025-12-11 18:39:11 +08:00
|
|
|
|
$sign_student_list[$i]['task_status'] = 3;
|
|
|
|
|
|
$sign_student_list[$i]['task_type_str'] = "已领取";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-11 18:30:33 +08:00
|
|
|
|
$i++;
|
2025-12-11 17:12:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-12 15:23:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
if($v['task_id'] == 24){
|
2025-12-10 18:44:16 +08:00
|
|
|
|
//师徒任务
|
|
|
|
|
|
//师傅签约返还
|
|
|
|
|
|
$user_sign_task = Db::name('vs_user_sign_task')->where(['user_id'=>$user_id,'day'=>date('Y-m-d')])->find();
|
|
|
|
|
|
if(empty($user_sign_task)){
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-12-25 12:32:47 +08:00
|
|
|
|
$user_sign_task_count = Db::name('vs_user_sign_task')->where(['user_id'=>$user_id])->count();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
$v['gold_reward'] = $user_sign_task['value'];
|
2025-12-25 12:32:47 +08:00
|
|
|
|
$v['target_quantity'] = $v['target_quantity'] * $user_sign_task_count;
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$v['is_time'] = 1;
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if($user_sign_task['status']==1){
|
|
|
|
|
|
$progress = $user_sign_task['times'] ?? 0;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$progress = $user_sign_task['times']-1 ?? 0;
|
|
|
|
|
|
}
|
2025-12-25 12:50:41 +08:00
|
|
|
|
if($user_sign_task['status']==1){
|
2025-12-25 12:32:47 +08:00
|
|
|
|
$v['task_status'] = 3;
|
|
|
|
|
|
$v['task_type_str'] = "已领取";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$v['task_status'] = 2;
|
|
|
|
|
|
$v['task_type_str'] = "领取奖励";
|
|
|
|
|
|
}
|
2025-12-25 13:01:25 +08:00
|
|
|
|
$v['reward_str'] = $user_sign_task['value']." 个钻石";
|
2025-12-25 12:32:47 +08:00
|
|
|
|
}elseif(in_array($v['task_id'],[26,27,28,29,30,31,32])){
|
2025-12-12 15:23:20 +08:00
|
|
|
|
$user_couple_times =[26=>1,27=>2,28=>3,29=>4,30=>5,31=>6,32=>7];
|
|
|
|
|
|
//情侣任务
|
2025-12-12 20:41:18 +08:00
|
|
|
|
$user_couple_task = Db::name('vs_user_cp_task')->where(['user_id'=>$user_id,'times'=>$user_couple_times[$v['task_id']],'delete_time'=>0])->find();
|
2025-12-12 15:23:20 +08:00
|
|
|
|
if(empty($user_couple_task)){
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-12-12 18:35:16 +08:00
|
|
|
|
$v['task_name'] = "第{$user_couple_times[$v['task_id']]}天:情侣等级提升 ({$user_couple_task['need_exp_value']})经验值,并在某一房间共同相处{$user_couple_task['need_time_value']}分钟";
|
2025-12-12 15:23:20 +08:00
|
|
|
|
if($user_couple_task['status'] ==0 && $user_couple_task['day']==date('Y-m-d')){
|
|
|
|
|
|
$v['task_status'] = 1;
|
|
|
|
|
|
$v['task_type_str'] = "待完成";
|
|
|
|
|
|
}elseif($user_couple_task['status'] ==1){
|
|
|
|
|
|
$v['task_status'] = 2;
|
|
|
|
|
|
$v['task_type_str'] = "领取奖励";
|
2025-12-12 18:59:38 +08:00
|
|
|
|
}elseif($user_couple_task['status'] ==2){
|
|
|
|
|
|
$v['task_status'] = 3;
|
|
|
|
|
|
$v['task_type_str'] = "已领取";
|
2025-12-12 15:23:20 +08:00
|
|
|
|
}else{
|
2025-12-12 18:09:07 +08:00
|
|
|
|
$v['task_status'] = 1;
|
2025-12-12 18:04:27 +08:00
|
|
|
|
$v['task_type_str'] = "未完成";
|
2025-12-12 15:23:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}elseif($v['task_id']==1){//每日签到处理
|
2025-12-12 10:32:25 +08:00
|
|
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d'),'delete_time'=>0])->find();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if ($sign_in_info) {
|
|
|
|
|
|
$v['task_status'] =3;
|
|
|
|
|
|
$v['task_type_str'] = "已签到";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$v['task_status'] = 1;
|
|
|
|
|
|
$v['task_type_str'] = "去签到";
|
|
|
|
|
|
}
|
2025-12-12 15:23:20 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
//处理状态
|
|
|
|
|
|
$v['task_status'] = 1;
|
|
|
|
|
|
$v['task_type_str'] = "去完成";
|
|
|
|
|
|
if(isset($user_daily_tasks['is_completed']) && $user_daily_tasks['is_completed'] ==1){ //已完成
|
|
|
|
|
|
$v['task_status'] = 2;
|
|
|
|
|
|
$v['task_type_str'] = "领取奖励";
|
|
|
|
|
|
}
|
|
|
|
|
|
if(isset($user_daily_tasks['is_claimed']) && $user_daily_tasks['is_claimed'] ==1){ //已完成
|
|
|
|
|
|
$v['task_status'] = 3;
|
|
|
|
|
|
$v['task_type_str'] = "已领取";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if($v['task_id'] != 24) {
|
|
|
|
|
|
$progress = isset($user_daily_tasks['current_progress']) ? $user_daily_tasks['current_progress'] : 0;
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-12 15:23:20 +08:00
|
|
|
|
$quantity_str = "";
|
|
|
|
|
|
if($v['target_quantity']!=1){
|
2025-12-12 19:52:41 +08:00
|
|
|
|
if($progress > $v['target_quantity']){
|
|
|
|
|
|
$progress = $v['target_quantity'];
|
|
|
|
|
|
}
|
2025-12-12 15:23:20 +08:00
|
|
|
|
$quantity_str= "({$progress}/{$v['target_quantity']})";
|
|
|
|
|
|
}
|
|
|
|
|
|
$v['task_name'] = $v['task_name'].$quantity_str;
|
2025-12-11 09:26:35 +08:00
|
|
|
|
$v['jump_type_str'] = $this->jump_type[$v['jump_type']];
|
2025-12-10 18:44:16 +08:00
|
|
|
|
//返回任务列表
|
2025-12-11 18:30:33 +08:00
|
|
|
|
if($v['task_type']!=4){
|
|
|
|
|
|
$reslut['tasks'][$v['task_type']-1]['task_list'][] = $v;
|
|
|
|
|
|
}else{
|
2025-12-24 20:21:54 +08:00
|
|
|
|
if($v['task_id'] == 24){
|
|
|
|
|
|
$reslut['tasks'][$v['task_type']-1]['task_list'][] = $v;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
if(!empty($sign_student_list)){
|
|
|
|
|
|
foreach ($sign_student_list as $key => $value) {
|
|
|
|
|
|
$reslut['tasks'][$v['task_type']-1]['task_list'][] = $value;
|
|
|
|
|
|
}
|
2025-12-11 18:30:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-16 10:57:25 +08:00
|
|
|
|
foreach ($reslut['tasks'] as &$value) {
|
|
|
|
|
|
if(empty($value['task_list'])){
|
|
|
|
|
|
$value['is_lock'] = 1;
|
|
|
|
|
|
}
|
2025-12-21 12:01:28 +08:00
|
|
|
|
$value['wait_reward_num'] = 0;
|
|
|
|
|
|
//待领取数量
|
|
|
|
|
|
foreach ($value['task_list'] as &$v) {
|
|
|
|
|
|
if($v['task_status'] == 2){
|
|
|
|
|
|
$value['wait_reward_num'] = $value['wait_reward_num']+1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//排序 $v['task_status'] 字段按照 [2 1 3]
|
|
|
|
|
|
usort($value['task_list'], function ($a, $b) {
|
|
|
|
|
|
$order = [2 => 0, 1 => 1, 3 => 2];
|
|
|
|
|
|
return $order[$a['task_status']] - $order[$b['task_status']];
|
|
|
|
|
|
});
|
2025-12-16 10:57:25 +08:00
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
return ['code' => 1, 'msg' => '获取成功', 'data' => $reslut];
|
|
|
|
|
|
}
|
|
|
|
|
|
//完成每日任务
|
2025-12-11 17:12:15 +08:00
|
|
|
|
public function tasks_complete($user_id,$task_id,$ext_value='',$student_id = 0){
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if($task_id ==15){
|
|
|
|
|
|
$current_progress = $ext_value!='' ? $ext_value : 1;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$current_progress =1;
|
|
|
|
|
|
}
|
|
|
|
|
|
//查询任务
|
2025-12-11 17:28:57 +08:00
|
|
|
|
$task_info = Db::name('vs_tasks')->where('id',$task_id)->where('delete_time',0)->where('is_active',1)->find();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if(empty($task_info)){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '任务不存在或已删除','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
//查询用户每日任务进度表
|
|
|
|
|
|
if($task_info['task_type']==2){
|
|
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->where('user_id',$user_id)->where('task_id',$task_id)->whereTime('createtime', 'today')->find();
|
|
|
|
|
|
}else{
|
2025-12-30 16:45:30 +08:00
|
|
|
|
if($task_info['task_type'] == 1){
|
|
|
|
|
|
//判断用户是否实名认证,并查询用户手机号下的用户
|
|
|
|
|
|
$is_real = model('UserData')->real_name_info($user_id);
|
|
|
|
|
|
if($is_real['code']==1){
|
|
|
|
|
|
if($is_real['data']['is_real'] ==1){
|
2025-12-30 22:14:42 +08:00
|
|
|
|
$user_ids = db::name('user')->where('mobile',$is_real['data']['mobile'])->column('id');
|
2025-12-30 16:45:30 +08:00
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->whereIn('user_id',$user_ids)->where('task_id',$task_id)->find();
|
|
|
|
|
|
if($user_daily_tasks){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '您已完成该任务','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->where('user_id', $user_id)->where('task_id', $task_id)->find();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-11 19:16:19 +08:00
|
|
|
|
$is_completed = 0;
|
2025-12-18 16:30:46 +08:00
|
|
|
|
$completion_time = null;
|
2025-12-11 17:12:15 +08:00
|
|
|
|
if(in_array($task_id,[21,22,23])){
|
|
|
|
|
|
$task_student_data =[];
|
|
|
|
|
|
$task_student = Db::name('vs_tasks_student')->where(['user_id'=>$user_id,'task_id'=>$task_id,'student_id'=>$student_id,'status'=>0,'delete_time'=>0])->find();
|
|
|
|
|
|
if(empty($task_student)){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '任务不存在或已删除','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if($ext_value==1){
|
2025-12-11 20:17:22 +08:00
|
|
|
|
if($task_info['target_quantity'] <= $task_student['value']){
|
2025-12-11 20:07:44 +08:00
|
|
|
|
return ['code' => 1, 'msg' => '操作成功','data' => ['is_completed'=>1]];
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$current_progress = $task_student['value']+1;
|
|
|
|
|
|
if($task_info['target_quantity']==$current_progress && $task_student['is_reward']==1){
|
|
|
|
|
|
$task_student_data['status'] = 1;
|
|
|
|
|
|
$is_completed = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
$task_student_data['value'] = $current_progress;
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-11 20:07:44 +08:00
|
|
|
|
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}else{
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$current_progress = $task_student['value'];
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if($task_info['target_quantity']==$current_progress){
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$task_student_data['status'] = 1;
|
2025-12-11 19:16:19 +08:00
|
|
|
|
$is_completed = 1;
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$task_student_data['is_reward'] = 1;
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-26 14:02:32 +08:00
|
|
|
|
$task_student_data['updatetime'] = time();
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$reslut = Db::name('vs_tasks_student')->where('id',$task_student['id'])->update($task_student_data);
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}else{
|
2025-12-26 14:02:32 +08:00
|
|
|
|
if ($user_daily_tasks && $user_daily_tasks['is_completed'] == 1) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '您已完成该任务','data' => null];
|
|
|
|
|
|
}
|
2025-12-11 17:12:15 +08:00
|
|
|
|
if ($user_daily_tasks) {
|
2025-12-12 20:14:22 +08:00
|
|
|
|
if($user_daily_tasks['current_progress'] > $task_info['target_quantity']){
|
|
|
|
|
|
$current_progress = $task_info['target_quantity'];
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$current_progress = $user_daily_tasks['current_progress'] +$current_progress;
|
|
|
|
|
|
}
|
|
|
|
|
|
if($task_info['target_quantity']==$current_progress){
|
|
|
|
|
|
$is_completed = 1;
|
2025-12-18 16:30:46 +08:00
|
|
|
|
$completion_time = time();
|
2025-12-12 20:14:22 +08:00
|
|
|
|
}
|
2025-12-11 17:12:15 +08:00
|
|
|
|
$reslut = Db::name('vs_tasks_user_daily')->where('id',$user_daily_tasks['id'])->update([
|
|
|
|
|
|
'current_progress' => $current_progress,
|
|
|
|
|
|
'is_completed'=> $is_completed,
|
|
|
|
|
|
'ext' => $ext_value,
|
2025-12-18 16:30:46 +08:00
|
|
|
|
'completion_time' => $completion_time,
|
2025-12-11 17:12:15 +08:00
|
|
|
|
]);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
if($task_info['target_quantity'] == 1){
|
|
|
|
|
|
$is_completed = 1;
|
2025-12-18 16:30:46 +08:00
|
|
|
|
$completion_time = time();
|
2025-12-11 17:12:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
$reslut = Db::name('vs_tasks_user_daily')->insert([
|
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
|
'task_id' => $task_id,
|
|
|
|
|
|
'current_progress' => $current_progress,
|
|
|
|
|
|
'tasks_bag_id' => $task_info['tasks_bag_id'],
|
|
|
|
|
|
'is_completed' => $is_completed,
|
|
|
|
|
|
'ext' => $ext_value,
|
|
|
|
|
|
'createtime' => time(),
|
2025-12-18 16:30:46 +08:00
|
|
|
|
'completion_time' => $completion_time,
|
2025-12-11 17:12:15 +08:00
|
|
|
|
]);
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-11 17:12:15 +08:00
|
|
|
|
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if ($reslut) {
|
|
|
|
|
|
if($is_completed==1){
|
2025-12-12 23:15:01 +08:00
|
|
|
|
if(in_array($task_id,[16,13,21,22,23])){
|
|
|
|
|
|
model('Tasks')->tasks_complete($user_id,17);
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
return ['code' => 1, 'msg' => '操作成功','data' => ['is_completed'=>1]];
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return ['code' => 1, 'msg' => '操作成功','data' => ['is_completed'=>0]];
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//领取每日任务奖励
|
2025-12-11 17:12:15 +08:00
|
|
|
|
public function daily_tasks_receive($user_id,$task_id,$student_id = 0){
|
2025-12-10 18:44:16 +08:00
|
|
|
|
//查询是否实名认证
|
|
|
|
|
|
$is_real = model('UserData')->real_name_info($user_id);
|
|
|
|
|
|
if($is_real['code']==0){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '请先实名认证','data' => null];
|
|
|
|
|
|
}else{
|
|
|
|
|
|
if($is_real['data']['is_real'] !=1){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '请先实名认证','data' => null];
|
2025-12-30 16:45:30 +08:00
|
|
|
|
}else{
|
2025-12-30 22:14:42 +08:00
|
|
|
|
$user_ids = db::name('user')->where('mobile',$is_real['data']['mobile'])->column('id');
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-11 17:28:57 +08:00
|
|
|
|
$task_info = Db::name('vs_tasks')->where('id',$task_id)->find();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if (!$task_info) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '任务不存在','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if($task_id==24){
|
|
|
|
|
|
//师徒任务
|
|
|
|
|
|
//师傅签约返还
|
|
|
|
|
|
$user_sign_task = Db::name('vs_user_sign_task')->where(['user_id'=>$user_id,'day'=>date('Y-m-d')])->find();
|
|
|
|
|
|
if (!$user_sign_task) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '任务不存在或已结束','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if($user_sign_task['status']==1){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '您已领取该奖励','data' => null];
|
|
|
|
|
|
}
|
2025-12-11 17:12:15 +08:00
|
|
|
|
}elseif(in_array($task_id,[21,22,23])){
|
|
|
|
|
|
if($student_id){
|
|
|
|
|
|
$task_student = Db::name('vs_tasks_student')->where(['user_id'=>$user_id,'task_id'=>$task_id,'student_id'=>$student_id,'status'=>1,'delete_time'=>0])->find();
|
|
|
|
|
|
if (!$task_student) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '任务不存在或已结束','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return ['code' => 0, 'msg' => '任务不存在','data' => null];
|
|
|
|
|
|
}
|
2025-12-12 15:23:20 +08:00
|
|
|
|
}elseif(in_array($task_id,[26,27,28,29,30,31,32])){
|
|
|
|
|
|
$user_couple_times =[26=>1,27=>2,28=>3,29=>4,30=>5,31=>6,32=>7];
|
|
|
|
|
|
//情侣任务
|
2025-12-12 20:41:18 +08:00
|
|
|
|
$user_couple_task = Db::name('vs_user_cp_task')->where(['user_id'=>$user_id,'times'=>$user_couple_times[$task_id],'delete_time'=>0])->find();
|
2025-12-12 15:23:20 +08:00
|
|
|
|
if (!$user_couple_task) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '任务不存在或已结束','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($user_couple_task['status'] == 2) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '您已领取该奖励','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($user_couple_task['status'] == 0) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '请先去完成该任务再领取','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if($user_couple_task['day'] != date('Y-m-d')){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '已过期或未到领取时间','data' => null];
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
if($task_info['task_type']==2){
|
2025-12-11 19:46:19 +08:00
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->where('user_id',$user_id)->where('task_id',$task_id)->whereTime('createtime', 'today')->find();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}else{
|
2025-12-30 18:05:07 +08:00
|
|
|
|
if(isset($user_ids) && $task_info['task_type'] == 1 && count($user_ids)>1){
|
2025-12-30 16:45:30 +08:00
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->whereIn('user_id',$user_ids)->where('task_id',$task_id)->find();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$user_daily_tasks = Db::name('vs_tasks_user_daily')->where('user_id',$user_id)->where('task_id',$task_id)->find();
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (!$user_daily_tasks) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '请完成该任务','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($user_daily_tasks['is_completed'] == 0) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '请完成该任务','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($user_daily_tasks['is_claimed'] == 1) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '您已领取该奖励','data' => null];
|
|
|
|
|
|
}
|
2025-12-30 16:45:30 +08:00
|
|
|
|
if($user_daily_tasks['user_id'] != $user_id && $task_info['task_type']== 1){
|
|
|
|
|
|
return ['code' => 0, 'msg' => '请用您的另一个实名认证账号领取,此账号无权领取','data' => null];
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
2025-12-30 16:45:30 +08:00
|
|
|
|
|
|
|
|
|
|
// 使用更严格的事务处理,统一加锁顺序
|
|
|
|
|
|
$lockKey = 'task_receive_' . $user_id . '_' . $task_id . ($student_id ? '_' . $student_id : '');
|
|
|
|
|
|
$lock = cache($lockKey);
|
|
|
|
|
|
if ($lock) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '操作过于频繁,请稍后再试','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
cache($lockKey, 1, 2); // 2秒锁
|
2025-12-12 18:56:08 +08:00
|
|
|
|
try {
|
2025-12-30 16:45:30 +08:00
|
|
|
|
Db::startTrans();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if($task_id==24){
|
|
|
|
|
|
//师徒任务
|
|
|
|
|
|
$reslut = Db::name('vs_user_sign_task')->where('id',$user_sign_task['id'])->update([
|
|
|
|
|
|
'status' => 1
|
|
|
|
|
|
]);
|
|
|
|
|
|
if (!$reslut) {
|
|
|
|
|
|
Db::rollback();
|
2025-12-30 16:45:30 +08:00
|
|
|
|
cache($lockKey, null);
|
2025-12-10 18:44:16 +08:00
|
|
|
|
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
|
|
|
|
|
}
|
2025-12-18 16:30:46 +08:00
|
|
|
|
Db::name('vs_tasks_user_daily')->insert([
|
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
|
'task_id' => $task_id,
|
|
|
|
|
|
'tasks_bag_id' => $task_info['tasks_bag_id'],
|
|
|
|
|
|
'is_completed' => 1,
|
|
|
|
|
|
'is_claimed' => 1,
|
|
|
|
|
|
'createtime' => time(),
|
|
|
|
|
|
'completion_time' => $user_sign_task['createtime'],
|
|
|
|
|
|
'collection_time' => time(),
|
|
|
|
|
|
]);
|
2025-12-12 15:23:20 +08:00
|
|
|
|
}elseif(in_array($task_id,[21,22,23])) {
|
|
|
|
|
|
$reslut = Db::name('vs_tasks_student')->where('id', $task_student['id'])->update([
|
|
|
|
|
|
'status' => 2,
|
|
|
|
|
|
'updatetime' => time(),
|
|
|
|
|
|
]);
|
2025-12-18 16:30:46 +08:00
|
|
|
|
Db::name('vs_tasks_user_daily')->insert([
|
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
|
'task_id' => $task_id,
|
|
|
|
|
|
'tasks_bag_id' => $task_info['tasks_bag_id'],
|
|
|
|
|
|
'is_completed' => 1,
|
|
|
|
|
|
'is_claimed' => 1,
|
|
|
|
|
|
'createtime' => time(),
|
|
|
|
|
|
'completion_time' => $task_student['createtime'],
|
|
|
|
|
|
'collection_time' => time(),
|
|
|
|
|
|
]);
|
2025-12-12 15:23:20 +08:00
|
|
|
|
}elseif(in_array($task_id,[26,27,28,29,30,31,32])){
|
|
|
|
|
|
$reslut = Db::name('vs_user_cp_task')->where(['id'=>$user_couple_task['id']])->update([
|
2025-12-12 18:55:50 +08:00
|
|
|
|
'status' => 2
|
2025-12-11 17:12:15 +08:00
|
|
|
|
]);
|
2025-12-18 16:30:46 +08:00
|
|
|
|
Db::name('vs_tasks_user_daily')->insert([
|
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
|
'task_id' => $task_id,
|
|
|
|
|
|
'tasks_bag_id' => $task_info['tasks_bag_id'],
|
|
|
|
|
|
'is_completed' => 1,
|
|
|
|
|
|
'is_claimed' => 1,
|
|
|
|
|
|
'createtime' => time(),
|
|
|
|
|
|
'completion_time' => $user_couple_task['createtime'],
|
|
|
|
|
|
'collection_time' => time(),
|
|
|
|
|
|
]);
|
2025-12-11 19:54:42 +08:00
|
|
|
|
} else{
|
|
|
|
|
|
$reslut = Db::name('vs_tasks_user_daily')->where('id',$user_daily_tasks['id'])->update([
|
2025-12-10 18:44:16 +08:00
|
|
|
|
'is_claimed' => 1,
|
2025-12-18 16:30:46 +08:00
|
|
|
|
'collection_time' => time(),
|
2025-12-10 18:44:16 +08:00
|
|
|
|
]);
|
|
|
|
|
|
if (!$reslut) {
|
|
|
|
|
|
Db::rollback();
|
2025-12-30 16:45:30 +08:00
|
|
|
|
cache($lockKey, null);
|
2025-12-10 18:44:16 +08:00
|
|
|
|
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-25 12:32:47 +08:00
|
|
|
|
//24不发礼包
|
|
|
|
|
|
if($task_id!=24){
|
|
|
|
|
|
//发放任务礼包
|
|
|
|
|
|
$op_bag_re = $this->open_tasks_bag($user_id,$task_info['tasks_bag_id']);
|
|
|
|
|
|
if ($op_bag_re['code'] != 1) {
|
|
|
|
|
|
Db::rollback();
|
2025-12-30 16:45:30 +08:00
|
|
|
|
cache($lockKey, null);
|
2025-12-25 12:32:47 +08:00
|
|
|
|
return ['code' => 0, 'msg' => $op_bag_re['msg'], 'data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
//24发钻石
|
|
|
|
|
|
//发放钻石
|
|
|
|
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $user_sign_task['value'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::SIGN_MASTER_DAILY_RETURN,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::SIGN_MASTER_DAILY_RETURN)." 第".$user_sign_task['times']."天");
|
|
|
|
|
|
if ($res['code'] != 1) {
|
|
|
|
|
|
Db::rollback();
|
2025-12-30 16:45:30 +08:00
|
|
|
|
cache($lockKey, null);
|
2025-12-25 12:32:47 +08:00
|
|
|
|
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 提交事务
|
|
|
|
|
|
Db::commit();
|
2025-12-30 16:45:30 +08:00
|
|
|
|
cache($lockKey, null);
|
2025-12-10 18:44:16 +08:00
|
|
|
|
return ['code' => 1, 'msg' => "领取成功", 'data' => null];
|
2025-12-12 18:56:08 +08:00
|
|
|
|
}catch (\Exception $e) {
|
|
|
|
|
|
// 回滚事务
|
|
|
|
|
|
Db::rollback();
|
2025-12-30 16:45:30 +08:00
|
|
|
|
cache($lockKey, null);
|
2025-12-12 18:56:08 +08:00
|
|
|
|
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//任务礼盒发放
|
|
|
|
|
|
public function open_tasks_bag($user_id,$gift_box_id){
|
|
|
|
|
|
$gift_box_info = Db::name('vs_gift_bag')->where('id',$gift_box_id)->find();
|
|
|
|
|
|
if (!$gift_box_info) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
//查询礼盒详情
|
|
|
|
|
|
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_box_id])->select();
|
|
|
|
|
|
if (!$gift_bag_detail) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '礼包未配置','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach ($gift_bag_detail as $k=>$v){
|
|
|
|
|
|
switch ($v['type']) {
|
|
|
|
|
|
case 1: //金币 方法1:直接添加到用户钱包
|
2025-12-11 20:47:25 +08:00
|
|
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::DAILY_TASKS_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DAILY_TASKS_REWARD));
|
2025-12-10 18:44:16 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 2: //礼物 方法2:添加到用户礼物背包
|
2025-12-12 11:38:09 +08:00
|
|
|
|
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::TASK_REWARD,"完成任务获得礼物");
|
2025-12-10 18:44:16 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 3: //坐骑 方法3:添加到用户装扮
|
|
|
|
|
|
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
|
|
|
|
|
if(empty($decorate_price_info)){
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-12-11 20:40:32 +08:00
|
|
|
|
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],10);
|
2025-12-10 18:44:16 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 4: //道具 方法5:钻石
|
2025-12-11 20:47:25 +08:00
|
|
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::DAILY_TASKS_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DAILY_TASKS_REWARD));
|
2025-12-10 18:44:16 +08:00
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($res['code'] != 1) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
// 记录日志
|
|
|
|
|
|
//添加礼盒记录
|
2025-12-30 19:57:54 +08:00
|
|
|
|
$reslut = Db::name('vs_gift_bag_receive_tasks_log')->insert([
|
2025-12-10 18:44:16 +08:00
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
|
'gift_bag_id' => $gift_box_id,
|
|
|
|
|
|
'parent_id' => $v['id'],
|
|
|
|
|
|
'gift_id'=> $v['foreign_id'],
|
2025-12-30 19:57:54 +08:00
|
|
|
|
'type' => $v['type'],
|
2025-12-10 18:44:16 +08:00
|
|
|
|
'num' => $v['quantity'],
|
|
|
|
|
|
'bag_price' => $gift_box_info['money'],
|
|
|
|
|
|
'gift_price' => $v['gold'],
|
|
|
|
|
|
'createtime' => time(),
|
|
|
|
|
|
'updatetime' => time()
|
|
|
|
|
|
]);
|
|
|
|
|
|
if (!$reslut) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 开启礼盒
|
|
|
|
|
|
* $user_id 用户id
|
|
|
|
|
|
* $gift_box_id 礼盒id
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function open_gift_box($user_id,$gift_box_id){
|
|
|
|
|
|
$gift_box_info = Db::name('vs_gift_bag')->where('id',$gift_box_id)->find();
|
|
|
|
|
|
if (!$gift_box_info) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '礼盒不存在','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
$ext = json_decode($gift_box_info['ext'],true);
|
|
|
|
|
|
$gift_bag_receive_num = Db::name('vs_gift_bag_receive_log')->where('user_id',$user_id)->where('gift_bag_id',$gift_box_id)->whereTime('createtime', 'today')->count();
|
|
|
|
|
|
if ($gift_bag_receive_num >= $ext['num']) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '您已领取该礼盒','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
//查询礼盒详情
|
|
|
|
|
|
$user_gift_box_details = db::name("vs_gift_bag_detail")->where('gift_bag_id',$gift_box_id)->orderRaw('rand()')->find();
|
|
|
|
|
|
if (!$user_gift_box_details) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '礼盒不存在','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
|
try {
|
|
|
|
|
|
switch ($user_gift_box_details['type']) {
|
|
|
|
|
|
case 1: //金币 方法1:直接添加到用户钱包
|
|
|
|
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $user_gift_box_details['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::GIFT_BOX_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::GIFT_BOX_REWARD));
|
|
|
|
|
|
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['gold']."金币";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2: //礼物 方法2:添加到用户礼物背包
|
|
|
|
|
|
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$user_gift_box_details['foreign_id'],$user_gift_box_details['quantity'],model('UserGiftPack')::GIFT_PACK_GET,$gift_box_info['name']);
|
|
|
|
|
|
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['quantity']."X".$user_gift_box_details['name'];
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3: //坐骑 方法3:添加到用户装扮
|
|
|
|
|
|
$res = model('Decorate')->pay_decorate($user_id,$user_gift_box_details['foreign_id'],$user_gift_box_details['days'],3);
|
|
|
|
|
|
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['quantity']."天".$user_gift_box_details['name'];
|
|
|
|
|
|
break;
|
|
|
|
|
|
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_box_id,
|
|
|
|
|
|
'parent_id' => $user_gift_box_details['id'],
|
|
|
|
|
|
'gift_id' => $user_gift_box_details['foreign_id'],
|
|
|
|
|
|
'num' => $user_gift_box_details['quantity'],
|
|
|
|
|
|
'gift_price' => $user_gift_box_details['gold'],
|
|
|
|
|
|
'bag_price' => $ext['meet'],
|
|
|
|
|
|
'createtime' => time(),
|
|
|
|
|
|
'updatetime' => time()
|
|
|
|
|
|
]);
|
|
|
|
|
|
if ($reslut) {
|
|
|
|
|
|
// 提交事务
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
|
return ['code' => 1, 'msg' => '操作成功','data' => $return_data];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Db::rollback();
|
|
|
|
|
|
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch (\Exception $e) {
|
|
|
|
|
|
// 回滚事务
|
|
|
|
|
|
Db::rollback();
|
|
|
|
|
|
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 礼盒记录
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function gift_bag_receive_list($user_id){
|
|
|
|
|
|
//查询每日任务礼盒记录
|
|
|
|
|
|
$gift_bag_receive_list = Db::name('vs_gift_bag_receive_log')
|
|
|
|
|
|
->field('bag.name as gift_bag_name,re.createtime as createtime,de.name as gift_name,de.quantity,de.type,de.foreign_id,de.days,de.gold')
|
|
|
|
|
|
->alias('re')
|
|
|
|
|
|
->join('vs_gift_bag bag', 'bag.id = re.gift_bag_id', 'LEFT')
|
|
|
|
|
|
->join('vs_gift_bag_detail de', 'de.id = re.parent_id', 'LEFT')
|
|
|
|
|
|
->where(['re.user_id'=>$user_id,'bag.activities_id'=>2,'bag.status'=>1])
|
|
|
|
|
|
->order('re.createtime desc')
|
|
|
|
|
|
->select();
|
|
|
|
|
|
if (!$gift_bag_receive_list) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '没有礼盒记录','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
$result = [];
|
|
|
|
|
|
foreach ($gift_bag_receive_list as $k=>$v){
|
|
|
|
|
|
$result[$k]['gift_bag_name'] = $v['gift_bag_name'];
|
|
|
|
|
|
if($v['type'] == 1){
|
|
|
|
|
|
$result[$k]['gift_name'] = $v['gold'].'金币';
|
|
|
|
|
|
}elseif ($v['type'] == 2){
|
|
|
|
|
|
$result[$k]['gift_name'] = $v['gift_name'].' x '.$v['quantity'];
|
|
|
|
|
|
}elseif ($v['type'] == 3){
|
|
|
|
|
|
$result[$k]['gift_name'] = $v['gift_name'].' x '.$v['days'].'天';
|
|
|
|
|
|
}
|
|
|
|
|
|
$result[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
|
|
|
|
|
}
|
|
|
|
|
|
return ['code' => 1, 'msg' => '操作成功','data' => $result];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 用户签到
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function sign_in($user_id){
|
2025-12-12 10:32:25 +08:00
|
|
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d'),'delete_time'=>0])->find();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if ($sign_in_info) {
|
|
|
|
|
|
return ['code' => 0, 'msg' => '今天已经签到过了','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
|
try {
|
|
|
|
|
|
//每日签到 【完成任务】
|
|
|
|
|
|
$this->tasks_complete($user_id,1);
|
|
|
|
|
|
//判断连续签到
|
|
|
|
|
|
$continuous = 1;
|
2025-12-12 10:32:25 +08:00
|
|
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'delete_time'=>0])->order('id desc')->find();
|
2025-12-10 18:44:16 +08:00
|
|
|
|
if ($sign_in_info) {
|
|
|
|
|
|
if ($sign_in_info['sign_in_date'] == date('Y-m-d',strtotime('-1 day'))) {
|
|
|
|
|
|
$continuous = $sign_in_info['continuous'] + 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$continuous = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$reslut = Db::name('vs_user_tasks_sign_in')->insert([
|
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
|
'sign_in_date' => date('Y-m-d'),
|
|
|
|
|
|
'continuous' => $continuous,
|
|
|
|
|
|
'createtime' => time(),
|
|
|
|
|
|
'updatetime' => time()
|
|
|
|
|
|
]);
|
|
|
|
|
|
if ($reslut) {
|
2025-12-12 11:38:09 +08:00
|
|
|
|
//发放签到礼物
|
|
|
|
|
|
$detail_list = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>18])->limit(7)->order('id asc')->select();
|
|
|
|
|
|
foreach ($detail_list as $k=>$v){
|
|
|
|
|
|
$day = $k+1;
|
|
|
|
|
|
if($continuous == $day){
|
|
|
|
|
|
switch ($v['type']) {
|
|
|
|
|
|
case 1: //金币 方法1:直接添加到用户钱包
|
|
|
|
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::DAILY_SIGN,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DAILY_SIGN));
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2: //礼物 方法2:添加到用户礼物背包
|
|
|
|
|
|
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::DAILY_SIGN,"每日签到获得礼物");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3: //坐骑 方法3:添加到用户装扮
|
|
|
|
|
|
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
|
|
|
|
|
if(empty($decorate_price_info)){
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],11);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4: //道具 方法5:钻石
|
|
|
|
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::DAILY_SIGN,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DAILY_SIGN));
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-12-30 19:57:54 +08:00
|
|
|
|
// 记录日志
|
|
|
|
|
|
//添加礼盒记录
|
|
|
|
|
|
$reslut = Db::name('vs_gift_bag_receive_tasks_log')->insert([
|
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
|
'gift_bag_id' => 18,
|
|
|
|
|
|
'parent_id' => $v['id'],
|
|
|
|
|
|
'gift_id'=> $v['foreign_id'],
|
|
|
|
|
|
'type' => $v['type'],
|
|
|
|
|
|
'num' => $v['quantity'],
|
|
|
|
|
|
'gift_price' => $v['gold'],
|
|
|
|
|
|
'createtime' => time(),
|
|
|
|
|
|
'updatetime' => time()
|
|
|
|
|
|
]);
|
2025-12-12 11:38:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-10 18:44:16 +08:00
|
|
|
|
// 提交事务
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
|
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Db::rollback();
|
|
|
|
|
|
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
// 回滚事务
|
|
|
|
|
|
Db::rollback();
|
|
|
|
|
|
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
2025-12-12 14:24:38 +08:00
|
|
|
|
* 签到页面
|
2025-12-10 18:44:16 +08:00
|
|
|
|
*/
|
2025-12-12 14:24:38 +08:00
|
|
|
|
public function daily_tasks_sign_in($user_id){
|
2025-12-12 12:03:17 +08:00
|
|
|
|
//查询昨天有没有签到
|
|
|
|
|
|
$yesterday_sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d',strtotime('-1 day'))])->find();
|
2025-12-12 12:46:47 +08:00
|
|
|
|
if(empty($yesterday_sign_in_info)){
|
|
|
|
|
|
db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'delete_time'=>0])
|
2025-12-12 12:48:04 +08:00
|
|
|
|
->where('sign_in_date','<>',date('Y-m-d'))
|
2025-12-12 12:46:47 +08:00
|
|
|
|
->update([
|
2025-12-12 12:03:17 +08:00
|
|
|
|
'delete_time' => time()
|
|
|
|
|
|
]);
|
2025-12-22 11:52:31 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
if($yesterday_sign_in_info['continuous']>=7){
|
|
|
|
|
|
db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'delete_time'=>0])
|
|
|
|
|
|
->where('sign_in_date','<>',date('Y-m-d'))
|
|
|
|
|
|
->update([
|
|
|
|
|
|
'delete_time' => time()
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
2025-12-12 12:03:17 +08:00
|
|
|
|
}
|
2025-12-11 19:46:19 +08:00
|
|
|
|
//礼包
|
2025-12-12 11:38:09 +08:00
|
|
|
|
$detail_list = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>18])->limit(7)->order('id asc')->select();
|
2025-12-11 19:46:19 +08:00
|
|
|
|
$list= [];
|
2025-12-12 10:32:25 +08:00
|
|
|
|
foreach ($detail_list as $k=>$v){
|
|
|
|
|
|
$day = $k+1;
|
|
|
|
|
|
$list[$k]['day'] = $day;
|
|
|
|
|
|
$sign_in = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'continuous'=>$day,'delete_time'=>0])->find();
|
|
|
|
|
|
if($sign_in){
|
|
|
|
|
|
$list[$k]['sign_in_date'] = $sign_in['sign_in_date'];
|
|
|
|
|
|
$list[$k]['sign_in_status'] = 1;
|
|
|
|
|
|
$list[$k]['sign_in_status_str'] = "已签到";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
if($k==0){
|
|
|
|
|
|
$list[$k]['sign_in_date'] = date('Y-m-d');
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$list[$k]['sign_in_date'] = date('Y-m-d',strtotime($list[$k-1]['sign_in_date'])+86400);
|
|
|
|
|
|
}
|
|
|
|
|
|
$list[$k]['sign_in_status'] = 0;
|
|
|
|
|
|
$list[$k]['sign_in_status_str'] = "未签到";
|
|
|
|
|
|
}
|
|
|
|
|
|
//是否是当天
|
|
|
|
|
|
$list[$k]['is_today'] = $list[$k]['sign_in_date'] == date('Y-m-d') ? 1 : 0;
|
2025-12-11 19:46:19 +08:00
|
|
|
|
if($v['type'] == 1){
|
|
|
|
|
|
$list[$k]['gift_name'] = "金币";
|
2025-12-12 17:43:19 +08:00
|
|
|
|
$list[$k]['num'] = $v['quantity'];
|
2025-12-11 19:46:19 +08:00
|
|
|
|
$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']." 天"??0; //天数
|
|
|
|
|
|
$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");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-12 10:42:09 +08:00
|
|
|
|
$result = $list;
|
2025-12-10 18:44:16 +08:00
|
|
|
|
return ['code' => 1, 'msg' => '成功','data' => $result];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 14:24:38 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* 今日签到状态
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function daily_tasks_sign_in_status($user_id){
|
2025-12-13 00:37:51 +08:00
|
|
|
|
$task_info = Db::name('vs_tasks')->where('id',1)->where('delete_time',0)->where('is_active',1)->find();
|
|
|
|
|
|
if(empty($task_info)){
|
|
|
|
|
|
$result['status'] = 1;
|
|
|
|
|
|
$result['status_str'] = "已签到";
|
|
|
|
|
|
return ['code' => 1, 'msg' => '成功','data' => $result];
|
|
|
|
|
|
}
|
2025-12-12 14:24:38 +08:00
|
|
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d')])->find();
|
|
|
|
|
|
$result = [];
|
|
|
|
|
|
if ($sign_in_info) {
|
|
|
|
|
|
$result['status'] = 1;
|
|
|
|
|
|
$result['status_str'] = "已签到";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$result['status'] = 0;
|
|
|
|
|
|
$result['status_str'] = "未签到";
|
|
|
|
|
|
}
|
|
|
|
|
|
return ['code' => 1, 'msg' => '成功','data' => $result];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-16 11:35:40 +08:00
|
|
|
|
//未完成任务数量
|
|
|
|
|
|
public function daily_tasks_unfinished_count($user_id){
|
2025-12-16 14:26:14 +08:00
|
|
|
|
$task_ids = Db::name('vs_tasks')->field('id as task_id,task_type')->where('delete_time',0)->where(['is_active'=>1,'id'=>['<>',1]])->select();
|
2025-12-16 11:35:40 +08:00
|
|
|
|
$result = [];
|
2025-12-16 12:38:19 +08:00
|
|
|
|
$task_user_count = 0;
|
2025-12-29 22:15:52 +08:00
|
|
|
|
|
|
|
|
|
|
// 按任务类型分组,减少数据库查询次数
|
|
|
|
|
|
$daily_task_ids = [];
|
|
|
|
|
|
$other_task_ids = [];
|
|
|
|
|
|
|
|
|
|
|
|
foreach($task_ids as $k=>$v) {
|
|
|
|
|
|
if($v['task_type']==2) {
|
|
|
|
|
|
$daily_task_ids[] = $v['task_id'];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$other_task_ids[] = $v;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 一次性查询所有每日任务(task_type==2)
|
|
|
|
|
|
if (!empty($daily_task_ids)) {
|
|
|
|
|
|
$daily_task_count = Db::name('vs_tasks_user_daily')
|
|
|
|
|
|
->where(['user_id'=>$user_id,'is_claimed'=>0,'is_completed'=>1])
|
|
|
|
|
|
->where('task_id', 'in', $daily_task_ids)
|
|
|
|
|
|
->whereTime('createtime', 'today')
|
2025-12-30 16:45:30 +08:00
|
|
|
|
->count('id');
|
2025-12-29 22:15:52 +08:00
|
|
|
|
$task_user_count += $daily_task_count;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理其他类型任务
|
|
|
|
|
|
foreach($other_task_ids as $k=>$v) {
|
|
|
|
|
|
if(in_array($v['task_id'],[21,22,23])){
|
|
|
|
|
|
$task_user = db::name('vs_tasks_student')
|
|
|
|
|
|
->where('user_id',$user_id)
|
|
|
|
|
|
->where('task_id',$v['task_id'])
|
|
|
|
|
|
->where('status',1)
|
|
|
|
|
|
->where('delete_time', 0)
|
|
|
|
|
|
->count();
|
|
|
|
|
|
}elseif($v['task_id']==24){
|
|
|
|
|
|
$task_user = Db::name('vs_user_sign_task')->where(['user_id'=>$user_id,'day'=>date('Y-m-d'),'status'=>0])->count();
|
|
|
|
|
|
}elseif(in_array($v['task_id'],[26,27,28,29,30,31,32])){
|
|
|
|
|
|
$task_user = Db::name('vs_user_cp_task')->where(['user_id'=>$user_id,'delete_time'=>0,'day'=>date('Y-m-d'),'status'=>1,'tasks_bag_id'=>$v['task_id']])->count();
|
|
|
|
|
|
}else{
|
2025-12-16 12:38:19 +08:00
|
|
|
|
$task_user = Db::name('vs_tasks_user_daily')
|
|
|
|
|
|
->where(['user_id'=>$user_id,'is_claimed'=>0,'is_completed'=>1])
|
2025-12-16 14:26:14 +08:00
|
|
|
|
->where('task_id',$v['task_id'])
|
2025-12-30 16:45:30 +08:00
|
|
|
|
->count('id');
|
2025-12-16 12:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
$task_user_count +=$task_user;
|
|
|
|
|
|
}
|
2025-12-29 22:15:52 +08:00
|
|
|
|
|
2025-12-16 11:35:40 +08:00
|
|
|
|
$result['num'] = $task_user_count;
|
|
|
|
|
|
return ['code' => 1, 'msg' => '成功','data' => $result];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-10 18:44:16 +08:00
|
|
|
|
}
|