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.

290 lines
8.3 KiB

8 years ago
7 years ago
8 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
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 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. public function getDb()
  13. {
  14. return DB::table($this->table);
  15. }
  16. /**
  17. * 列表
  18. * @param array $where 查询条件
  19. * @param string $order 排序
  20. * @param string $field 字段
  21. * @param int $offset 偏移量
  22. * @param int $limit 取多少条
  23. * @return array
  24. */
  25. public function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 10)
  26. {
  27. $model = $this->getDb();
  28. if($where){$model = $model->where($where);}
  29. $res['count'] = $model->count();
  30. $res['list'] = array();
  31. if($res['count'] > 0)
  32. {
  33. if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}}
  34. if($order){$model = parent::getOrderByData($model, $order);}
  35. if($offset){}else{$offset = 0;}
  36. if($limit){}else{$limit = 10;}
  37. $res['list'] = $model->skip($offset)->take($limit)->get();
  38. }
  39. return $res;
  40. }
  41. /**
  42. * 分页,用于前端html输出
  43. * @param array $where 查询条件
  44. * @param string $order 排序
  45. * @param string $field 字段
  46. * @param int $limit 每页几条
  47. * @param int $page 当前第几页
  48. * @return array
  49. */
  50. public function getPaginate($where = array(), $order = '', $field = '*', $limit = 10)
  51. {
  52. $res = $this->getDb();
  53. if($where){$res = $res->where($where);}
  54. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  55. if($order){$res = parent::getOrderByData($res, $order);}
  56. if($limit){}else{$limit = 10;}
  57. return $res->paginate($limit);
  58. }
  59. /**
  60. * 查询全部
  61. * @param array $where 查询条件
  62. * @param string $order 排序
  63. * @param string $field 字段
  64. * @param int $limit 取多少条
  65. * @return array
  66. */
  67. public function getAll($where = array(), $order = '', $field = '*', $limit = '', $offset = '')
  68. {
  69. $res = $this->getDb();
  70. if($where){$res = $res->where($where);}
  71. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  72. if($order){$res = parent::getOrderByData($res, $order);}
  73. if($offset){$res = $res->skip($offset);}
  74. if($limit){$res = $res->take($limit);}
  75. $res = $res->get();
  76. return $res;
  77. }
  78. /**
  79. * 获取一条
  80. * @param array $where 条件
  81. * @param string $field 字段
  82. * @return array
  83. */
  84. public function getOne($where, $field = '*')
  85. {
  86. $res = $this->getDb();
  87. if($where){$res = $res->where($where);}
  88. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  89. $res = $res->first();
  90. return $res;
  91. }
  92. /**
  93. * 添加
  94. * @param array $data 数据
  95. * @return int
  96. */
  97. public function add(array $data,$type = 0)
  98. {
  99. if($type==0)
  100. {
  101. // 新增单条数据并返回主键值
  102. return self::insertGetId(parent::filterTableColumn($data,$this->table));
  103. }
  104. elseif($type==1)
  105. {
  106. /**
  107. * 添加单条数据
  108. * $data = ['foo' => 'bar', 'bar' => 'foo'];
  109. * 添加多条数据
  110. * $data = [
  111. * ['foo' => 'bar', 'bar' => 'foo'],
  112. * ['foo' => 'bar1', 'bar' => 'foo1'],
  113. * ['foo' => 'bar2', 'bar' => 'foo2']
  114. * ];
  115. */
  116. return self::insert($data);
  117. }
  118. }
  119. /**
  120. * 修改
  121. * @param array $data 数据
  122. * @param array $where 条件
  123. * @return bool
  124. */
  125. public function edit($data, $where = array())
  126. {
  127. $res = $this->getDb();
  128. $res = $res->where($where)->update(parent::filterTableColumn($data, $this->table));
  129. if ($res === false)
  130. {
  131. return false;
  132. }
  133. return true;
  134. }
  135. /**
  136. * 删除
  137. * @param array $where 条件
  138. * @return bool
  139. */
  140. public function del($where)
  141. {
  142. $res = $this->getDb();
  143. $res = $res->where($where)->delete();
  144. return $res;
  145. }
  146. /*
  147. //获取列表
  148. public static function getList(array $param)
  149. {
  150. extract($param); //参数:limit,offset
  151. $limit = isset($limit) ? $limit : 10;
  152. $offset = isset($offset) ? $offset : 0;
  153. $where['user_id'] = $user_id;
  154. $where['is_delete'] = 0;
  155. $model = new self;
  156. if(isset($status) && !empty($status)){if($status==-1){}else{$where['status'] = $status;}}
  157. if(isset($method)){$where['method'] = $method;}
  158. $model = $model->where($where);
  159. $res['count'] = $model->count();
  160. $res['list'] = array();
  161. if($res['count']>0)
  162. {
  163. $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get();
  164. foreach($res['list'] as $k=>$v)
  165. {
  166. $res['list'][$k]['status_text'] = self::getStatusText($v);
  167. }
  168. }
  169. else
  170. {
  171. return false;
  172. }
  173. return $res;
  174. }
  175. public static function getOne(array $param)
  176. {
  177. extract($param);
  178. $where['id'] = $id;
  179. $where['is_delete'] = 0;
  180. return self::where($where)->first();
  181. }
  182. public static function add(array $data)
  183. {
  184. $user = User::where(array('id'=>$data['user_id'],'pay_password'=>$data['pay_password']))->first();
  185. if(!$user){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'支付密码错误');}
  186. unset($data['pay_password']);
  187. $min_withdraw_money = sysconfig('CMS_MIN_WITHDRAWAL_MONEY'); //最低可提现金额
  188. if($user['money']<$data['money']){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'余额不足');}
  189. if($user['money']<$min_withdraw_money){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'用户金额小于最小提现金额');}
  190. if($data['money']<$min_withdraw_money){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'提现金额不得小于最小提现金额');}
  191. if ($id = self::insertGetId($data))
  192. {
  193. //扣除用户余额
  194. DB::table('user')->where(array('id'=>$data['user_id']))->decrement('money', $data['money']);
  195. //增加用户余额记录
  196. 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()));
  197. return ReturnData::create(ReturnData::SUCCESS,$id);
  198. }
  199. return ReturnData::create(ReturnData::SYSTEM_FAIL);
  200. }
  201. public static function modify($where, array $data)
  202. {
  203. if (self::where($where)->update($data))
  204. {
  205. return true;
  206. }
  207. return false;
  208. }
  209. //删除一条记录
  210. public static function remove($id,$user_id)
  211. {
  212. if (!self::whereIn('id', explode(',', $id))->where('user_id',$user_id)->update(array('is_delete'=>1)))
  213. {
  214. return false;
  215. }
  216. return true;
  217. }
  218. //获取提现状态文字:0未处理,1处理中,2成功,3取消,4拒绝
  219. public static function getStatusText($where)
  220. {
  221. $res = '';
  222. if($where['status'] == 0)
  223. {
  224. $res = '未处理';
  225. }
  226. elseif($where['status'] == 1)
  227. {
  228. $res = '处理中';
  229. }
  230. elseif($where['status'] == 2)
  231. {
  232. $res = '成功';
  233. }
  234. elseif($where['status'] == 3)
  235. {
  236. $res = '取消';
  237. }
  238. elseif($where['status'] == 4)
  239. {
  240. $res = '拒绝';
  241. }
  242. return $res;
  243. } */
  244. }