| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?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 MachineModel extends TimeModel
- {
- protected $name = 'machine';
- public function exchangeMacheine($uid, $mid){
- $info = self::where('id', $mid)->find();
- if (!$info){
- throw new Exception('参数错误');
- }
- if ($info['xz_number'] < 1){
- throw new Exception('参数错误');
- }
- $m_user = new UserModel();
- $m_mlist = new MachineListModel();
- $user = $m_user->getUserInfo(['id'=>$uid], 'xz_num,id,is_auth');
- if ($user['is_auth'] != 1){
- throw new Exception('还未进行实名认证');
- }
- $have_count = $m_mlist->where('uid', $uid)->where('mid', $mid)->where('state', 1)->count();
- if ($have_count >= $info['max_have']){
- throw new Exception('超过最大持有量,购买失败');
- }
- if ($user['xz_num'] < $info['xz_number']){
- throw new Exception('星钻不足');
- }
- $time = time();
- $m_mlist->insert([
- 'mid'=>$mid,
- 'create_time'=>sr_getcurtime($time),
- 'expire_time'=> sr_getcurtime(strtotime("+ ".$info['valid_day']." days")),
- 'back_count'=>$info['cycle'],
- 'once_back'=>number_format($info['total_number']/$info['cycle'], '4', '.', ''),
- 'over_count'=>$info['cycle'],
- 'get_type'=>1,
- 'uid'=>$uid
- ]);
- edit_user_xz(2, $uid, $info['xz_number']);
- edit_user_active(1, $uid, $info['add_active']);
- Db::name('user')->where('id', $uid)->save(['is_excharge_lock'=>0]);
- }
- public function getMachineAward($uid, $id, $source){
- $m_list = new MachineListModel();
- $m_log = new MachineGetrecordModel();
- $info_list = $m_list->where('id', $id)->find();
- $info_machine = Db::name('machine')->where('id', $info_list['mid'])->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('请求非法');
- }
- $get_info = $m_log->whereDay('create_time', 'today')->where('uid', $uid)->where('lid', $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]);
- if (!in_array($info_list['get_type'], [3,4])){
- // 扣除用户活跃点
- edit_user_active(3, $uid, $info_machine['add_active']);
- }
- }
- $m_log->insert(['create_time'=>sr_getcurtime(time()), 'lid'=>$id, 'uid'=>$uid, 'num'=>$info_list['once_back']]);
- $m_list->where('id', $id)->inc('get_count', 1)->dec('over_count', 1)->update();
- edit_user_xz(3, $uid, $info_list['once_back']);
- $user_info = UserModel::where('id', $uid)->find();
- if ($user_info['pid'] != 0){
- $scale = env('JUANZHOU.ZHITUI_SCALE', 0);
- edit_user_xz(4, $user_info['pid'], number_format(($info_list['once_back']*$scale/100), '4', '.', ''), $uid);
- }
- //判定人机养号
- // $user = Db::name('user')->where('id', $uid)->field('id, getinfo_count')->find();
- // if ($user['getinfo_count'] < 7){
- // if (!Db::name('deny_user')->where('uid', $uid)->find()){
- // Db::name('deny_user')->insert([
- // 'uid'=>$uid,
- // 'create_time'=>sr_getcurtime(time()),
- // 'reason'=>'刷机养号',
- // 'sources'=>$source,
- // 'ip'=>'3.3.3.3',
- // 'req_header'=>$user['getinfo_count'],
- // 'req_body'=>'222'
- // ]);
- // }
- // }
- }
- }
|