User.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\model\shopro\user;
  3. use app\admin\model\shopro\user\MoneyLog;
  4. use app\admin\model\shopro\user\ScoreLog;
  5. use addons\shopro\library\notify\Notifiable;
  6. use think\Model;
  7. use think\Db;
  8. class User extends Model
  9. {
  10. use Notifiable;
  11. // 表名
  12. protected $name = 'user';
  13. // 自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'createtime';
  17. protected $updateTime = 'updatetime';
  18. // 追加属性
  19. protected $append = [
  20. ];
  21. public function getGenderList()
  22. {
  23. return ['1' => __('Male'), '0' => __('Female')];
  24. }
  25. public function getStatusList()
  26. {
  27. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  28. }
  29. public function group()
  30. {
  31. return $this->belongsTo('Group', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
  32. }
  33. public function agent()
  34. {
  35. return $this->hasOne(\app\admin\model\shopro\commission\Agent::class, 'user_id', 'id');
  36. }
  37. /**
  38. * 获取验证字段数组值
  39. * @param string $value
  40. * @param array $data
  41. * @return object
  42. */
  43. public function getVerificationAttr($value, $data)
  44. {
  45. $value = array_filter((array)json_decode($value, true));
  46. $value = array_merge(['email' => 0, 'mobile' => 0], $value);
  47. return (object)$value;
  48. }
  49. /**
  50. * 设置验证字段
  51. * @param mixed $value
  52. * @return string
  53. */
  54. public function setVerificationAttr($value)
  55. {
  56. $value = is_object($value) || is_array($value) ? json_encode($value) : $value;
  57. return $value;
  58. }
  59. }