UserBanks.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/25
  6. */
  7. namespace app\models\user;
  8. use crmeb\basic\BaseModel;
  9. use crmeb\traits\ModelTrait;
  10. /**
  11. * TODO 用户收货地址
  12. * Class UserAddress
  13. * @package app\models\user
  14. */
  15. class UserBanks extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'user_banks';
  27. use ModelTrait;
  28. protected $insert = ['add_time'];
  29. protected $hidden = ['add_time', 'is_del', 'uid'];
  30. protected function setAddTimeAttr()
  31. {
  32. return time();
  33. }
  34. /**
  35. * 设置用户地址查询初始条件
  36. * @param null $model
  37. * @param string $prefix
  38. * @return \think\Model
  39. */
  40. public static function userValidAddressWhere($model = null, $prefix = '')
  41. {
  42. if ($prefix) $prefix .= '.';
  43. $model = self::getSelfModel($model);
  44. return $model->where("{$prefix}is_del", 0);
  45. }
  46. /**
  47. * 获取用户收货地址并分页
  48. * @param $uid 用户uid
  49. * @param int $page 页码
  50. * @param int $limit 展示条数
  51. * @param string $field 展示字段
  52. * @return array
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. */
  57. public static function getUserValidAddressList($uid, $type, $page = 1, $limit = 8, $field = '*')
  58. {
  59. if ($page) return self::userValidAddressWhere()->where('type', $type)->where('uid', $uid)->order('add_time DESC')->field($field)->page((int)$page, (int)$limit)->select()->toArray() ?: [];
  60. else return self::userValidAddressWhere()->where('type', $type)->where('uid', $uid)->order('add_time DESC')->field($field)->select()->toArray() ?: [];
  61. }
  62. }