MachineModel.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EasyAdmin
  4. // +----------------------------------------------------------------------
  5. // | PHP交流群: 763822524
  6. // +----------------------------------------------------------------------
  7. // | 开源协议 https://mit-license.org
  8. // +----------------------------------------------------------------------
  9. // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model;
  12. use app\common\model\TimeModel;
  13. use think\db\builder\Oracle;
  14. use think\Exception;
  15. use think\facade\Db;
  16. class MachineModel extends TimeModel
  17. {
  18. protected $name = 'machine';
  19. public function exchangeMacheine($uid, $mid){
  20. $info = self::where('id', $mid)->find();
  21. if (!$info){
  22. throw new Exception('参数错误');
  23. }
  24. if ($info['xz_number'] < 1){
  25. throw new Exception('参数错误');
  26. }
  27. $m_user = new UserModel();
  28. $m_mlist = new MachineListModel();
  29. $user = $m_user->getUserInfo(['id'=>$uid], 'xz_num,id,is_auth');
  30. if ($user['is_auth'] != 1){
  31. throw new Exception('还未进行实名认证');
  32. }
  33. $have_count = $m_mlist->where('uid', $uid)->where('mid', $mid)->where('state', 1)->count();
  34. if ($have_count >= $info['max_have']){
  35. throw new Exception('超过最大持有量,购买失败');
  36. }
  37. if ($user['xz_num'] < $info['xz_number']){
  38. throw new Exception('星钻不足');
  39. }
  40. $time = time();
  41. $m_mlist->insert([
  42. 'mid'=>$mid,
  43. 'create_time'=>sr_getcurtime($time),
  44. 'expire_time'=> sr_getcurtime(strtotime("+ ".$info['valid_day']." days")),
  45. 'back_count'=>$info['cycle'],
  46. 'once_back'=>number_format($info['total_number']/$info['cycle'], '4', '.', ''),
  47. 'over_count'=>$info['cycle'],
  48. 'get_type'=>1,
  49. 'uid'=>$uid
  50. ]);
  51. edit_user_xz(2, $uid, $info['xz_number']);
  52. edit_user_active(1, $uid, $info['add_active']);
  53. Db::name('user')->where('id', $uid)->save(['is_excharge_lock'=>0]);
  54. }
  55. public function getMachineAward($uid, $id, $source){
  56. $m_list = new MachineListModel();
  57. $m_log = new MachineGetrecordModel();
  58. $info_list = $m_list->where('id', $id)->find();
  59. $info_machine = Db::name('machine')->where('id', $info_list['mid'])->find();
  60. if (!$info_list){
  61. throw new Exception('参数错误');
  62. }
  63. if ($info_list['state'] != 1 || $info_list['over_count'] < 1){
  64. throw new Exception('领取失败,卷轴不存在或已过期');
  65. }
  66. if ($info_list['uid'] != $uid){
  67. throw new Exception('请求非法');
  68. }
  69. $get_info = $m_log->whereDay('create_time', 'today')->where('uid', $uid)->where('lid', $id)->find();
  70. if ($get_info){
  71. throw new Exception('今日已领取');
  72. }
  73. if ($info_list['get_count'] == $info_list['back_count']-1){
  74. $m_list->where('id', $id)->save(['state'=>2]);
  75. if (!in_array($info_list['get_type'], [3,4])){
  76. // 扣除用户活跃点
  77. edit_user_active(3, $uid, $info_machine['add_active']);
  78. }
  79. }
  80. $m_log->insert(['create_time'=>sr_getcurtime(time()), 'lid'=>$id, 'uid'=>$uid, 'num'=>$info_list['once_back']]);
  81. $m_list->where('id', $id)->inc('get_count', 1)->dec('over_count', 1)->update();
  82. edit_user_xz(3, $uid, $info_list['once_back']);
  83. $user_info = UserModel::where('id', $uid)->find();
  84. if ($user_info['pid'] != 0){
  85. $scale = env('JUANZHOU.ZHITUI_SCALE', 0);
  86. edit_user_xz(4, $user_info['pid'], number_format(($info_list['once_back']*$scale/100), '4', '.', ''), $uid);
  87. }
  88. //判定人机养号
  89. // $user = Db::name('user')->where('id', $uid)->field('id, getinfo_count')->find();
  90. // if ($user['getinfo_count'] < 7){
  91. // if (!Db::name('deny_user')->where('uid', $uid)->find()){
  92. // Db::name('deny_user')->insert([
  93. // 'uid'=>$uid,
  94. // 'create_time'=>sr_getcurtime(time()),
  95. // 'reason'=>'刷机养号',
  96. // 'sources'=>$source,
  97. // 'ip'=>'3.3.3.3',
  98. // 'req_header'=>$user['getinfo_count'],
  99. // 'req_body'=>'222'
  100. // ]);
  101. // }
  102. // }
  103. }
  104. }