123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class UserRetired extends Model
- {
- public function add(){
- $data = [
- 'user_id' => input('uid/d',0),
- 'jbgz' => input('jbgz/f','','trim'),
- 'txbt' => input('txbt/f','','trim'),
- 'bz' => input('bz/f','','trim'),
- 'zysdbt' => input('zysdbt/f','','trim'),
- 'fb' => input('fb/f','','trim'),
- 'bljx' => input('bljx/f','','trim'),
- 'jbtxf' => input('jbtxf/f','','trim'),
- 'wybt' => input('wybt/f','','trim'),
- 'dktc' => input('dktc/f','','trim')
- ];
- $result = validate('UserRetired')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('UserRetired')->getError());
- }
- $ubase = Db::name('user_retired')->where('user_id',$data['user_id'])->find();
- if($ubase){ // 修改
- $data['update_time'] = date('Y-m-d H:i:s');
- $res = Db::name('user_retired')->where('id',$ubase['id'])->update($data);
- } else {// 新增
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['update_time'] = date('Y-m-d H:i:s');
- $res = Db::name('user_retired')->insert($data);
- }
- if(!$res){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($uid){
- $info = Db::name('user_info')
- ->alias('ui')
- ->join('user_retired ure','ure.user_id = ui.user_id','left')
- ->where('ui.user_id',$uid)
- ->field('ure.*,ui.name as user_name,ui.gender,ui.user_id as uid')
- ->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info;
- }
- public function lists($page,$size,$orgId,$name,$phone){
- if($name != ''){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($phone != ''){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- $map[] = ['ui.company_id','=',1];
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $map[] = ['ui.pay_type','=',5];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->join('user_retired ure','ure.user_id = u.id','left')
- ->where($map)
- ->field('ure.*,u.phone,ui.name,ui.gender,ui.user_id as uid')
- ->page($page,$size)
- ->order('u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- // $map = empty($map)?true:$map;
- // $lists = Db::name('user_retired')
- // ->alias('ur')
- // ->join('user u','u.id = ur.user_id')
- // ->join('user_info ui','ui.user_id = ur.user_id')
- // ->where($map)
- // ->field('ur.*,u.phone,ui.name,ui.gender')
- // ->page($page,$size)
- // ->order('id desc')
- // ->select();
- $total = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->join('user_retired ure','ure.user_id = u.id','left')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function changeStatus($id,$enable){
- $ret = Db::name('user_retired')->where('id',$id)->setField('status',$enable);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function retiredUser($page,$size,$name,$phone,$orgId){
- $uids = Db::name('user_retired')->column('user_id');
- $map[] = ['ui.is_working','=',4];
- if($phone){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- $lists = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->field('u.id,u.phone,ui.name,ui.out_time,ui.out_reason,ui.gender')
- ->page($page,$size)
- ->order('ui.out_time desc,ui.id desc')
- ->select();
- $total = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- }
|