762 lines
32 KiB
PHP
762 lines
32 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
use app\admin\service\SurveyService;
|
|
|
|
use app\common\validate\SurveyValidate;
|
|
use app\model\Survey as SurveyModel;
|
|
use app\model\SurveyDetail as SurveyDetailModel;
|
|
use app\model\Inquiry as InquiryModel;
|
|
use app\model\Property_cert_info as InquiryDetailModel;
|
|
use app\model\Report as ReportModel;
|
|
use app\model\Region ;
|
|
use app\common\validate\ReportValidate;
|
|
use app\model\OptionsAutomation;
|
|
use app\util\Tools;
|
|
use app\util\ReturnCode;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 查勘控制器
|
|
* @author zhong
|
|
*
|
|
* Class Survey
|
|
* @package app\admin\controller
|
|
*/
|
|
class Survey extends Base
|
|
{
|
|
|
|
/**
|
|
* @api {get} admin/survey/index 我的查勘列表
|
|
* @author zdc
|
|
*/
|
|
public function index(SurveyModel $survey)
|
|
{
|
|
$data = $this->request->get();
|
|
|
|
//2020年5月24日14:03:28 cavan
|
|
if(empty($this->userInfo)){
|
|
return $this->buildFailed("获取查勘列表失败,因用户信息为空,请重新登录","",ReturnCode::AUTH_ERROR);
|
|
}
|
|
|
|
if (!$this->isAdmin() && !$this->isAppraiser()) {
|
|
//$data['user_id'] = $this->userInfo['user_ids'] ? implode(',', $this->userInfo['user_ids']) : ''; //权限
|
|
$data['user_id'] = array($this->userInfo['user_id']);
|
|
|
|
}
|
|
$res = $survey->getSurveyList($this->getPage(), $data);
|
|
return $this->buildSuccess($res);
|
|
}
|
|
|
|
|
|
/**
|
|
* @api {get} admin/survey/exportList 导出我的查勘列表
|
|
*/
|
|
public function exportList(SurveyModel $survey){
|
|
$data = $this->request->post();
|
|
if(empty($this->userInfo)){
|
|
return $this->buildFailed("导出查勘列表失败,因用户信息为空,请重新登录","",ReturnCode::AUTH_ERROR);
|
|
}
|
|
if (!$this->isAdmin()) {
|
|
$data['user_id'] = $this->userInfo['user_id'];
|
|
}
|
|
$res = $survey->exportSurveyList($data);
|
|
$indexKey = ['order_no', 'city', 'area', 'property_full_name', 'type_str','is_multi_str', 'survey_status_str', 'status_str', 'size', 'eva_unit_price', 'eva_total_value', 'eva_net_value', 'eva_net_value2', 'bank_name', 'create_time', 'user_name', 'survey_time', 'survey_user_name'];
|
|
$indexValue = ['单号', '城市','小片区', '物业名称', '物业类型', '询价套数', '查勘状态', '订单状态', '面积', '单价', '评估总值', '评估净值1', '评估净值2', '银行', '询价时间', '业务员', '查勘完成时间', '查勘员'];
|
|
(new ChargeManage())->exportExcel($res, 'survey_'.date('Ymd'), $indexKey, $indexValue);
|
|
}
|
|
|
|
|
|
public function save()
|
|
{
|
|
|
|
}
|
|
|
|
public function read($id)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* 退回到待派单
|
|
*
|
|
* @return \think\Response
|
|
* @throws \app\admin\exception\LogicException
|
|
*/
|
|
public function returnSurveyToAsked()
|
|
{
|
|
$data = $this->request->post();
|
|
|
|
$surveyService = new SurveyService();
|
|
$res = $surveyService->return_survey_to_asked($this->userInfo['user_id'], $data);
|
|
if ($res['code'] != 1){
|
|
return $this->buildFailed($res['message']);
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
/**
|
|
* 退回(废单)
|
|
*
|
|
* @return \think\Response
|
|
* @throws \app\admin\exception\LogicException
|
|
*/
|
|
public function reqSubmitSurveyReturn()
|
|
{
|
|
$data = $this->request->post();
|
|
$validate = new SurveyValidate();
|
|
if (!$validate->scene(SurveyValidate::SCENE_RETURN)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$surveyService = new SurveyService();
|
|
$res = $surveyService->return_survey($this->userInfo['user_id'], $data);
|
|
if ($res['code'] != 1){
|
|
return $this->buildFailed($res['message']);
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
|
|
/**
|
|
* @api {post} admin/survey/reqSurveyInfo 查勘详情
|
|
* @author zdc
|
|
*/
|
|
public function reqSurveyInfo(SurveyModel $survey)
|
|
{
|
|
$data = $this->request->post();
|
|
$validate = new SurveyValidate();
|
|
if (!$validate->scene(SurveyValidate::SURVEY_DETAIL)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$res = $survey->getSurveyDetail($data);
|
|
return $this->buildSuccess($res);
|
|
}
|
|
|
|
/**
|
|
* @api {post} admin/survey/getBuildingInfo 获取楼盘
|
|
* @author zdc
|
|
*/
|
|
public function getBuildingInfo(InquiryDetailModel $estate)
|
|
{
|
|
$quot_id = $this->request->post('quot_id');
|
|
$res = $estate->field('id,building_name')->where(['quot_id' => $quot_id])->select();
|
|
return $this->buildSuccess($res);
|
|
}
|
|
|
|
/**
|
|
* @api {post} admin/survey/addReport 生成报告
|
|
* @author zdc
|
|
*/
|
|
public function addReport(ReportModel $report)
|
|
{
|
|
$data['id'] = $this->request->post('id');
|
|
$data['details'] = $this->request->post('details/a');
|
|
if (empty($data['details'])) return $this->buildFailed('房产信息不能为空!');
|
|
$validate = new ReportValidate();
|
|
foreach ($data['details'] as $key => $value) {
|
|
if (!$validate->check($value)) {
|
|
return $this->buildFailed($validate->getError());
|
|
}
|
|
}
|
|
|
|
$result = $report->createReport($data, $this->userInfo['user_id']);
|
|
if ($result != true) {
|
|
return $this->buildFailed('操作失败', $result);
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
|
|
/**
|
|
*查勘任务指派列表
|
|
*/
|
|
public function reqAssignSurveyOrder(){
|
|
$data = $this->request->post();
|
|
$recordDate = $this->getQueryDateTime();
|
|
$validate=new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_APPOINT)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$where = self::getWhere();
|
|
if($this->isAdmin()) {
|
|
|
|
}else if(in_array('Surveyor', $this->userInfo['roleCode']) && !in_array('Evaluation_salesman', $this->userInfo['roleCode']) && !in_array('general_manager', $this->userInfo['roleCode'])){
|
|
$where[] = ['survey.user_id' , '=' , $this->userInfo['user_id']];
|
|
} elseif (in_array('Evaluation_salesman', $this->userInfo['roleCode']) || in_array('Business_manager', $this->userInfo['roleCode'])) {
|
|
//$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
} elseif (in_array('general_manager', $this->userInfo['roleCode'])) {
|
|
//$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
}else
|
|
{
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
}
|
|
|
|
$where[]= ['survey.status' , '=' , 1];
|
|
!empty($recordDate) && $where[] = ['survey.create_time' ,$recordDate[0] , $recordDate[1]];
|
|
!empty($keyword) && $where[] = ['i.order_no|ind.property_full_name','like','%'.$data['keyword'].'%'];
|
|
$res=SurveyModel::getSurveyList1($where,$this->getPage(),'survey.create_time','survey.id');
|
|
|
|
return $this->buildSuccess(['list' => $res['data'], 'count' => $res['total']]);
|
|
}
|
|
|
|
/**
|
|
*查勘待跟进列表
|
|
*/
|
|
public function reqFollowSurveyList(){
|
|
$data = $this->request->post();
|
|
$recordDate = $this->getQueryDateTime();
|
|
|
|
$validate=new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_WAIT)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$where = self::getWhere();
|
|
// 权限控制
|
|
// if(in_array('Surveyor', $this->userInfo['roleCode']) && !in_array('Evaluation_salesman', $this->userInfo['roleCode'])){
|
|
// $where[] = ['survey.user_id' , '=' , $this->userInfo['user_id']];
|
|
// } elseif ((in_array('Evaluation_salesman', $this->userInfo['roleCode']) && in_array('Surveyor', $this->userInfo['roleCode'])) || in_array('Business_manager', $this->userInfo['roleCode'])) {
|
|
// $where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
// }
|
|
if($this->isAdmin()) {
|
|
|
|
}else if(in_array('Surveyor', $this->userInfo['roleCode']) && !in_array('Evaluation_salesman', $this->userInfo['roleCode']) && !in_array('general_manager', $this->userInfo['roleCode'])){
|
|
$where[] = ['survey.user_id' , '=' , $this->userInfo['user_id']];
|
|
} elseif (in_array('Evaluation_salesman', $this->userInfo['roleCode']) || in_array('Business_manager', $this->userInfo['roleCode'])) {
|
|
//$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
} elseif (in_array('general_manager', $this->userInfo['roleCode'])) {
|
|
//$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
}
|
|
else
|
|
{
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
}
|
|
$where[]= ['survey.status', '=', 2];
|
|
!empty($recordDate) && $where[] = ['survey.assign_time' ,$recordDate[0] , $recordDate[1]];
|
|
$res=SurveyModel::getSurveyList1($where,$this->getPage(),'survey.assign_time');
|
|
|
|
return $this->buildSuccess(['list' => $res['data'], 'count' => $res['total']]);
|
|
}
|
|
|
|
/**
|
|
* 查勘已完成列表
|
|
*/
|
|
public function reqCompletedSurveyList(){
|
|
$data = $this->request->post();
|
|
$recordDate = $this->getQueryDateTime();
|
|
|
|
$validate=new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_FINISH)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$where = self::getWhere();
|
|
// 权限控制
|
|
// if(in_array('Surveyor', $this->userInfo['roleCode']) && !in_array('Evaluation_salesman', $this->userInfo['roleCode'])){
|
|
// $where[] = ['survey.user_id' , '=' , $this->userInfo['user_id']];
|
|
// } elseif ((in_array('Evaluation_salesman', $this->userInfo['roleCode']) && in_array('Surveyor', $this->userInfo['roleCode'])) || in_array('Business_manager', $this->userInfo['roleCode'])) {
|
|
// $where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
// }
|
|
|
|
if($this->isAdmin()) {
|
|
}else if(in_array('Surveyor', $this->userInfo['roleCode']) && !in_array('Evaluation_salesman', $this->userInfo['roleCode']) && !in_array('general_manager', $this->userInfo['roleCode'])){
|
|
$where[] = ['survey.user_id' , '=' , $this->userInfo['user_id']];
|
|
} elseif (in_array('Evaluation_salesman', $this->userInfo['roleCode']) || in_array('Business_manager', $this->userInfo['roleCode'])) {
|
|
//$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
} elseif (in_array('general_manager', $this->userInfo['roleCode'])) {
|
|
$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
} else
|
|
{
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
}
|
|
|
|
$where[]= ['survey.status', '=', 3];
|
|
!empty($recordDate) && $where[] = ['survey.complete_time' ,$recordDate[0] , $recordDate[1]];
|
|
$res=SurveyModel::getSurveyList1($where,$this->getPage(),'survey.complete_time desc');
|
|
|
|
return $this->buildSuccess(['list' => $res['data'], 'count' => $res['total']]);
|
|
}
|
|
|
|
/**
|
|
*查勘订单退回列表
|
|
*/
|
|
public function reqSurveyReturnList(){
|
|
$data = $this->request->post();
|
|
$recordDate = $this->getQueryDateTime();
|
|
|
|
$validate=new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_BACK)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$where = self::getWhere();
|
|
if($this->isAdmin()) {
|
|
}else if(in_array('Surveyor', $this->userInfo['roleCode']) && !in_array('Evaluation_salesman', $this->userInfo['roleCode']) && !in_array('general_manager', $this->userInfo['roleCode'])){
|
|
$where[] = ['survey.user_id' , '=' , $this->userInfo['user_id']];
|
|
} elseif (in_array('Evaluation_salesman', $this->userInfo['roleCode']) || in_array('Business_manager', $this->userInfo['roleCode'])) {
|
|
//$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
} elseif (in_array('general_manager', $this->userInfo['roleCode'])) {
|
|
$where[] = ['i.user_id|survey.user_id', 'in', $this->userInfo['user_ids']];
|
|
} else
|
|
{
|
|
$where[] = ['i.user_id|survey.user_id', '=', $this->userInfo['user_id']];
|
|
}
|
|
|
|
$where[]= ['survey.status' , '=' , 4];
|
|
!empty($recordDate) && $where[] = ['survey.create_time' ,$recordDate[0] , $recordDate[1]];
|
|
|
|
$res=SurveyModel::getSurveyList1($where,$this->getPage(),'survey.create_time');
|
|
|
|
return $this->buildSuccess(['list' => $res['data'], 'count' => $res['total']]);
|
|
}
|
|
|
|
/**
|
|
*查勘任务退回列表删除按钮
|
|
*/
|
|
public function reqDelSurveyReturnOrder(){
|
|
$data = $this->request->post();
|
|
if (empty($data['survey_ids'])) return $this->buildFailed('请选择需要删除的查勘!');
|
|
|
|
Db::startTrans();
|
|
try {
|
|
foreach ($data['survey_ids'] as $key => $value) {
|
|
$db = new SurveyModel();
|
|
$survey = $db->where('id', $value)->find();
|
|
$building_name = Db::name('property_cert_info')->where('id', $survey['property_cert_info_id'])->value('property_full_name');
|
|
if ($survey['status'] != SurveyModel::STATUS_ASKED && $survey['status'] != SurveyModel::STATUS_RETURNED) {
|
|
return $this->buildFailed($building_name.'的查勘目前暂无法删除');
|
|
}
|
|
$upd['status'] = 5;
|
|
$upd['update_time'] = date('Y-m-d H:i:s', time());
|
|
$upd['delete_time'] = date('Y-m-d H:i:s', time());
|
|
$db->where('id', $survey['id'])->update($upd);
|
|
}
|
|
// 提交事务
|
|
Db::commit();
|
|
return $this->buildSuccess('删除成功');
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
Db::rollback();
|
|
return $this->buildFailed('删除失败'.$e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function getWhere($where = []){
|
|
$workUsername=input('workUsername');
|
|
$keyword=input('keyword');
|
|
$surveyUsername=input('surveyUsername');
|
|
$city=input('city');
|
|
$area=input('area');
|
|
$inquiry_status=input('inquiry_status');
|
|
!empty($workUsername) && $where[] = ['i.buss_username' , 'like','%'.$workUsername.'%'];
|
|
!empty($keyword) && $where[] = ['i.order_no|ind.property_full_name','like','%'.$keyword.'%'];
|
|
!empty($surveyUsername) && $where[] = ['survey.user_name' , 'like','%'.$surveyUsername.'%'];
|
|
!empty($city) && $where[] = ['ind.city_id' , '=' , $city];
|
|
!empty($area) && $where[] = ['survey.area_id' , '=' , $area];
|
|
!empty($inquiry_status) && $where[] = ['i.status' , '=' , $inquiry_status];
|
|
return $where;
|
|
|
|
}
|
|
|
|
/**
|
|
*指派查勘员
|
|
*/
|
|
public function reqAppointedToSurveyor(){
|
|
$surveyIds=input('survey_ids');
|
|
$surveyUserId=input('surveyUserId');
|
|
$surveyName=input('surveyName');
|
|
$surveyPhone=input('surveyPhone');
|
|
$data = $this->request->post();
|
|
$validate=new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_SURVEYUSER)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$building_name = [];
|
|
Db::startTrans();
|
|
try {
|
|
foreach ($data['survey_ids'] as $k => $v) {
|
|
$db=new SurveyModel();
|
|
$InquiryModel = new InquiryModel();
|
|
$survey=$db->where('id',$v)->find();
|
|
if ($survey['status'] != SurveyModel::STATUS_ASKED && $survey['status'] != SurveyModel::STATUS_RETURNED)
|
|
return $this->buildFailed('该查勘目前状态暂无法提交');
|
|
$building_name[] = Db::name('property_cert_info')->where('id' , $survey['property_cert_info_id'])->value('property_full_name');
|
|
$a['user_id']=$data['surveyUserId'];
|
|
$a['user_name']=$data['surveyName'];
|
|
$a['assignee_id']= $this->userInfo['user_id'];
|
|
$a['status']=2;
|
|
$a['assign_time']=date('Y-m-d H:i:s',time());
|
|
$db->where('id',$survey['id'])->update($a);
|
|
$result = $db->where(['order_no' => $survey['order_no'] , 'status' => ['in' , '1,4']])->find();
|
|
if(!$result){
|
|
$InquiryModel->where('order_no' , $survey['order_no'])->update(['status' => 4]);
|
|
}
|
|
}
|
|
|
|
|
|
PublicMessage($InquiryModel->where('order_no' , $survey['order_no'])->value('id'),5,6,$survey['property_cert_info_id']); // 消息推送
|
|
// 提交事务
|
|
Db::commit();
|
|
return $this->buildSuccess('指派成功');
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
Db::rollback();
|
|
return $this->buildFailed('指派失败'.$e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
*转派查勘员
|
|
*/
|
|
public function transferSurveyUser(){
|
|
$data = $this->request->post();
|
|
$validate = new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_TRANSFER_SURVEYUSER)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
|
|
Db::startTrans();
|
|
try{
|
|
$db = new SurveyModel();
|
|
$survey = $db->where('id',$data['survey_id'])->find();
|
|
if ($survey['status'] != SurveyModel::STATUS_ASSIGNED)
|
|
return $this->buildFailed('该查勘目前状态暂无法提交');
|
|
|
|
if($survey['user_name'] == $data['surveyName'])
|
|
return $this->buildFailed('转派查勘员不可与现查勘员相同');
|
|
|
|
$update['user_id'] = $data['surveyUserId'];
|
|
$update['user_name'] = $data['surveyName'];
|
|
$update['assignee_id'] = $this->userInfo['user_id'];
|
|
$update['assign_time'] = date('Y-m-d H:i:s',time());
|
|
$db->where('id',$survey['id'])->update($update);
|
|
|
|
//写入消息
|
|
$InquiryModel = new InquiryModel();
|
|
PublicMessage($InquiryModel->where('order_no' , $survey['order_no'])->value('id'),5,6,$survey['property_cert_info_id']); // 消息推送
|
|
|
|
Db::commit();
|
|
return $this->buildSuccess('指派成功');
|
|
} catch (\Exception $e){
|
|
Db::rollback();
|
|
return $this->buildFailed('改派失败'.$e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
*查勘细项
|
|
*/
|
|
public function surveyOptions(){
|
|
$db=new OptionsAutomation();
|
|
$res=$db->column('id,pid,name,survey_type,type,key,key2,code,value,text');
|
|
$tree=$this->listToTree($res,'id','pid');
|
|
return $this->buildSuccess($tree);
|
|
}
|
|
|
|
/**
|
|
*查勘细项
|
|
*/
|
|
public function surveyOptionsList(){
|
|
$db=new OptionsAutomation();
|
|
$res=$db->column('id,pid,name,survey_type,type,key,key2,code,value,text');
|
|
$tree=$this->listToTree($res,'id','pid');
|
|
return $tree;
|
|
}
|
|
/**
|
|
*提交查勘
|
|
*/
|
|
public function reqSubmitSurvey(){
|
|
$data = $this->request->post();
|
|
$validate=new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_SUBMIT)->batch()->check($data)){
|
|
return $this->buildFailed('数据验证失败',$validate->getError());
|
|
}
|
|
$surveyService = new SurveyService();
|
|
$data=$this->changeArrayToString($data);
|
|
$res = $surveyService->survey_detail($this->userInfo['user_id'],$data);
|
|
if ($res['code'] == -1){
|
|
return $this->buildFailed($res['message']);
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
|
|
/**
|
|
* 查勘退回到待跟进
|
|
*/
|
|
public function surveyReturn(){
|
|
$id = $this->request->post('id');
|
|
$order_no = Db::name('survey')->where('id='.$id)->value('order_no');
|
|
Db::startTrans();
|
|
$survey_upd = Db::name('survey')->where('id='.$id)->update(['status' => 2]);
|
|
$inquiry_upd = Db::name('inquiry')->where('order_no', $order_no)->update(['status' => 4]);
|
|
if ($survey_upd && $inquiry_upd) {
|
|
Db::commit();
|
|
return $this->buildSuccess();
|
|
} else {
|
|
Db::rollback();
|
|
return $this->buildFailed('查勘退回到待跟进失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
*编辑查勘
|
|
*/
|
|
public function reqEditSurvey(){
|
|
$data = $this->request->post();
|
|
//查勘信息
|
|
$validate=new SurveyValidate();
|
|
if(!$validate->scene(SurveyValidate::SCENE_SUBMIT)->batch()->check($data)){
|
|
return $this->buildFailed($validate->getError());
|
|
}
|
|
$surveyService = new SurveyService();
|
|
//删除arr不要的数据
|
|
foreach ($data as $key=>$v){
|
|
if(strpos($key,'_arr')){
|
|
unset($data[$key]);
|
|
}
|
|
if ($key == "facility") {
|
|
unset($data['facility']['shop_facilities_elevator_arr']);
|
|
}
|
|
if (strpos($key, '_img_ids') && !strpos($key,'_arr')) {
|
|
is_array($v) && $surveyInfo[$key] = implode(',', $v);
|
|
}
|
|
}
|
|
$surveydata=$this->changeArrayToString($data);
|
|
if (!$surveyService->survey_detail($this->userInfo['user_id'], $surveydata,3)){
|
|
return $this->buildFailed('保存失败');
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
|
|
|
|
public function changeArrayToString($data){
|
|
foreach ($data as $k => $v) {
|
|
if(is_array($v)){
|
|
if(isset($v[0])){
|
|
$data[$k]=implode(',',$v);
|
|
}else{
|
|
$data[$k]=$this->changeArrayToString($v);
|
|
}
|
|
}
|
|
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 把返回的数据集转换成Tree
|
|
* @param $list
|
|
* @param string $pk
|
|
* @param string $pid
|
|
* @param string $child
|
|
* @param string $root
|
|
* @return array
|
|
*/
|
|
public static function listToTree($list, $pk = 'id', $pid = 'fid', $child = '_child', $root = '0') {
|
|
$tree = array();
|
|
if (is_array($list)) {
|
|
$refer = array();
|
|
foreach ($list as $key => $data) {
|
|
$refer[$data[$pk]] = &$list[$key];
|
|
}
|
|
foreach ($list as $key => $data) {
|
|
$parentId = $data[$pid];
|
|
if ($root == $parentId) {
|
|
$tree[$data['code']] = &$list[$key];
|
|
} else {
|
|
if (isset($refer[$parentId])) {
|
|
$parent = &$refer[$parentId];
|
|
if(!is_numeric($data['code'])){
|
|
$parent[$data['code']] = &$list[$key];
|
|
}else{
|
|
$parent[$child][] = &$list[$key];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $tree;
|
|
}
|
|
|
|
/**
|
|
*获取报告信息
|
|
*/
|
|
public function reqReportPropertyInfo() {
|
|
$id = $this->request->post('id');
|
|
if (empty($id)) return $this->buildFailed('参数不能为空!');
|
|
$res = Db::name('property_cert_info')->field('owner_name,property_cert,attachments')->where('id', $id)->find();
|
|
if ($res) {
|
|
$attachment = Db::name('attachment')->field('id,url,name,thum1,ext')->whereIn('id', $res['attachments'])->select();
|
|
foreach ($attachment as &$value) {
|
|
$value['url'] = config('uploadFile.url') . $value['url'];
|
|
}
|
|
$res['house_cert_img_ids'] = $attachment;
|
|
$res['obligee'] = $res['owner_name'];
|
|
unset($res['owner_name'],$res['attachments']);
|
|
}
|
|
return $this->buildSuccess($res);
|
|
}
|
|
|
|
/**
|
|
* 获取查看人员列表
|
|
*
|
|
*/
|
|
public function surveyPersonnel(){
|
|
$info = Db::name('project_team')->field('uid_str,username_str')->where('type', 4)->where("status",1)->find();
|
|
$data = array();
|
|
if(!empty($info)){
|
|
$uid_arr = explode(",",$info['uid_str']);
|
|
$username_arr = explode(",",$info['username_str']);
|
|
foreach($uid_arr as $k => $v){
|
|
$data[$k]['value'] = $v;
|
|
$data[$k]['name'] = $username_arr[$k];
|
|
}
|
|
}
|
|
return $this->buildSuccess($data);
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 获取城市 / 片区
|
|
* @return [type] [description]
|
|
*/
|
|
public function reqSurveyAreaList(){
|
|
$data = [
|
|
['value' => '110100' , 'label' => '北京' , 'children' => Region::BJ_area],
|
|
['value' => '440300' , 'label' => '深圳' , 'children' => Region::SZ_area],
|
|
['value' => '420100' , 'label' => '武汉' , 'children' => Region::WH_area],
|
|
['value' => '441900' , 'label' => '东莞' , 'children' => Region::DONGGUAN_area],
|
|
];
|
|
return $this->buildSuccess($data);
|
|
}
|
|
|
|
/**
|
|
* 复制查勘数据
|
|
*
|
|
*/
|
|
public function copySurveyData() {
|
|
$flag = true;
|
|
$survey_id = $this->request->param('id');
|
|
if (empty($survey_id)) {
|
|
return $this->buildFailed('查勘记录id不能为空');
|
|
}
|
|
$copy_survey_data = Db::name('survey')
|
|
->where(['id' => $survey_id])
|
|
->find();
|
|
|
|
$copy_survey_detail_data = Db::name('survey_detail')
|
|
->where(['survey_id' => $survey_id])
|
|
->find();
|
|
|
|
$copy_inquiry_detail_data = Db::name('property_cert_info')
|
|
->where(['id' => $copy_survey_data['property_cert_info_id']])
|
|
->find();
|
|
|
|
$reference_inquiry_detail_where[] = ['property_full_name', '=', $copy_inquiry_detail_data['property_full_name']];
|
|
$reference_inquiry_detail_where[] = ['create_time', '>=', '2023-07-20 00:00:00'];
|
|
$reference_inquiry_detail_where[] = ['id', '<>', $copy_survey_data['property_cert_info_id']];
|
|
$reference_inquiry_detail_data_arr = Db::name('property_cert_info')
|
|
->where($reference_inquiry_detail_where)
|
|
->order('create_time desc')
|
|
->select();
|
|
if ($reference_inquiry_detail_data_arr) {
|
|
$copyed_survey_data = [];
|
|
$copyed__inquiry_detail_data = [];
|
|
foreach ($reference_inquiry_detail_data_arr as $key => $value) {
|
|
$reference_survey_data = Db::name('survey')
|
|
->where(['property_cert_info_id' => $value['id']])
|
|
->find();
|
|
if ($reference_survey_data && $reference_survey_data['status'] == 3) {
|
|
$copyed__inquiry_detail_data = $value;
|
|
$copyed_survey_data = $reference_survey_data;
|
|
break;
|
|
}
|
|
}
|
|
if (!empty($copyed_survey_data)) {
|
|
Db::startTrans();
|
|
$copyed_survey_detail_data = Db::name('survey_detail')
|
|
->where(['survey_id'=>$copyed_survey_data['id']])
|
|
->find();
|
|
// 查勘详细数据复制
|
|
$copyed_survey_detail_data['id'] = $copy_survey_detail_data['id'];
|
|
$copyed_survey_detail_data['survey_id'] = $copy_survey_detail_data['survey_id'];
|
|
// $copyed_survey_detail_data['user_id'] = $copy_survey_detail_data['user_id'];
|
|
$copyed_survey_detail_data['building_completion_time'] = $copy_survey_detail_data['building_completion_time'];
|
|
$copyed_survey_detail_data['create_time'] = $copy_survey_detail_data['create_time'];
|
|
$copyed_survey_detail_data['update_time'] = $copy_survey_detail_data['update_time'];
|
|
$upd_survey_detail = Db::name('survey_detail')
|
|
->where(['id'=>$copy_survey_detail_data['id']])
|
|
->update($copyed_survey_detail_data);
|
|
// 更新查勘状态
|
|
$copy_survey_data['survey_type'] = $copyed_survey_data['survey_type'];
|
|
$copy_survey_data['area'] = $copyed_survey_data['area'];
|
|
$copy_survey_data['area_id'] = $copyed_survey_data['area_id'];
|
|
$copy_survey_data['complete_time'] = $copyed_survey_data['complete_time'];
|
|
$copy_survey_data['user_id'] = $copyed_survey_data['user_id'];
|
|
$copy_survey_data['user_name'] = $copyed_survey_data['user_name'];
|
|
$copy_survey_data['remark'] = $copyed_survey_data['remark'];
|
|
$copy_survey_data['status'] = $copyed_survey_data['status'];
|
|
$upd_survey = Db::name('survey')
|
|
->where(['id'=>$copy_survey_data['id']])
|
|
->update($copy_survey_data);
|
|
// 更新询价详细数据
|
|
$copy_inquiry_detail_data['survey_user_id'] = $copyed__inquiry_detail_data['survey_user_id'];
|
|
$copy_inquiry_detail_data['survey_user_name'] = $copyed__inquiry_detail_data['survey_user_name'];
|
|
$copy_inquiry_detail_data['survey_time'] = $copyed__inquiry_detail_data['survey_time'];
|
|
$copy_inquiry_detail_data['property_complex'] = $copyed__inquiry_detail_data['property_complex'];
|
|
$upd_inquiry_detail = Db::name('property_cert_info')
|
|
->where(['id'=>$copy_inquiry_detail_data['id']])
|
|
->update($copy_inquiry_detail_data);
|
|
// 更新询价状态(多套物业的还需要检查其它物业的查勘是否已完成)
|
|
$map[] = ['quot_id', '=', $copy_inquiry_detail_data['quot_id']];
|
|
$map[] = ['id', '<>', $copy_inquiry_detail_data['id']];
|
|
$inquiry_detail_data = Db::name('property_cert_info')
|
|
->where($map)
|
|
->field('id')
|
|
->select();
|
|
$upd_flag = true;
|
|
if (count($inquiry_detail_data) >= 1) {
|
|
foreach ($inquiry_detail_data as $k=>$v) {
|
|
$survey_data = Db::name('survey')
|
|
->where(['property_cert_info_id' => $v['id']])
|
|
->find();
|
|
if ($survey_data && $survey_data['status'] != 3) {
|
|
$upd_flag = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ($upd_flag) {
|
|
$upd_inquiry = Db::name('inquiry')
|
|
->where(['id'=>$copy_inquiry_detail_data['quot_id']])
|
|
->update(['status'=>5]);
|
|
} else {
|
|
$upd_inquiry = 1;
|
|
}
|
|
if ($upd_inquiry && $upd_inquiry_detail && $upd_survey && $upd_survey_detail) {
|
|
Db::commit();
|
|
} else {
|
|
$flag = false;
|
|
Db::rollback();
|
|
}
|
|
} else {
|
|
$flag = false;
|
|
}
|
|
} else {
|
|
$flag = false;
|
|
}
|
|
|
|
if ($flag) {
|
|
return $this->buildSuccess('', '复制查勘数据成功!');
|
|
} else {
|
|
return $this->buildFailed('没有可供复制的查勘数据!');
|
|
}
|
|
}
|
|
|
|
} |