You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
4.3 KiB
153 lines
4.3 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace addon\hygl\app\service\admin\user;
|
|
|
|
use addon\hygl\app\model\user\User;
|
|
|
|
use app\model\site\Site;
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 会员管理服务层
|
|
* Class UserService
|
|
* @package addon\hygl\app\service\admin\user
|
|
*/
|
|
class UserService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new User();
|
|
}
|
|
|
|
/**
|
|
* 获取会员管理列表
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getPage(array $where = [])
|
|
{
|
|
$field = 'id,site_id,tel,name,pic,password,pid,level,wx_openid,wx_unionid,sex,birthday,is_show,create_time,update_time,delete_time';
|
|
$order = 'id desc';
|
|
$search_model = $this->model->where([['site_id', "=", $this->site_id]])
|
|
->withSearch(["id", "tel", "name", "password", "sex", "birthday", "is_show"], $where)
|
|
->with([
|
|
'user' => function ($query) {
|
|
$query->field('id,pid,name')->withTrashed(); // 包含已被软删除的数据
|
|
},
|
|
])
|
|
->field($field)->order($order);
|
|
$list = $this->pageQuery($search_model);
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 获取会员管理信息
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function getInfo(int $id)
|
|
{
|
|
$field = 'id,site_id,tel,name,pic,pid,level,wx_openid,wx_unionid,sex,birthday,is_show,create_time,update_time,delete_time';
|
|
|
|
$info = $this->model->field($field)->where([['id', "=", $id]])->findOrEmpty()->toArray();
|
|
$info['sex'] = strval($info['sex']);
|
|
$info['is_show'] = strval($info['is_show']);
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 添加会员管理
|
|
* @param array $data
|
|
* @return mixed
|
|
*/
|
|
public function add(array $data)
|
|
{
|
|
$data['site_id'] = $this->site_id;
|
|
$res = $this->model->create($data);
|
|
return $res->id;
|
|
|
|
}
|
|
|
|
/**
|
|
* 会员管理编辑
|
|
* @param int $id
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public function edit(int $id, array $data)
|
|
{
|
|
|
|
$this->model->where([['id', '=', $id],['site_id', '=', $this->site_id]])->update($data);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 删除会员管理
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public function del(int $id)
|
|
{
|
|
$model = $this->model->where([['id', '=', $id],['site_id', '=', $this->site_id]])->find();
|
|
$res = $model->delete();
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 根据pid计算对应的用户层级
|
|
* @param int $pid 父级用户的id 0=顶级用户
|
|
*/
|
|
public function createLevel(int $pid = 0){
|
|
$level = 1;//1=顶级
|
|
if ($pid >= 1){
|
|
//根据pid查询父级用户的level,然后父级的level+1就是新用户的层级
|
|
$level = $this->model->where('id',$pid)->value('level') ?? 1;
|
|
$level = $level + 1;
|
|
}
|
|
return $level;
|
|
}
|
|
|
|
/**
|
|
* 检测手机号是否存在
|
|
* @param $tel 手机号
|
|
* @param null $id 医生id,有值则排除当前用户
|
|
* @return bool
|
|
*/
|
|
public function isTelExist($tel,$id=null){
|
|
$data = $this->model->where('tel',$tel)
|
|
->where('site_id',$this->site_id);
|
|
if ($id){
|
|
$data =$data->where('id','<>',$id);
|
|
}
|
|
$data = $data->value('id');
|
|
|
|
if ($data){
|
|
return true;//手机号存在
|
|
}
|
|
return false;//手机号不存在
|
|
}
|
|
|
|
public function getSiteAll(){
|
|
$siteModel = new Site();
|
|
return $siteModel->where([["site_id","=",$this->site_id]])->select()->toArray();
|
|
}
|
|
|
|
public function getUserAll(){
|
|
$userModel = new User();
|
|
return $userModel->where([["site_id","=",$this->site_id]])->select()->toArray();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|