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.

167 lines
4.7 KiB

7 years ago
4 years ago
7 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Support\Facades\DB;
  4. use Illuminate\Support\Facades\Log;
  5. class UserRecharge extends BaseModel
  6. {
  7. //用户充值
  8. protected $table = 'user_recharge';
  9. public $timestamps = false;
  10. protected $hidden = array();
  11. protected $guarded = array(); //$guarded包含你不想被赋值的字段数组。
  12. const UN_PAY = 0; //未支付状态
  13. const COMPLETE_PAY = 1; //充值成功
  14. const USER_RECHARGE_DES = '充值';
  15. public function getDb()
  16. {
  17. return DB::table($this->table);
  18. }
  19. /**
  20. * 列表
  21. * @param array $where 查询条件
  22. * @param string $order 排序
  23. * @param string $field 字段
  24. * @param int $offset 偏移量
  25. * @param int $limit 取多少条
  26. * @return array
  27. */
  28. public function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 15)
  29. {
  30. $model = $this->getDb();
  31. if($where){$model = $model->where($where);}
  32. $res['count'] = $model->count();
  33. $res['list'] = array();
  34. if($res['count'] > 0)
  35. {
  36. if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}}
  37. if($order){$model = parent::getOrderByData($model, $order);}
  38. if($offset){}else{$offset = 0;}
  39. if($limit){}else{$limit = 15;}
  40. $res['list'] = $model->skip($offset)->take($limit)->get();
  41. }
  42. return $res;
  43. }
  44. /**
  45. * 分页,用于前端html输出
  46. * @param array $where 查询条件
  47. * @param string $order 排序
  48. * @param string $field 字段
  49. * @param int $limit 每页几条
  50. * @param int $page 当前第几页
  51. * @return array
  52. */
  53. public function getPaginate($where = array(), $order = '', $field = '*', $limit = 15)
  54. {
  55. $res = $this->getDb();
  56. if($where){$res = $res->where($where);}
  57. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  58. if($order){$res = parent::getOrderByData($res, $order);}
  59. if($limit){}else{$limit = 15;}
  60. return $res->paginate($limit);
  61. }
  62. /**
  63. * 查询全部
  64. * @param array $where 查询条件
  65. * @param string $order 排序
  66. * @param string $field 字段
  67. * @param int $limit 取多少条
  68. * @return array
  69. */
  70. public function getAll($where = array(), $order = '', $field = '*', $limit = '', $offset = '')
  71. {
  72. $res = $this->getDb();
  73. if($where){$res = $res->where($where);}
  74. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  75. if($order){$res = parent::getOrderByData($res, $order);}
  76. if($offset){$res = $res->skip($offset);}
  77. if($limit){$res = $res->take($limit);}
  78. $res = $res->get();
  79. return $res;
  80. }
  81. /**
  82. * 获取一条
  83. * @param array $where 条件
  84. * @param string $field 字段
  85. * @return array
  86. */
  87. public function getOne($where, $field = '*')
  88. {
  89. $res = $this->getDb();
  90. if($where){$res = $res->where($where);}
  91. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  92. $res = $res->first();
  93. return $res;
  94. }
  95. /**
  96. * 添加
  97. * @param array $data 数据
  98. * @return int
  99. */
  100. public function add(array $data,$type = 0)
  101. {
  102. if($type==0)
  103. {
  104. // 新增单条数据并返回主键值
  105. return self::insertGetId(parent::filterTableColumn($data,$this->table));
  106. }
  107. elseif($type==1)
  108. {
  109. /**
  110. * 添加单条数据
  111. * $data = ['foo' => 'bar', 'bar' => 'foo'];
  112. * 添加多条数据
  113. * $data = [
  114. * ['foo' => 'bar', 'bar' => 'foo'],
  115. * ['foo' => 'bar1', 'bar' => 'foo1'],
  116. * ['foo' => 'bar2', 'bar' => 'foo2']
  117. * ];
  118. */
  119. return self::insert($data);
  120. }
  121. }
  122. /**
  123. * 修改
  124. * @param array $data 数据
  125. * @param array $where 条件
  126. * @return int
  127. */
  128. public function edit($data, $where = array())
  129. {
  130. $res = $this->getDb();
  131. return $res->where($where)->update(parent::filterTableColumn($data, $this->table));
  132. }
  133. /**
  134. * 删除
  135. * @param array $where 条件
  136. * @return bool
  137. */
  138. public function del($where)
  139. {
  140. $res = $this->getDb();
  141. $res = $res->where($where)->delete();
  142. return $res;
  143. }
  144. }