Files
annnj-company 130c1026c4 first commit
2026-04-17 18:29:53 +08:00

150 lines
4.9 KiB
PHP

<?php
namespace app\admin\controller;
use app\model\Estimate;
use think\Db;
class EstimateSetUp extends Base
{
public $type = ["1"=>"住宅","2"=>"商业"];
/**
* 预估单设置列表
* @author cavan
*/
public function EstimateList()
{
$bank_id = $this->request->post('bank_id', '','trim'); //银行
$page = $this->request->post('page', '','trim'); //页码
$size = $this->request->post('limit', '','trim'); //单页数量
$where = array();
if(!empty($bank_id)){
$where[]=['bank_id','=',$bank_id];
}
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
);
$Estimate = new Estimate();
$resultData=$Estimate->where($where)
->order(json_decode($order,true))
->field('id,bank,product_name,type,create_time,update_time')
->paginate($size,false,$config);
if(!empty($resultData)){
foreach ($resultData as $k => $v){
$resultData[$k]['type_name'] = $this->type[$v['type']];
$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 EstimateDetails(){
$id = $this->request->post('id', '', 'trim');
if(!$id){
return $this->buildFailed("缺少参数id");
}
$Estimate = new Estimate();
//主表信息
$list = $Estimate->where("id",$id)
->field("id,bank,bank_id,product_name,product_id,type,estimate_sheet,estimated_desc")
->find();
if(!empty($list)){
$list['type_name'] = $this->type[$list['type']];
}
return $this->buildSuccess($list);
}
/**
* 新增预估单设置
* @author cavan
*
* @parameter bank_id 银行id
* @parameter product_id 产品名称
* @parameter type 收费对象
* @parameter estimate_sheet 收费方式
* @parameter estimated_desc 报告模板id
*/
public function save(){
$id = $this->request->post('id', '', 'trim');
$bank_id = $this->request->post('bank_id', '', 'trim');
$product_id = $this->request->post('product_id', '', 'trim');
$type = $this->request->post('type', '', 'trim');
$estimate_sheet = $this->request->post('estimate_sheet', '', 'trim');
$estimated_desc = $this->request->post('estimated_desc', '', 'trim');
if (!$bank_id) {
return $this->buildFailed("银行为必选项");
}
if (!$product_id) {
return $this->buildFailed("产品为必选项");
}
if (!$type) {
return $this->buildFailed("业务类型为必选项");
}
if (!$estimate_sheet) {
return $this->buildFailed("预估单模板不能为空");
}
if (!$estimated_desc) {
return $this->buildFailed("说明不能为空");
}
$Estimate = new Estimate();
if (!$id){
$return = $Estimate->where(['bank_id' => $bank_id, 'product_id' => $product_id, 'type' => $type])->value("id");
if ($return) {
return $this->buildFailed("该银行下此业务类型预估单模板已存在");
}
}else{
$return = $Estimate->where("id","<>",$id)->where(['bank_id' => $bank_id, 'product_id' => $product_id, 'type' => $type])->value("id");
if ($return) {
return $this->buildFailed("该银行下此业务类型预估单模板已存在");
}
}
$bank = Db::name("bank")->where("id",$bank_id)->value("name");
$product_name = Db::name("product")->where("id",$product_id)->value("product_name");
$insert_data['bank'] = $bank;
$insert_data['bank_id'] = $bank_id;
$insert_data['product_id'] = $product_id;
$insert_data['product_name'] = $product_name;
$insert_data['type'] = $type;
$insert_data['estimate_sheet'] = $estimate_sheet;
$insert_data['estimated_desc'] = $estimated_desc;
if($id){
$insert_data['update_time'] = time();
$Estimate->where("id",$id)->update($insert_data);
}else{
$insert_data['create_time'] = time();
$Estimate->insertGetId($insert_data);
}
return $this->buildSuccess([],"保存成功");
}
}