155 lines
6.2 KiB
PHP
155 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\admin\service\InquiryService;
|
|
use app\model\Inquiry;
|
|
use app\model\Property_cert_info;
|
|
use app\model\Taxation;
|
|
use app\util\ReturnCode;
|
|
use app\common\validate\InquiryValidate;
|
|
use think\Db;
|
|
|
|
class AutomaticInquiry extends Base
|
|
{
|
|
|
|
/**
|
|
* @api {post} api/AutomaticInquiry/save 提交询价
|
|
*/
|
|
public function save(){
|
|
$data = $this->request->post();
|
|
$validate = new InquiryValidate();
|
|
if (!$validate->scene(InquiryValidate::Automatic_SCENE_CREATE)->batch()->check($data)) {
|
|
return $this->buildFailed('提交信息有误', $validate->getError());
|
|
}
|
|
|
|
$inquiryService = new InquiryService();
|
|
$verifyResult = $inquiryService->checkInquiryDetails($data['type'], $data['details']);
|
|
if ($verifyResult['is_success'] !== true) {
|
|
return $this->buildFailed('提交信息有误', $verifyResult['errors'], -2);
|
|
}
|
|
|
|
Db::startTrans();
|
|
try{
|
|
$inquiry = new Inquiry();
|
|
$inquiry->order_no = $this->generateInquiryNo($data['bank_code']);
|
|
$inquiry->user_id = $data['user_id'];
|
|
$inquiry->user_name = $data['user_name'];
|
|
$inquiry->bank_name = $data['bank_name'];
|
|
$inquiry->bank_id = $data['bank_id'];
|
|
if (isset($data['bank_branch_name']) && !empty($data['bank_branch_name']))
|
|
$inquiry->bank_branch_name = $data['bank_branch_name'];
|
|
if (isset($data['bank_branch_id']) && !empty($data['bank_branch_id']))
|
|
$inquiry->bank_branch_id = $data['bank_branch_id'];
|
|
if (isset($data['bank_sub_name']) && !empty($data['bank_sub_name']))
|
|
$inquiry->bank_sub_name = $data['bank_sub_name'];
|
|
if (isset($data['bank_sub_id']) && !empty($data['bank_sub_id']))
|
|
$inquiry->bank_sub_id = $data['bank_sub_id'];
|
|
$inquiry->eva_purpose = $data['eva_purpose'];
|
|
$inquiry->product_id = $data['product_id'];
|
|
$inquiry->type = $data['type'];
|
|
$inquiry->is_auto = 1;
|
|
$inquiry->is_auto_eva = ($data['status'] == 2) ? 1 : 0;
|
|
$inquiry->is_multiple = count($data['details']) > 1;
|
|
$inquiry->status = $data['status'];
|
|
$inquiry->create_time = date('Y-m-d H:i:s');
|
|
$inquiry->update_time = date('Y-m-d H:i:s');
|
|
if (!$inquiry->save())
|
|
return ['code'=>-1, 'msg'=>'inquiry表插入异常'];
|
|
|
|
foreach ($data['details'] as $detail) {
|
|
$property_cert_info = new Property_cert_info();
|
|
$property_cert_info->quot_id = $inquiry->id;
|
|
$property_cert_info->city = $detail['city'];
|
|
$property_cert_info->city_id = $detail['city_id'];
|
|
$property_cert_info->building_name = trim($detail['building_name']);;
|
|
$property_cert_info->building_no = trim($detail['building_no']);
|
|
$property_cert_info->unit_no = trim($detail['unit_no']);
|
|
$property_cert_info->building_unit_no = (empty($detail['building_no']) || trim($detail['building_no']) == '0') ? $detail['unit_no'] : $detail['building_no'] . $detail['unit_no'];
|
|
$property_cert_info->property_full_name = $property_cert_info->building_name . $property_cert_info->building_unit_no;
|
|
$property_cert_info->size = $detail['size'];
|
|
$property_cert_info->reg_price = $detail['reg_price'];
|
|
$property_cert_info->usage = $detail['usage'];
|
|
$property_cert_info->is_tran_tax_free = $detail['is_tran_tax_free'];
|
|
if (isset($detail['purchase_date']) && !empty($detail['purchase_date']))
|
|
$property_cert_info->purchase_date = $detail['purchase_date'];
|
|
if (isset($detail['ownership_type']))
|
|
$property_cert_info->ownership_type = $detail['ownership_type'];
|
|
if (isset($detail['remark']))
|
|
$property_cert_info->remark = $detail['remark'];
|
|
//todo 附件的处理
|
|
$property_cert_info->save();
|
|
}
|
|
|
|
if($inquiry->is_auto_eva == 0){
|
|
//写入消息
|
|
PublicMessage($inquiry->id,1,1);
|
|
}
|
|
|
|
//查询税费计算
|
|
$Taxation = new Taxation();
|
|
|
|
$map['bank_id'] = $data['bank_id'];
|
|
$map['product_name'] = $data['eva_purpose'];
|
|
$map['type'] = $data['type'];
|
|
$map['state'] = 1;
|
|
if(isset($data['bank_branch_id']) && !empty($data['bank_branch_id'])){
|
|
$map['branch_id'] = $data['bank_branch_id'];
|
|
}
|
|
$tax_items = $Taxation->where($map)->value("tax_items");
|
|
Db::commit();
|
|
return $this->buildSuccess(['id' => $inquiry->id, 'order_no'=>$inquiry->order_no, 'tax_items'=>$tax_items, 'property_cert_info_id' => $property_cert_info->id]);
|
|
}catch (\Exception $e){
|
|
Db::rollback();
|
|
return $this->buildFailed('操作失败', $e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 产生唯一订单号
|
|
*
|
|
* @param $type
|
|
* @return string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function generateInquiryNo($bank_code)
|
|
{
|
|
|
|
$inquiryNo = $bank_code.date('Ym');
|
|
$max = Db::name('inquiry')->order('id','desc')->find();
|
|
if (!$max){
|
|
$inquiryNo .= '000001';
|
|
}else{
|
|
$number = substr($max['order_no'],strlen($max['order_no'])-7, 7);
|
|
$number += 1;
|
|
$inquiryNo .= sprintf('%07d',$number);
|
|
}
|
|
|
|
return $inquiryNo;
|
|
}
|
|
|
|
|
|
/**
|
|
* @api {post} api/AutomaticInquiry/getProduct 获取产品名称
|
|
* @param string $bank 银行名称
|
|
*/
|
|
public function getProduct(){
|
|
$bank = $this->request->post('bank');
|
|
if(!$bank) return $this->buildFailed('银行名称不能为空', ReturnCode::EMPTY_PARAMS);
|
|
$where['bank'] = $bank;
|
|
$where['state'] = 1;
|
|
$where['type'] = 1;
|
|
$res = Db::name('product')->field('id,product_name')->where($where)->select();
|
|
return $this->buildSuccess($res);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |