You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use App\Common\Token;
  4. use DB;
  5. use App\Common\ReturnData;
  6. class UserWithdraw extends BaseModel
  7. {
  8. //用户余额明细
  9. protected $table = 'user_withdraw';
  10. public $timestamps = false;
  11. /**
  12. * 不能被批量赋值的属性
  13. *
  14. * @var array
  15. */
  16. protected $guarded = [];
  17. //获取列表
  18. public static function getList(array $param)
  19. {
  20. extract($param); //参数:limit,offset
  21. $limit = isset($limit) ? $limit : 10;
  22. $offset = isset($offset) ? $offset : 0;
  23. $where['user_id'] = $user_id;
  24. $where['is_delete'] = 0;
  25. $model = new self;
  26. if(isset($status) && !empty($status)){if($status==-1){}else{$where['status'] = $status;}}
  27. if(isset($method)){$where['method'] = $method;}
  28. $model = $model->where($where);
  29. $res['count'] = $model->count();
  30. $res['list'] = array();
  31. if($res['count']>0)
  32. {
  33. $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get();
  34. foreach($res['list'] as $k=>$v)
  35. {
  36. $res['list'][$k]['status_text'] = self::getStatusText($v);
  37. }
  38. }
  39. else
  40. {
  41. return false;
  42. }
  43. return $res;
  44. }
  45. public static function getOne(array $param)
  46. {
  47. extract($param);
  48. $where['id'] = $id;
  49. $where['is_delete'] = 0;
  50. return self::where($where)->first();
  51. }
  52. public static function add(array $data)
  53. {
  54. $user = User::where(array('id'=>$data['user_id'],'pay_password'=>$data['pay_password']))->first();
  55. if(!$user){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'支付密码错误');}
  56. unset($data['pay_password']);
  57. $min_withdraw_money = sysconfig('CMS_MIN_WITHDRAWAL_MONEY'); //最低可提现金额
  58. if($user['money']<$data['money']){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'余额不足');}
  59. if($user['money']<$min_withdraw_money){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'用户金额小于最小提现金额');}
  60. if($data['money']<$min_withdraw_money){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'提现金额不得小于最小提现金额');}
  61. if ($id = self::insertGetId($data))
  62. {
  63. //扣除用户余额
  64. DB::table('user')->where(array('id'=>$data['user_id']))->decrement('money', $data['money']);
  65. //增加用户余额记录
  66. DB::table('user_money')->insert(array('user_id'=>$data['user_id'],'type'=>1,'money'=>$data['money'],'des'=>'提现','user_money'=>DB::table('user')->where(array('id'=>$data['user_id']))->value('money'),'add_time'=>time()));
  67. return ReturnData::create(ReturnData::SUCCESS,$id);
  68. }
  69. return ReturnData::create(ReturnData::SYSTEM_FAIL);
  70. }
  71. public static function modify($where, array $data)
  72. {
  73. if (self::where($where)->update($data))
  74. {
  75. return true;
  76. }
  77. return false;
  78. }
  79. //删除一条记录
  80. public static function remove($id,$user_id)
  81. {
  82. if (!self::whereIn('id', explode(',', $id))->where('user_id',$user_id)->update(array('is_delete'=>1)))
  83. {
  84. return false;
  85. }
  86. return true;
  87. }
  88. //获取提现状态文字:0未处理,1处理中,2成功,3取消,4拒绝
  89. public static function getStatusText($where)
  90. {
  91. $res = '';
  92. if($where['status'] == 0)
  93. {
  94. $res = '未处理';
  95. }
  96. elseif($where['status'] == 1)
  97. {
  98. $res = '处理中';
  99. }
  100. elseif($where['status'] == 2)
  101. {
  102. $res = '成功';
  103. }
  104. elseif($where['status'] == 3)
  105. {
  106. $res = '取消';
  107. }
  108. elseif($where['status'] == 4)
  109. {
  110. $res = '拒绝';
  111. }
  112. return $res;
  113. }
  114. }