BindUser.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\models\user;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. class BindUser extends BaseModel
  6. {
  7. /**
  8. * 数据表主键
  9. * @var string
  10. */
  11. protected $pk = 'id';
  12. /**
  13. * 模型名称
  14. * @var string
  15. */
  16. protected $name = 'bind_user';
  17. use ModelTrait;
  18. /**
  19. * 创建用户信息记录
  20. */
  21. public static function addBindUser($openid, $nickname, $sex, $language, $city, $province, $country, $headimgurl, $type, $status, $mer_id = '')
  22. {
  23. $add_time = time();
  24. return self::create(compact('openid', 'nickname', 'sex', 'language', 'city', 'province', 'country', 'headimgurl', 'type', 'status', 'add_time', 'mer_id'));
  25. }
  26. /**
  27. * 更新用户信息记录
  28. */
  29. public static function editBindUser($openid, $nickname, $sex, $language, $city, $province, $country, $headimgurl)
  30. {
  31. return self::update(['openid' => $openid, 'nickname' => $nickname, 'sex' => $sex, 'language' => $language, 'city' => $city, 'province' => $province, 'country' => $country, 'headimgurl' => $headimgurl]);
  32. }
  33. /**
  34. * 绑定推送用户列表
  35. */
  36. public static function systemPage($where)
  37. {
  38. $model = self::setWhere($where);
  39. $count = $model->count();
  40. $list = $model->page((int)$where['page'], (int)$where['limit'])
  41. ->select();
  42. return compact('count', 'list');
  43. }
  44. /**
  45. * 设置 where 条件
  46. * @param $where
  47. * @param null $model
  48. * @return mixed
  49. */
  50. public static function setWhere($where, $model = null)
  51. {
  52. $model = $model === null ? new self() : $model;
  53. if (isset($where['mer_id']) && $where['mer_id'] != '') $model = $model->where('mer_id', $where['mer_id']);
  54. if (isset($where['nickname']) && $where['nickname'] != '') $model = $model->where('nickname', 'LIKE', "%$where[nickname]%");
  55. return $model->order('id desc')->where('is_del', 0);
  56. }
  57. }