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.

81 lines
1.6 KiB

8 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use App\Common\Token;
  4. use DB;
  5. class UserMoney extends BaseModel
  6. {
  7. //用户余额明细
  8. protected $table = 'user_money';
  9. public $timestamps = false;
  10. /**
  11. * 不能被批量赋值的属性
  12. *
  13. * @var array
  14. */
  15. protected $guarded = [];
  16. //获取列表
  17. public static function getList(array $param)
  18. {
  19. extract($param); //参数:limit,offset
  20. $where['user_id'] = Token::$uid;
  21. $limit = isset($limit) ? $limit : 10;
  22. $offset = isset($offset) ? $offset : 0;
  23. $model = new UserMoney;
  24. if(isset($type)){$where['type'] = $type;}
  25. $model = $model->where($where);
  26. $res['count'] = $model->count();
  27. $res['list'] = array();
  28. if($res['count']>0)
  29. {
  30. $res['list'] = $model->skip($offset)->take($limit)->get()->toArray();
  31. }
  32. else
  33. {
  34. return false;
  35. }
  36. return $res;
  37. }
  38. public static function add(array $data)
  39. {
  40. if ($id = DB::table(self::$table)->insertGetId($data))
  41. {
  42. return $id;
  43. }
  44. return false;
  45. }
  46. public static function modify($where, array $data)
  47. {
  48. $slide = DB::table(self::$table);
  49. if ($slide->where($where)->update($data))
  50. {
  51. return true;
  52. }
  53. return false;
  54. }
  55. //删除一条记录
  56. public static function remove($id)
  57. {
  58. if (!self::whereIn('id', explode(',', $id))->delete())
  59. {
  60. return false;
  61. }
  62. return true;
  63. }
  64. }