12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use app\Request;
- use think\Db;
- use think\Model;
- class HouseAuth extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'user_id' => input('uid/d',0),
- 'type' => input('type/d',1),
- 'org_id' => input('orgId/d',0),
- 'remind' => input('remind/d',0),
- 'ids' => input('ids','','trim'),
- ];
- $result = validate('HouseAuth')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('HouseAuth')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function del($id){
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$title,$type,$orgId){
- $map[] = ['ha.type','=',$type];
- $map[] = ['ha.org_id','=',$orgId];
- if($title != ''){
- $map[] = ['ui.name','like','%'.$title.'%'];
- }
- $lists = Db::name('house_auth')
- ->alias('ha')
- ->join('user_info ui','ui.user_id = ha.user_id')
- ->field('ha.*,ui.name as userName')
- ->where($map)
- ->page($page,$size)
- ->order('ha.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- if($v['ids']){
- $auths = Db::name('house_level')->where('id','in',$v['ids'])->column('title');
- $lists[$k]['auth'] = implode(',',$auths);
- }else{
- $lists[$k]['auth'] = '';
- }
- }
- $total = Db::name('house_auth')
- ->alias('ha')
- ->join('user_info ui','ui.user_id = ha.user_id')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- }
|