204 lines
7.5 KiB
PHP
204 lines
7.5 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\model\Valuer;
|
||
use app\model\Attachment;
|
||
use think\Db;
|
||
|
||
class ValuerSetUp extends Base
|
||
{
|
||
public $status_arr = ["1"=>"全职", "2"=>"兼职", "3"=>"离职"];
|
||
public $default_arr = ["1"=>"是", "2"=>"否"];
|
||
/**
|
||
* 估价师列表
|
||
* @author cavan
|
||
*/
|
||
public function ValuerList()
|
||
{
|
||
$keyword = $this->request->post('keyword', '','trim'); //姓名搜索
|
||
$page = $this->request->post('page', '','trim'); //页码
|
||
$size = $this->request->post('limit', '','trim'); //单页数量
|
||
|
||
|
||
$where = array();
|
||
if(!empty($keyword)){
|
||
$where[]=['name','like',"%".$keyword."%"];
|
||
}
|
||
if(empty($order)){
|
||
$order=json_encode(array('create_time'=>'desc'));
|
||
}
|
||
if(empty($page)){
|
||
$page=1;
|
||
}
|
||
if(empty($size)){
|
||
$size=10;
|
||
}
|
||
|
||
$config = array(
|
||
"list_rows" => $size,
|
||
"page" => $page
|
||
);
|
||
|
||
$Valuer = new Valuer();
|
||
$Attachment = new Attachment();
|
||
|
||
$resultData=$Valuer->where($where)
|
||
->order(json_decode($order,true))
|
||
->field('id,name,mobile,certificate_number,status,mark,certificate,autograph,create_time,update_time,updated_by,default')
|
||
->paginate($size,false,$config);
|
||
|
||
if(!empty($resultData)){
|
||
foreach ($resultData as $k => $v){
|
||
$resultData[$k]['certificate_file'] = !empty($v['certificate'])?$Attachment->getUrl($v['certificate']):"";
|
||
$resultData[$k]['autograph_file'] = !empty($v['autograph'])?$Attachment->getUrl($v['autograph']):"";
|
||
$resultData[$k]['status_name'] = $this->status_arr[$v['status']];
|
||
$resultData[$k]['default_name'] = $this->default_arr[$v['default']];
|
||
$resultData[$k]['time'] = !empty($v['update_time'])?date("Y-m-d H:i:s",$v['update_time']):date("Y-m-d H:i:s",$v['create_time']);
|
||
}
|
||
}
|
||
|
||
return $this->buildSuccess($resultData);
|
||
}
|
||
|
||
/**
|
||
* 估价师详情--修改调用接口
|
||
* @author cavan
|
||
*
|
||
*/
|
||
public function ValuerDetails(){
|
||
$id = $this->request->post('id', '', 'trim');
|
||
if(!$id){
|
||
return $this->buildFailed("缺少参数id");
|
||
}
|
||
$Valuer = new Valuer();
|
||
$Attachment = new Attachment();
|
||
//主表信息
|
||
$list = $Valuer->where("id",$id)
|
||
->field("id,name,mobile,certificate_number,status,mark,certificate,autograph,default")
|
||
->find();
|
||
if(!empty($list)){
|
||
$list['status_name'] = $this->status_arr[$list['status']];
|
||
$list['default_name'] = $this->default_arr[$list['default']];
|
||
$list['certificate_file'] = !empty($list['certificate'])?$Attachment->getUrl($list['certificate']):"";
|
||
$list['autograph_file'] = !empty($list['autograph'])?$Attachment->getUrl($list['autograph']):"";
|
||
}
|
||
|
||
return $this->buildSuccess($list);
|
||
}
|
||
|
||
/**
|
||
* 新增/修改估价师
|
||
* @author cavan
|
||
*
|
||
* @parameter name 姓名
|
||
* @parameter mobile 手机号
|
||
* @parameter certificate_number 证书编号
|
||
* @parameter status 状态 1、全职 2、兼职 3、离职
|
||
* @parameter mark 备注
|
||
* @parameter certificate 上传证书,附件表id
|
||
* @parameter autograph 上传签名,附件表id
|
||
* @parameter default 默认选中
|
||
*/
|
||
public function save()
|
||
{
|
||
$id = $this->request->post('id', '', 'trim');
|
||
$name = $this->request->post('name', '', 'trim');
|
||
$mobile = $this->request->post('mobile', '', 'trim');
|
||
$certificate_number = $this->request->post('certificate_number', '', 'trim');
|
||
$status = $this->request->post('status', '', 'trim');
|
||
$mark = $this->request->post('mark', '', 'trim');
|
||
$certificate = $this->request->post('certificate', '', 'trim');
|
||
$autograph = $this->request->post('autograph', '', 'trim');
|
||
$default = $this->request->post('default', '', 'trim');
|
||
if (!$name) {
|
||
return $this->buildFailed("姓名不能为空");
|
||
}else{
|
||
if( strlen($name) > 50 ) return $this->buildFailed('输入姓名太长了');
|
||
}
|
||
if (!$mobile) {
|
||
return $this->buildFailed("手机号不能为空");
|
||
}else{
|
||
if( strlen($mobile) > 11 ) return $this->buildFailed('手机号码太长了,只能输入11位');
|
||
//验证手机格式
|
||
$mobile_pattern = "/^1[34578]\d{9}$/";
|
||
if(!empty($mobile) && !preg_match($mobile_pattern,$mobile)) return $this->buildFailed('手机号格式不正确!');
|
||
}
|
||
if (!$certificate_number) {
|
||
return $this->buildFailed("证书编号不能为空");
|
||
}else{
|
||
if( strlen($certificate_number) > 50 ) return $this->buildFailed('输入姓名太长了');
|
||
}
|
||
if (!$status) {
|
||
return $this->buildFailed("在职状态为必选项");
|
||
}
|
||
if (!$certificate) {
|
||
return $this->buildFailed("上传证书不能为空");
|
||
}
|
||
if (!$autograph) {
|
||
return $this->buildFailed("上传签名不能为空");
|
||
}
|
||
if (!$default) {
|
||
$default = 2;
|
||
}
|
||
|
||
$Valuer = new Valuer();
|
||
|
||
// 2020年7月28日14:20:24 cavan
|
||
if(intval($default) == 1){
|
||
if($id){
|
||
$num = $Valuer->where("id","<>",$id)->where("default",1)->count();
|
||
if($num >= 2){
|
||
return $this->buildFailed("不可配置超过两个估价师默认选中,请先取消其他估价师的默认选中");
|
||
}
|
||
}else{
|
||
$num = $Valuer->where("default",1)->count();
|
||
if($num >= 2){
|
||
return $this->buildFailed("不可配置超过两个估价师默认选中,请先取消其他估价师的默认选中");
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
$insert_data['name'] = $name;
|
||
$insert_data['mobile'] = $mobile;
|
||
$insert_data['certificate_number'] = $certificate_number;
|
||
$insert_data['status'] = $status;
|
||
$insert_data['mark'] = $mark;
|
||
$insert_data['certificate'] = $certificate;
|
||
$insert_data['autograph'] = $autograph;
|
||
$insert_data['default'] = $default;
|
||
$insert_data['updated_by'] = $this->userInfo['user_name'];
|
||
if($id){
|
||
Db::startTrans();
|
||
try {
|
||
$insert_data['update_time'] = time();
|
||
$Valuer->where("id",$id)->update($insert_data);
|
||
$msg = "编辑成功";
|
||
// 提交事务
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $e->getMessage();
|
||
}
|
||
}else{
|
||
Db::startTrans();
|
||
try {
|
||
$insert_data['create_time'] = time();
|
||
$id = $Valuer->insertGetId($insert_data);
|
||
$msg = "保存成功";
|
||
// 提交事务
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $e->getMessage();
|
||
}
|
||
}
|
||
return $this->buildSuccess([],"保存成功");
|
||
}
|
||
|
||
|
||
}
|