| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- // +----------------------------------------------------------------------
- // | EasyAdmin
- // +----------------------------------------------------------------------
- // | PHP交流群: 763822524
- // +----------------------------------------------------------------------
- // | 开源协议 https://mit-license.org
- // +----------------------------------------------------------------------
- // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
- // +----------------------------------------------------------------------
- namespace app\common\model;
- use app\common\model\TimeModel;
- use think\db\builder\Oracle;
- use think\Exception;
- use think\facade\Db;
- class RenwuMachineModel extends TimeModel
- {
- protected $name = 'renwu_machine';
- public function exchangeRenwuMacheine($uid, $rid){
- $info = self::where('id', $rid)->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']);
- }
- }
|