WechatUser.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\wechat;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. /**
  16. * Class WechatUser
  17. * @package app\model\wechat
  18. */
  19. class WechatUser extends BaseModel
  20. {
  21. use ModelTrait;
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'uid';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'wechat_user';
  32. protected $insert = ['add_time'];
  33. public static function setAddTimeAttr()
  34. {
  35. return time();
  36. }
  37. protected function getAddTimeAttr($value)
  38. {
  39. if ($value) return date('Y-m-d H:i', (int)$value);
  40. return $value;
  41. }
  42. /**
  43. * 关联user
  44. * @return \think\model\relation\HasOne
  45. */
  46. public function user()
  47. {
  48. return $this->hasOne(User::class, 'uid', 'uid');
  49. }
  50. /**
  51. * 绑定公众号
  52. * @param Model $query
  53. * @param $value
  54. */
  55. public function searchUnionidAttr($query, $value)
  56. {
  57. return $query->where('unionid', $value);
  58. }
  59. /**
  60. * 公众号唯一id
  61. * @param Model $query
  62. * @param $value
  63. */
  64. public function searchOpenidAttr($query, $value)
  65. {
  66. return $query->where('openid', $value);
  67. }
  68. /**
  69. * 分组
  70. * @param Model $query
  71. * @param $value
  72. */
  73. public function searchGroupIdAttr($query, $value)
  74. {
  75. return $query->where('group_id', $value);
  76. }
  77. /**
  78. * 性别
  79. * @param Model $query
  80. * @param $value
  81. */
  82. public function searchSexAttr($query, $value)
  83. {
  84. return $query->where('sex', $value);
  85. }
  86. /**
  87. * 是否关注
  88. * @param Model $query
  89. * @param $value
  90. */
  91. public function searchSubscribeAttr($query, $value)
  92. {
  93. return $query->where('subscribe', $value);
  94. }
  95. /**
  96. * 用户类型
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchTypeAttr($query, $value)
  101. {
  102. return $query->where('user_type', $value);
  103. }
  104. /**
  105. * 用户类型
  106. * @param Model $query
  107. * @param $value
  108. */
  109. public function searchUserTypeAttr($query, $value)
  110. {
  111. return $query->where('user_type', $value);
  112. }
  113. /**
  114. * 是否注销
  115. * @param $query
  116. * @param $value
  117. * @return mixed
  118. */
  119. public function searchIsDelAttr($query, $value)
  120. {
  121. if ($value !== '') return $query->where('is_del', $value);
  122. }
  123. }