first commit

This commit is contained in:
annnj-company
2026-04-17 18:29:53 +08:00
parent e49fa5a215
commit 130c1026c4
5615 changed files with 1639145 additions and 0 deletions

View File

@@ -0,0 +1,406 @@
<?php
namespace app\admin\controller;
use app\model\Product;
use app\model\ProductItem;
use app\model\Attachment;
use app\model\ReportTemplate;
use think\Db;
class ProductSetUp extends Base
{
public $charging_object = ["0"=>"","1"=>"个人","2"=>"银行"];
public $charging_method = ["1"=>"评估总值区间","2"=>"评估总值物业区间","3"=>"物业类型","4"=>"单笔","5"=>"单套评估总值"];
/**
* 产品设置列表
* @author cavan
*/
public function ProductList()
{
$bank_id = $this->request->post('bank_id', '','trim'); //银行
$type = $this->request->post('type', '','trim'); //业务类型
$keyword = $this->request->post('keyword', '','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($type)){
$where[]=['type','=',$type];
}
if(!empty($keyword)){
$where[]=['product_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
);
$Product = new Product();
$Attachment = new Attachment();
$ReportTemplate = new ReportTemplate();
$resultData=$Product->where($where)
->order(json_decode($order,true))
->field('id,bank,product_name,type,charging_object,charging_method,report_template,report_cost,state,create_time,update_time,many_report_template')
->paginate($size,false,$config);
if(!empty($resultData)){
foreach ($resultData as $k => $v){
$resultData[$k]['type_name'] = ($v['type']==1)?"住宅":(($v['type']==2)?"商业":"");
$resultData[$k]['charging_object_name'] = $this->charging_object[$v['charging_object']];
$resultData[$k]['charging_method_name'] = $this->charging_method[$v['charging_method']];
$resultData[$k]['state_name'] = $v['state']==1?"有效":"无效";
$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']);
$resultData[$k]['report_template_name'] = $ReportTemplate->where("id",$v['report_template'])->value("name");
$resultData[$k]['many_report_template_name'] = $ReportTemplate->where("id",$v['many_report_template'])->value("name");
}
}
return $this->buildSuccess($resultData);
}
/**
* 产品设置详情--修改调用接口
* @author cavan
*
*/
public function ProductDetails(){
$id = $this->request->post('id', '', 'trim');
if(!$id){
return $this->buildFailed("缺少参数id");
}
$Product = new Product();
$ProductItem = new ProductItem();
$Attachment = new Attachment();
$ReportTemplate = new ReportTemplate();
//主表信息
$list = $Product->where("id",$id)
->field("id,bank,bank_id,product_name,charging_object,charging_method,report_template,report_cost,type,many_report_template")
->find();
if(!empty($list)){
if($list['charging_method'] == 2){
$list['json_data'] = $ProductItem->where("product_id",$id)->where("type",1)->field("id,product_id,type,tvoa_rise,tvoa_stop,money,ratio,minimum_standard_amount,minimum_standard_ratio,extra_charge")->select();
$list['business_json_data'] = $ProductItem->where("product_id",$id)->where("type",2)->field("id,product_id,type,tvoa_rise,tvoa_stop,money,ratio,minimum_standard_amount,minimum_standard_ratio,extra_charge")->select();
}else{
$list['json_data'] = $ProductItem->where("product_id",$id)->field("id,product_id,type,tvoa_rise,tvoa_stop,money,ratio,minimum_standard_amount,minimum_standard_ratio,extra_charge")->select();
}
if(!empty($list['json_data'])){
foreach ($list['json_data'] as $kj => $vj){
$list['json_data'][$kj]['money'] = is_null($vj['money'])?"":$vj['money'];
$list['json_data'][$kj]['ratio'] = is_null($vj['ratio'])?"":$vj['ratio'];
$list['json_data'][$kj]['minimum_standard_amount'] = is_null($vj['minimum_standard_amount'])?"":$vj['minimum_standard_amount'];
$list['json_data'][$kj]['minimum_standard_ratio'] = is_null($vj['minimum_standard_ratio'])?"":$vj['minimum_standard_ratio'];
}
}
if(!empty($list['business_json_data'])){
foreach ($list['business_json_data'] as $kb => $vb){
$list['json_data'][$kb]['money'] = is_null($vb['money'])?"":$vb['money'];
$list['json_data'][$kb]['ratio'] = is_null($vb['ratio'])?"":$vb['ratio'];
$list['json_data'][$kb]['minimum_standard_amount'] = is_null($vb['minimum_standard_amount'])?"":$vb['minimum_standard_amount'];
$list['json_data'][$kb]['minimum_standard_ratio'] = is_null($vb['minimum_standard_ratio'])?"":$vb['minimum_standard_ratio'];
}
}
$list['report_template_name'] = $ReportTemplate->where("id",$list['report_template'])->value("name");
$list['type_name'] = ($list['type'] == 1)?"住宅":(($list['type'] == 2)?"商业":"");
$list['many_report_template_name'] = $ReportTemplate->where("id",$list['many_report_template'])->value("name");
}
return $this->buildSuccess($list);
}
/**
* 产品设置状态修改
* @author cavan
*
* @parameter id 数据id
* @parameter state 当前状态
*/
public function ProductModify(){
$id = $this->request->post('id', '', 'trim'); //数据id
$state = $this->request->post('state', '','trim'); //当前状态
if(!$id){
return $this->buildFailed("缺少参数id");
}
if(!$state){
return $this->buildFailed("缺少参数状态值");
}
$Product = new Product(); //
if($state != 1){ //2020年4月22日09:02:40
$rt = $Product->where("id",$id)->field("bank_id,product_name,type")->find();
$old_id = $Product->where("id","<>",$id)->where(["bank_id"=>$rt['bank_id'],"product_name"=>$rt['product_name'],"type"=>$rt['type'],"state"=>1])->value("id");
if($old_id){
return $this->buildFailed("已经存在该银行同一产品信息");
}
}
$update_data = array();
if($state == 1){
$update_data['state'] = 2;
$msg = "禁用成功";
$errormsg = "禁用失败";
}else{
$update_data['state'] = 1;
$msg = "启用成功";
$errormsg = "启用失败";
}
$do = $Product->where("id",$id)->update($update_data);
if($do > 0){
return $this->buildSuccess("",$msg);
}else{
return $this->buildFailed($errormsg);
}
}
/**
* 新增计税银行税费设置
* @author cavan
*
* @parameter bank_id 银行id
* @parameter product_name 产品名称
* @parameter type 业务类型
* @parameter charging_object 收费对象
* @parameter charging_method 收费方式
* @parameter report_template 报告模板id
* @parameter report_cost 报告工本费
* @parameter json_data 收费规则 (charging_method 为2时代表住宅收费规则)
* @parameter business_json_data 收费规则 (charging_method 为2时代表商业收费规则)
*/
public function save()
{
$id = $this->request->post('id', '', 'trim');
$bank_id = $this->request->post('bank_id', '', 'trim');
$product_name = $this->request->post('product_name', '', 'trim');
$type = $this->request->post('type', '', 'trim');
$charging_object = $this->request->post('charging_object', '', 'trim');
$charging_method = $this->request->post('charging_method', '', 'trim');
$report_template = $this->request->post('report_template', '', 'trim');
$many_report_template = $this->request->post('many_report_template', '', 'trim');
$report_cost = $this->request->post('report_cost', '', 'trim');
$json_data = $this->request->post('json_data', '', 'trim');
$business_json_data = $this->request->post('business_json_data', '', 'trim');
if (!$bank_id) {
return $this->buildFailed("缺少银行信息");
}
if (!$product_name) {
return $this->buildFailed("缺少产品名称");
}
if (!$type) {
return $this->buildFailed("业务类型为必选项");
}
if ($charging_object && $charging_object === "") {
return $this->buildFailed("缺少收费对象");
}
if (!$charging_method) {
return $this->buildFailed("缺少收费方式");
}
if (!$report_template) {
return $this->buildFailed("请选择单套报告模板");
}
if (!$many_report_template) {
return $this->buildFailed("请选择多套报告模板");
}
if (!$report_cost) {
return $this->buildFailed("缺少报告工本费");
}
if (empty($json_data)) {
return $this->buildFailed("缺少收费规则信息");
}
if($charging_method == 2){
if (empty($business_json_data)) {
return $this->buildFailed("缺少收费规则信息");
}
}
// $json_data = json_decode($json_data,true);
$Product = new Product();
$ProductItem = new ProductItem();
if($charging_method == 2){
$json_data = array_merge($json_data,$business_json_data);
}
if (!$id){
$return = $Product->where("id","<>",$id)->where(['bank_id' => $bank_id, 'product_name' => $product_name, 'type' => $type, 'state' => 1])->value("id");
if ($return) {
return $this->buildFailed("该银行已存在有效状态的产品设置");
}
}
if(!empty($json_data)){
foreach ($json_data as $k => $v){
if($charging_method == 3){
if(!array_key_exists("type",$v)){
return $this->buildFailed("类型不能为空");
}else if(!array_key_exists("money",$v)){
return $this->buildFailed("金额不能为空");
}
}else if($charging_method == 4){
if(!array_key_exists("money",$v)){
return $this->buildFailed("金额不能为空");
}else if(!array_key_exists("extra_charge",$v)){
return $this->buildFailed("增加一套加收费不能为空");
}
}else{
if(!array_key_exists("tvoa_rise",$v) && !array_key_exists("tvoa_stop",$v)){
return $this->buildFailed("评估总值-起止必须存在一个值");
}else if(!array_key_exists("money",$v) && !array_key_exists("ratio",$v)){
return $this->buildFailed("金额和比率必须存在一个值");
}
$tvoa_rise = $v['tvoa_rise'];
$tvoa_stop = $v['tvoa_stop'];
$money = $v['money'];
$ratio = $v['ratio'];
if($tvoa_rise <= 0 && $tvoa_stop <= 0){
return $this->buildFailed("评估总值-起止必须存在一个值为有效数值");
}
if($money === "" && $ratio === ""){
return $this->buildFailed("金额和比率必须存在一个值为有效数值");
}
}
}
}
$bank = Db::name("bank")->where("id",$bank_id)->value("name");
$insert_data['bank'] = $bank;
$insert_data['bank_id'] = $bank_id;
$insert_data['product_name'] = $product_name;
$insert_data['type'] = $type;
$insert_data['charging_object'] = $charging_object;
$insert_data['charging_method'] = $charging_method;
$insert_data['report_template'] = $report_template;
$insert_data['many_report_template'] = $many_report_template;
$insert_data['report_cost'] = $report_cost;
$insert_data['state'] = 1;
Db::startTrans();
try {
if($id){
$old_id = $Product->where("id","<>",$id)->where(["bank_id"=>$bank_id,"product_name"=>$product_name,"type"=>$type,"state"=>1])->value("id");
if($old_id){
return $this->buildFailed("该银行已存在有效状态的产品设置");
}
$insert_data['update_time'] = time();
$Product->where("id",$id)->update($insert_data);
$ids = $ProductItem->where("product_id",$id)->column("id");
if(!empty($json_data)) {
foreach ($json_data as $k => $v) {
$item_data = array();
if ($charging_method == 2) { //评估总值物业区间
$item_data['type'] = !empty($v['type']) ? $v['type'] : "";
$item_data['tvoa_rise'] = (!$v['tvoa_rise'] && $v['tvoa_rise'] === "") ? null : $v['tvoa_rise'];
$item_data['tvoa_stop'] = (!$v['tvoa_stop'] && $v['tvoa_stop'] === "") ? null : $v['tvoa_stop'];
$item_data['money'] = (!$v['money'] && $v['money'] === "") ? null : $v['money'];
$item_data['ratio'] = (!$v['ratio'] && $v['ratio'] === "") ? null : $v['ratio'];
$item_data['minimum_standard_amount'] = (!$v['minimum_standard_amount'] && $v['minimum_standard_amount'] === "") ? null : $v['minimum_standard_amount'];
$item_data['minimum_standard_ratio'] = (!$v['minimum_standard_ratio'] && $v['minimum_standard_ratio'] === "") ? null : $v['minimum_standard_ratio'];
} elseif ($charging_method == 3) { //物业类型
$item_data['money'] = (!$v['money'] && $v['money'] === "") ? null : $v['money'];
$item_data['type'] = !empty($v['type']) ? $v['type'] : "";
} else if ($charging_method == 4) { //单笔
$item_data['extra_charge'] = (!$v['extra_charge'] && $v['extra_charge'] === "")?null:$v['extra_charge'];
$item_data['money'] = (!$v['money'] && $v['money'] === "") ? null : $v['money'];
} else { //评估总值区间、单套评估总值
$item_data['tvoa_rise'] = (!$v['tvoa_rise'] && $v['tvoa_rise'] === "") ? null : $v['tvoa_rise'];
$item_data['tvoa_stop'] = (!$v['tvoa_stop'] && $v['tvoa_stop'] === "") ? null : $v['tvoa_stop'];
$item_data['money'] = (!$v['money'] && $v['money'] === "") ? null : $v['money'];
$item_data['ratio'] = (!$v['ratio'] && $v['ratio'] === "") ? null : $v['ratio'];
$item_data['minimum_standard_amount'] = (!$v['minimum_standard_amount'] && $v['minimum_standard_amount'] === "") ? null : $v['minimum_standard_amount'];
$item_data['minimum_standard_ratio'] = (!$v['minimum_standard_ratio'] && $v['minimum_standard_ratio'] === "") ? null : $v['minimum_standard_ratio'];
}
$item_data['create_time'] = time();
if (!empty($v['id'])) {
if (in_array($v['id'], $ids)) {
foreach ($ids as $ks => $vs) {
if ($v['id'] == $vs) unset($ids[$ks]);
}
$ids = array_merge($ids);
}
$ProductItem->where("id", $v['id'])->update($item_data);
} else {
$item_data['product_id'] = $id;
$ProductItem->insert($item_data);
}
}
if (!empty($ids)) {
$idstr = implode(",", $ids);
$ProductItem->where("id", "in", $idstr)->delete();
}
}
$msg = "编辑成功";
// 提交事务
Db::commit();
}else{
$insert_data['create_time'] = time();
$id = $Product->insertGetId($insert_data);
if($id > 0){
if(!empty($json_data)){
$item_data = array();
foreach ($json_data as $k =>$v){
$item_data[$k]['product_id'] = $id;
if($charging_method == 2){ //评估总值物业区间
$item_data[$k]['type'] = !empty($v['type'])?$v['type']:"";
$item_data[$k]['tvoa_rise'] = (!$v['tvoa_rise'] && $v['tvoa_rise'] === "")?null:$v['tvoa_rise'];
$item_data[$k]['tvoa_stop'] = (!$v['tvoa_stop'] && $v['tvoa_stop'] === "")?null:$v['tvoa_stop'];
$item_data[$k]['money'] = (!$v['money'] && $v['money'] === "")?null:$v['money'];
$item_data[$k]['ratio'] = (!$v['ratio'] && $v['ratio'] === "")?null:$v['ratio'];
$item_data[$k]['minimum_standard_amount'] = (!$v['minimum_standard_amount'] && $v['minimum_standard_amount'] === "")?null:$v['minimum_standard_amount'];
$item_data[$k]['minimum_standard_ratio'] = (!$v['minimum_standard_ratio'] && $v['minimum_standard_ratio'] === "")?null:$v['minimum_standard_ratio'];
}elseif($charging_method == 3){ //物业类型
$item_data[$k]['money'] = (!$v['money'] && $v['money'] === "")?null:$v['money'];
$item_data[$k]['type'] = !empty($v['type'])?$v['type']:"";
}else if($charging_method == 4){ //单笔
$item_data[$k]['extra_charge'] = (!$v['extra_charge'] && $v['extra_charge'] === "")?null:$v['extra_charge'];
$item_data[$k]['money'] = (!$v['money'] && $v['money'] === "")?null:$v['money'];
}else{ //评估总值区间、单套评估总值
$item_data[$k]['tvoa_rise'] = (!$v['tvoa_rise'] && $v['tvoa_rise'] === "")?null:$v['tvoa_rise'];
$item_data[$k]['tvoa_stop'] = (!$v['tvoa_stop'] && $v['tvoa_stop'] === "")?null:$v['tvoa_stop'];
$item_data[$k]['money'] = (!$v['money'] && $v['money'] === "")?null:$v['money'];
$item_data[$k]['ratio'] = (!$v['ratio'] && $v['ratio'] === "")?null:$v['ratio'];
$item_data[$k]['minimum_standard_amount'] = (!$v['minimum_standard_amount'] && $v['minimum_standard_amount'] === "")?null:$v['minimum_standard_amount'];
$item_data[$k]['minimum_standard_ratio'] = (!$v['minimum_standard_ratio'] && $v['minimum_standard_ratio'] === "")?null:$v['minimum_standard_ratio'];
}
$item_data[$k]['create_time'] = time();
}
$ProductItem->insertAll($item_data);
}
}
$msg = "保存成功";
// 提交事务
Db::commit();
}
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $e->getMessage();
}
return $this->buildSuccess([],$msg);
}
/**
* 报告模板列表
*
*/
public function ReportTemplateList(){
$ReportTemplate = new ReportTemplate();
$list = $ReportTemplate->where("status",1)->where("type",1)->field("id as value,name")->select();
return $this->buildSuccess($list);
}
}