134 lines
5.3 KiB
PHP
134 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
估价师管理控制器
|
|
*/
|
|
namespace app\admin\controller;
|
|
use app\model\Attachment;
|
|
use think\Request;
|
|
|
|
class Valuer extends Base{
|
|
|
|
public $postData;
|
|
//构造函数
|
|
public function __construct(){
|
|
// if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
|
|
// header("Access-Control-Allow-Origin: *");
|
|
// header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
|
// header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH');
|
|
// exit;
|
|
// }
|
|
// parent::__construct();
|
|
$this->postData = $this->request->post();
|
|
return true;
|
|
}
|
|
|
|
//估价师列表
|
|
public function valuerList(){
|
|
$postData = $this->postData;
|
|
$page = $postData['page'];
|
|
$limit = $postData['limit'];
|
|
$where = '';
|
|
if(!empty($postData['keyword'])){
|
|
$where = 'num like "'.trim($postData['keyword']).'" or name like "'.trim($postData['keyword']).'"';
|
|
}
|
|
|
|
$list = \Db::name('valuer')->where($where)->page($page)->limit($limit)->select();
|
|
$count = \Db::name('valuer')->where($where)->count();
|
|
$lastList = [];
|
|
$att = new Attachment();
|
|
foreach ($list as $item){
|
|
$item['statusStr'] = $item['status'] == 1?'试用':'转正';
|
|
$item['attachments'] = $att->getUrls($item['fileids']);
|
|
$lastList['list'][] = $item;
|
|
}
|
|
$lastList['count'] = $count;
|
|
if($lastList) return $this->buildSuccess($lastList);
|
|
return $this->buildFailed('未获取到数据');
|
|
}
|
|
|
|
//添加估价师信息
|
|
public function addValuer(){
|
|
$postData = $this->postData;
|
|
|
|
if(!$postData['name']) return $this->buildFailed('姓名必须填写');
|
|
if(!$postData['certificate_number']) return $this->buildFailed('证书编号必须填写');
|
|
|
|
$data['name'] = trim($postData['name']);
|
|
$data['certificate_number'] = trim($postData['certificate_number']);
|
|
$data['mark'] = $postData['mark'] ? trim($postData['mark']):'';
|
|
$data['mobile'] = $postData['mobile'] ? trim($postData['mobile']):'';
|
|
if( strlen($postData['mobile']) > 11 ) return $this->buildFailed('手机号码太长了,只能输入11位');
|
|
if( strlen($postData['name']) > 50 ) return $this->buildFailed('输入姓名太长了');
|
|
if( strlen($postData['certificate_number']) > 50 ) return $this->buildFailed('证书编号太长了');
|
|
|
|
//验证手机格式
|
|
$mobile_pattern = "/^1[34578]\d{9}$/";
|
|
if(!empty($data['mobile']) && !preg_match($mobile_pattern,$data['mobile'])) return $this->buildFailed('手机号格式不正确!');
|
|
|
|
$data['fileids'] = '';
|
|
if($postData['fileids']) $data['fileids'] = join(',',$postData['fileids']);
|
|
|
|
$data['create_time'] = date('Y-m-d H:i:s');
|
|
$res = \Db::name('valuer')->insert($data);
|
|
if($res){
|
|
$result = [
|
|
'code' => 1,
|
|
'msg' => '添加成功',
|
|
];
|
|
$response = \Response::create($result, 'json');
|
|
return $response;
|
|
}
|
|
return $this->buildFailed('添加失败!');
|
|
}
|
|
|
|
//编辑估价师信息
|
|
public function editValuer(){
|
|
$postData = $this->postData;
|
|
$id = $postData['id'];
|
|
unset($postData['id']);
|
|
$postData['update_time'] = date('Y-m-d H:i:s');
|
|
|
|
if(!empty($postData['mobile']) && strlen($postData['mobile']) > 11 ) return $this->buildFailed('手机号码太长了,只能输入11位');
|
|
if(!empty($postData['name']) && strlen($postData['name']) > 50 ) return $this->buildFailed('输入姓名太长了');
|
|
if(!empty($postData['certificate_number']) && strlen($postData['certificate_number']) > 50 ) return $this->buildFailed('证书编号太长了');
|
|
|
|
$mobile_pattern = "/^1[34578]\d{9}$/";
|
|
if(!empty($postData['mobile']) && !preg_match($mobile_pattern,$postData['mobile'])) return $this->buildFailed('手机号格式不正确!');
|
|
// print_r( $postData['fileids']);
|
|
$postData['fileids'] = join(',',$postData['fileids']);
|
|
// print_r( $postData);die;
|
|
$res = \Db::name('valuer')->where('id',$id)->update($postData);
|
|
if($res){
|
|
$result = [
|
|
'code' => 1,
|
|
'msg' => '编辑成功',
|
|
];
|
|
$response = \Response::create($result, 'json');
|
|
return $response;
|
|
}
|
|
return $this->buildFailed('编辑失败!');
|
|
}
|
|
|
|
//编辑的时候获取估价师信息
|
|
public function getValuerInfoById(){
|
|
$postData = $this->postData;
|
|
$id = $postData['id'];
|
|
$res = \Db::name('valuer')->where('id',$id)->find();
|
|
if(empty($res)){
|
|
return $this->buildFailed('没有找到要编辑的估价师信息');
|
|
}
|
|
$attachment = new Attachment();
|
|
$fileids = $res['fileids'];
|
|
$fileArr = $fileids ? explode(',',$fileids):[];
|
|
$picArr = [];
|
|
if($fileArr){
|
|
foreach ($fileArr as $fileid){
|
|
$picinfo = \Db::name('attachment')->where('id', $fileid)->field('name,url,id,ext')->find();
|
|
$picinfo['url'] = config('uploadFile.url') . $picinfo['url'];
|
|
$picArr[] = $picinfo;
|
|
}
|
|
}
|
|
$res['pic_info'] = $picArr;
|
|
return $this->buildSuccess($res);
|
|
}
|
|
} |