input('uid/d',0), 'qynj' => input('qynj/f',0), 'gjj' => input('gjj/f',0), 'sb' => input('sb/f',0), 'syyl' => input('syyl/f',0), 'gssy' => input('gssy/f',0), 'ylnj' => input('ylnj/f',0), ]; $result = validate('UserBase')->check($data,[],''); if(true !== $result){ HelpHander::error(validate('UserBase')->getError()); } $ubase = Db::name('user_base')->where('user_id',$data['user_id'])->find(); if($ubase){ // 修改 $data['update_time'] = date('Y-m-d H:i:s'); $res = Db::name('user_base')->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_base')->insert($data); } if(!$res){ HelpHander::error('操作失败'); } return true; } public function info($id){ $info = $this->where('id',$id)->find(); if(!$info){ HelpHander::error('数据不存在'); } $data = $info->toArray(); $data['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name'); return $data; } public function lists($page,$size,$name,$phone,$companyId,$orgId){ if($name != ''){ $map[] = ['ui.name','like','%'.$name.'%']; } if($phone != ''){ $map[] = ['u.phone','like','%'.$phone.'%']; } if($companyId > 0){ $map[] = ['ui.company_id','=',$companyId]; } $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]; $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_base ub','ub.user_id = u.id','left') ->where($map) ->field('ub.*,u.phone,ui.name,ui.gender,ui.user_id as uid') ->page($page,$size) ->order('u.id desc') ->select(); $lists = $lists?$lists:[]; /*$lists = Db::name('user_base') ->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(); $bls = Db::name('user_bl')->select(); foreach ($lists as $k=>$v){ $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['gjjp'] = $lists[$k]['gjjc'] = 0; $lists[$k]['qynjp'] = $lists[$k]['qynjc'] = 0; $lists[$k]['sbylap'] = $lists[$k]['sbylac'] = 0; $lists[$k]['sbsyep'] = $lists[$k]['sbsyep'] = 0; $lists[$k]['sbylip'] = $lists[$k]['sbylic'] = 0; $lists[$k]['sbgsc'] = $lists[$k]['sbsyuc'] = 0; $sbhj = $gjjhj = $qynjhj = 0; // 计算各项扣除 foreach ($bls as $key=>$val){ if($val['company_id'] == $v['company_id']){ switch ($val['name']){ case 'gjj': $lists[$k]['gjjp'] = calculate_money($v['gjj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['gjjc'] = calculate_money($v['gjj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); $gjjhj = round($lists[$k]['gjjp'] + $lists[$k]['gjjc'],2); break; case 'qynj': if($val['company_id'] == 1){ $lists[$k]['qynjp'] = calculate_money($v['ylnj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['qynjc'] = calculate_money($v['ylnj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } else { $lists[$k]['qynjp'] = calculate_money($v['qynj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['qynjc'] = calculate_money($v['qynj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } $qynjhj = round($lists[$k]['qynjp'] + $lists[$k]['qynjc'],2); break; case 'yla': if($val['company_id'] == 1){ $lists[$k]['sbylap'] = calculate_money($v['ylnj'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['sbylac'] = calculate_money($v['ylnj'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } else { $lists[$k]['sbylap'] = calculate_money($v['sb'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['sbylac'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } $sbhj += $lists[$k]['sbylap']; $sbhj += $lists[$k]['sbylac']; break; case 'sye': if($val['company_id'] == 1){ $lists[$k]['sbsyep'] = calculate_money($v['gssy'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['sbsyec'] = calculate_money($v['gssy'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } else { $lists[$k]['sbsyep'] = calculate_money($v['sb'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['sbsyec'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } $sbhj += $lists[$k]['sbsyep']; $sbhj += $lists[$k]['sbsyec']; break; case 'yli': if($val['company_id'] == 1){ $lists[$k]['sbylip'] = calculate_money($v['syyl'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['sbylic'] = calculate_money($v['syyl'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } else { $lists[$k]['sbylip'] = calculate_money($v['sb'],$val['p_bl'],$val['p_bl_type'],$val['p_bl_extra'],$val['p_free_bl']); $lists[$k]['sbylic'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } $sbhj += $lists[$k]['sbylip']; $sbhj += $lists[$k]['sbylic']; break; case 'gs': if($val['company_id'] == 1){ $lists[$k]['sbgsc'] = calculate_money($v['gssy'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } else { $lists[$k]['sbgsc'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } $sbhj += $lists[$k]['sbgsc']; break; case 'syu': if($val['company_id'] == 1){ $lists[$k]['sbsyuc'] = calculate_money($v['gssy'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } else { $lists[$k]['sbsyuc'] = calculate_money($v['sb'],$val['c_bl'],$val['c_bl_type'],$val['c_bl_extra'],$val['c_free_bl']); } $sbhj += $lists[$k]['sbsyuc']; break; } } } $lists[$k]['sbhj'] = round($sbhj,2); $lists[$k]['gjjhj'] = round($sbhj,2); $lists[$k]['qynjhj'] = round($qynjhj,2); }*/ $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_base ub','ub.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; } }