Files
oms-back/application/api/controller_74GYL3/Contract.php

282 lines
10 KiB
PHP
Raw Normal View History

2026-03-09 22:55:58 +08:00
<?php
namespace app\api\controller;
use think\Config;
use think\Controller;
use think\Db;
use think\Log;
use think\Model;
use think\Request;
use think\cache\driver\Memcache;
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
class Contract extends Common
{
//获取运营合同类型列表
public function GetOperationContractTypeList()
{
$FirstLeveType = db('contract_type')->where('super_type_id', 0)->where('type_id', '>', 10)->select();
for ($i = 0; $i < count($FirstLeveType); $i++) {
$SecondLeveType = db('contract_type')->where('super_type_id', $FirstLeveType[$i]['type_id'])->select();
for ($m = 0; $m < count($SecondLeveType); $m++)
{
$count = db('contract_info')->where('contract_type', $SecondLeveType[$m]['type_id'])->count();
if ($count>0)
{
$SecondLeveType[$m]['type_name'] .= '【'.$count.'】';
}
}
for ($j = 0; $j < count($SecondLeveType); $j++) {
$ThridLeveType = db('contract_type')->where('super_type_id', $SecondLeveType[$j]['type_id'])->select();
for ($k = 0; $k < count($ThridLeveType); $k++)
{
$count = db('contract_info')->where('contract_type', $ThridLeveType[$k]['type_id'])->count();
if ($count>0)
{
$ThridLeveType[$k]['type_name'] .= '【'.$count.'】';
}
}
$SecondLeveType[$j]['sub_type'] = $ThridLeveType;
}
$FirstLeveType[$i]['sub_type'] = $SecondLeveType;
}
return $this->sendSuccess($FirstLeveType);
}
//根据合同类型获取合同列表
public function GetOperationContractList()
{
$param = request()->post();
$ContractInfoList = db('contract_info')->where('contract_type', $param['contract_type'])
->where('del_time',null)
->select();
return $this->sendSuccess($ContractInfoList);
}
public function GetCustomerProjectList()
{
$param = request()->post();
$FirstLeveType = db('partner_company')->where('company_type & 0x01', 1)->field('company_id as id, company_name as name')->select();
for ($i = 0; $i < count($FirstLeveType); $i++)
{
//dump($FirstLeveType[$i]['type_id']);
$SecondLeveType = db('project_info')->where('customer_id', $FirstLeveType[$i]['id'])->field('project_id as id, project_name as name')->select();
//dump($SecondLeveType);
for ($j = 0; $j < count($SecondLeveType); $j++)
{
$count = db('contract_info')->where('project_id', $SecondLeveType[$j]['id'])->count();
$SecondLeveType[$j]['name'] .= '【'.$count.'】';
}
$FirstLeveType[$i]['customer_projects'] = $SecondLeveType;
}
return $this->sendSuccess($FirstLeveType);
}
public function GetProjectContractList()
{
$param = request()->post();
$ContractInfoList = [];
if (isset($param['contract_category']))
{
//采购合同/技术协议
if (3 == $param['contract_category'] || 4 == $param['contract_category'])
{
$ContractInfoList = db('contract_info')->where('project_id', $param['project_id'])
->where('contract_type', $param['contract_type'])
->where('partner_id', $param['partner_id'])
->where('contract_category', $param['contract_category'])
->select();
}
//销售合同/技术协议
if (1 == $param['contract_category'] || 2 == $param['contract_category'])
{
$ContractInfoList = db('contract_info')->where('project_id', $param['project_id'])
->where('contract_type', 1)
->where('contract_category', $param['contract_category'])
->select();
}
if (5 == $param['contract_category']){
$ContractInfoList = db('contract_info')->where('project_id', $param['project_id'])
->where('contract_type', 1)
->where('contract_category', $param['contract_category'])
->select();
}
}
else
{
$ContractInfoList = db('contract_info')->where('project_id', $param['project_id'])
->where('contract_type', 1)
->where('contract_category', 'in', [1, 3])
->select();
}
return $this->sendSuccess($ContractInfoList);
}
//添加合同类型
public function AddContractType()
{
$param = request()->post();
$ret = [];
if ($param['type_id']>0)
{
//添加子类型
$ret = db('contract_type')->where('type_id', $param['type_id'])->field('type_id,super_type_id')->find();
}
else
{
//添加基类型
$ret['type_id'] = 0;
}
if ($ret != null) {
$insert = [];
$insert['type_name'] = $param['type_name'];
$insert['super_type_id'] = $ret['type_id'];
$insert['create_time'] = date('Y-m-d H:i:s');
db('contract_type')->insert($insert);
}
}
public function AddContractInfo()
{
$param = request()->post();
$insert_info = [];
$insert_info['contract_number'] = $param['contract_number'];
$insert_info['contract_name'] = $param['contract_name'];
$insert_info['create_time'] = $param['create_time'];
$insert_info['contract_price'] = $param['contract_price'];
//$insert_info['contract_des'] = $param['contract_des'];
if(isset($param['partner_id'])){
$insert_info['partner_id'] = $param['partner_id'];
}
if (isset($param['project_id']))
{
$insert_info['project_id'] = $param['project_id']; //合同所属项目ID
$insert_info['contract_type'] = $param['contract_type']; //合同类型 1 商务合同2 技术协议
}
if (isset($param['contract_type']))
{
$insert_info['contract_type'] = $param['contract_type']; //合同所属项目ID
}
if (isset($param['contract_category']))
{
$insert_info['contract_category']= $param['contract_category'];
}
if($param['contract_url'] == ''){
$insert_info['contract_url'] = '';
}else{
$insert_info['contract_url'] = $param['contract_url'];
}
db('contract_info')->insert($insert_info);
return $this->sendSuccess('添加成功');
}
public function AddProjectContract()
{
$param = request()->post();
$insert_info = [];
$insert_info['contract_number'] = $param['contract_number'];
$insert_info['contract_name'] = $param['contract_name'];
$insert_info['create_time'] = $param['create_time'];
$insert_info['contract_price'] = $param['contract_price'];
if(isset($param['partner_id'])){
$insert_info['partner_id'] = $param['partner_id'];
}
if (isset($param['project_id']))
{
$insert_info['project_id'] = $param['project_id']; //合同所属项目ID
$insert_info['contract_type'] = $param['contract_type']; //合同类型 1 商务合同2 技术协议
}
$insert_info['contract_type'] = 1; //客户项目合同类
if (isset($param['contract_category']))
{
$insert_info['contract_category']= $param['contract_category'];
}
if($param['contract_url'] == ''){
$insert_info['contract_url'] = '';
}else{
$insert_info['contract_url'] = $param['contract_url'];
}
db('contract_info')->insert($insert_info);
return $this->sendSuccess('添加成功');
}
public function updateContractInfo()
{
$param = request()->post();
if($param != null){
$update = [];
$update['contract_name'] = $param['contract_name'];
$update['contract_category'] = $param['contract_category'];
$update['contract_number'] = $param['contract_number'];
//$update['contract_des'] = $param['contract_des'];
if($param['contract_url'] != '')
{
$update['contract_url'] = $param['contract_url'];
}
$update['contract_price'] = $param['contract_price'];
$update['create_time'] = $param['create_time'];
$ret = db('contract_info')->where('contract_id',$param['contract_id'])->update($update);
if($ret){
return $this->sendSuccess('修改成功');
}else{
return $this->sendError('修改失败');
}
}
}
public function delContractInfo()
{
$param = request()->post();
// dump($param);
$update = [];
$update['del_time'] = date('Y-m-d H:i:s');
$ret = db('contract_info')->where('contract_id',$param['contract_id'])->update($update);
if($ret){
return $this->sendSuccess('删除成功');
}else{
return $this->sendError('删除失败');
}
}
}