find(); if (!$info){ throw new Exception('参数错误'); } if ($info['score'] < 1){ throw new Exception('参数错误'); } $m_user = new UserModel(); $m_mlist = new RenwuMachineListModel(); $user = $m_user->getUserInfo(['id'=>$uid], 'score,id,is_auth'); if ($user['is_auth'] != 1){ throw new Exception('还未进行实名认证'); } //============================================================ // $have_count = $m_mlist->where('uid', $uid)->where('rid', $rid)->where('state', 1)->count(); // if ($have_count == $info['max_have']){ // throw new Exception('超过最大持有量,购买失败'); // } // 2022、/04、/23 改为用户只能买一次 $has = $m_mlist->where('uid', $uid)->where('rid', $rid)->find(); if ($has){ throw new Exception('超过最大持有量,购买失败'); } //============================================================ if ($user['score'] < $info['score']){ throw new Exception('积分不足'); } $time = time(); $m_mlist->insert([ 'rid'=>$rid, 'create_time'=>sr_getcurtime($time), 'expire_time'=> sr_getcurtime(strtotime("+ ".$info['valid_day']." days")), 'back_count'=>$info['cycle'], // 'once_back'=>number_format($info['total_score']/$info['cycle'], '4', '.', ''), 'once_back'=>$info['once_back'], 'over_count'=>$info['cycle'], 'uid'=>$uid ]); edit_user_score(13, $uid, $info['score']); } public function getRenwuMachineAward($uid, $id){ $m_list = new RenwuMachineListModel(); $m_log = new RenwuMachineGetrecordModel(); $info_list = $m_list->where('id', $id)->find(); if (!$info_list){ throw new Exception('参数错误'); } if ($info_list['state'] != 1 || $info_list['over_count'] < 1){ throw new Exception('已过期'); } if ($info_list['uid'] != $uid){ throw new Exception('请求非法'); } getActionBefore(3); $get_info = $m_log->whereDay('create_time', 'today')->where('uid', $uid)->where('rid', $id)->find(); if ($get_info){ throw new Exception('今日已领取'); } if ($info_list['get_count'] == $info_list['back_count']-1){ $m_list->where('id', $id)->save(['state'=>2]); } $m_log->insert(['create_time'=>sr_getcurtime(time()), 'rid'=>$id, 'uid'=>$uid, 'num'=>$info_list['once_back']]); $m_list->where('id', $id)->inc('get_count', 1)->dec('over_count', 1)->update(); edit_user_renwusocre(1, $uid, $info_list['once_back']); } }