WxUserModel.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\model;
  3. use traits\model\SoftDelete;
  4. class WxUserModel extends BaseModel
  5. {
  6. use SoftDelete;
  7. protected $table = 'wx_user';
  8. protected $deleteTime = 'delete_time';
  9. protected $autoWriteTimestamp = true;
  10. public function getCreateTimeAttr($value,$data)
  11. {
  12. return date('Y-m-d H:i:s',$value);
  13. }
  14. public function getGenderTAttr($value,$data)
  15. {
  16. $arr = ['','男','女'];
  17. return $arr[$data['gender']];
  18. }
  19. public function getUserPage($page,$limit,$param=[]){
  20. $where = [];
  21. if(!empty($param['keyword'])){
  22. $where['nickname|a.openid'] = ['like','%'.$param['keyword'].'%'];
  23. }
  24. $join=[
  25. ['user user','user.id=a.user_id','LEFT'],
  26. ];
  27. $this->alias('a')
  28. ->field('a.*')
  29. ->group('user_id')
  30. ->join($join);
  31. if(!empty($condition)){
  32. $this->where($condition);
  33. }
  34. return $this->where($where)->paginate($limit,false,['page'=>$page]);
  35. }
  36. //获取用户信息
  37. public function getUserInfo($condition=[])
  38. {
  39. $join=[
  40. ['department department','department.department_id=user.department_id','LEFT'],
  41. ];
  42. $this->alias('user')
  43. ->field('user.*,department_name')
  44. ->join($join);
  45. //获取用户信息
  46. if($condition){
  47. $this->where($condition);
  48. }
  49. $user_info=$this->find();
  50. return $user_info;
  51. }
  52. }