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.

208 lines
6.4 KiB

8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use DB;
  4. use Log;
  5. class UserWithdraw extends BaseModel
  6. {
  7. //用户余额明细
  8. protected $table = 'user_withdraw';
  9. public $timestamps = false;
  10. protected $hidden = array();
  11. protected $guarded = array(); //$guarded包含你不想被赋值的字段数组。
  12. const UN_DELETE = 0; //未删除
  13. const USER_WITHDRAW_DES = '提现';
  14. public function getDb()
  15. {
  16. return DB::table($this->table);
  17. }
  18. /**
  19. * 列表
  20. * @param array $where 查询条件
  21. * @param string $order 排序
  22. * @param string $field 字段
  23. * @param int $offset 偏移量
  24. * @param int $limit 取多少条
  25. * @return array
  26. */
  27. public function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 10)
  28. {
  29. $model = $this->getDb();
  30. if($where){$model = $model->where($where);}
  31. $res['count'] = $model->count();
  32. $res['list'] = array();
  33. if($res['count'] > 0)
  34. {
  35. if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}}
  36. if($order){$model = parent::getOrderByData($model, $order);}
  37. if($offset){}else{$offset = 0;}
  38. if($limit){}else{$limit = 10;}
  39. $res['list'] = $model->skip($offset)->take($limit)->get();
  40. }
  41. return $res;
  42. }
  43. /**
  44. * 分页,用于前端html输出
  45. * @param array $where 查询条件
  46. * @param string $order 排序
  47. * @param string $field 字段
  48. * @param int $limit 每页几条
  49. * @param int $page 当前第几页
  50. * @return array
  51. */
  52. public function getPaginate($where = array(), $order = '', $field = '*', $limit = 10)
  53. {
  54. $res = $this->getDb();
  55. if($where){$res = $res->where($where);}
  56. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  57. if($order){$res = parent::getOrderByData($res, $order);}
  58. if($limit){}else{$limit = 10;}
  59. return $res->paginate($limit);
  60. }
  61. /**
  62. * 查询全部
  63. * @param array $where 查询条件
  64. * @param string $order 排序
  65. * @param string $field 字段
  66. * @param int $limit 取多少条
  67. * @return array
  68. */
  69. public function getAll($where = array(), $order = '', $field = '*', $limit = '', $offset = '')
  70. {
  71. $res = $this->getDb();
  72. if($where){$res = $res->where($where);}
  73. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  74. if($order){$res = parent::getOrderByData($res, $order);}
  75. if($offset){$res = $res->skip($offset);}
  76. if($limit){$res = $res->take($limit);}
  77. $res = $res->get();
  78. return $res;
  79. }
  80. /**
  81. * 获取一条
  82. * @param array $where 条件
  83. * @param string $field 字段
  84. * @return array
  85. */
  86. public function getOne($where, $field = '*')
  87. {
  88. $res = $this->getDb();
  89. if($where){$res = $res->where($where);}
  90. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  91. $res = $res->first();
  92. return $res;
  93. }
  94. /**
  95. * 添加
  96. * @param array $data 数据
  97. * @return int
  98. */
  99. public function add(array $data,$type = 0)
  100. {
  101. if($type==0)
  102. {
  103. // 新增单条数据并返回主键值
  104. return self::insertGetId(parent::filterTableColumn($data,$this->table));
  105. }
  106. elseif($type==1)
  107. {
  108. /**
  109. * 添加单条数据
  110. * $data = ['foo' => 'bar', 'bar' => 'foo'];
  111. * 添加多条数据
  112. * $data = [
  113. * ['foo' => 'bar', 'bar' => 'foo'],
  114. * ['foo' => 'bar1', 'bar' => 'foo1'],
  115. * ['foo' => 'bar2', 'bar' => 'foo2']
  116. * ];
  117. */
  118. return self::insert($data);
  119. }
  120. }
  121. /**
  122. * 修改
  123. * @param array $data 数据
  124. * @param array $where 条件
  125. * @return bool
  126. */
  127. public function edit($data, $where = array())
  128. {
  129. $res = $this->getDb();
  130. $res = $res->where($where)->update(parent::filterTableColumn($data, $this->table));
  131. if ($res === false)
  132. {
  133. return false;
  134. }
  135. return true;
  136. }
  137. /**
  138. * 删除
  139. * @param array $where 条件
  140. * @return bool
  141. */
  142. public function del($where)
  143. {
  144. $res = $this->getDb();
  145. $res = $res->where($where)->delete();
  146. return $res;
  147. }
  148. //获取提现状态文字:0未处理,1处理中,2成功,3取消,4拒绝
  149. public function getStatusAttr($data)
  150. {
  151. $arr = array(0 => '未处理', 1 => '处理中', 2 => '成功', 3 => '取消', 4 => '拒绝');
  152. return $arr[$data->status];
  153. }
  154. /*
  155. public static function add(array $data)
  156. {
  157. $user = User::where(array('id'=>$data['user_id'],'pay_password'=>$data['pay_password']))->first();
  158. if(!$user){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'支付密码错误');}
  159. unset($data['pay_password']);
  160. $min_withdraw_money = sysconfig('CMS_MIN_WITHDRAWAL_MONEY'); //最低可提现金额
  161. if($user['money']<$data['money']){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'余额不足');}
  162. if($user['money']<$min_withdraw_money){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'用户金额小于最小提现金额');}
  163. if($data['money']<$min_withdraw_money){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'提现金额不得小于最小提现金额');}
  164. if ($id = self::insertGetId($data))
  165. {
  166. //扣除用户余额
  167. DB::table('user')->where(array('id'=>$data['user_id']))->decrement('money', $data['money']);
  168. //增加用户余额记录
  169. 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()));
  170. return ReturnData::create(ReturnData::SUCCESS,$id);
  171. }
  172. return ReturnData::create(ReturnData::SYSTEM_FAIL);
  173. }
  174. */
  175. }