Files
oms/back/application/api/controller/Customer.php
2026-03-10 18:45:36 +08:00

132 lines
4.3 KiB
PHP

<?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 Customer extends Common
{
//获取资产类型列表
public function GetCustomerList()
{
$param = request()->post();
$FirstLeveType = db('customer_info')->where('customer_type', $param['customer_type'])->field('customer_id as id, customer_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();
/*for ($j = 0; $j < count($SecondLeveType); $j++)
{
$count = db('project_info')->where('project_type', $SecondLeveType[$j]['type_id'])->count();
if ($count>0)
{
$SecondLeveType[$j]['type_name'] .= '【'.$count.'】';
}
}*/
//dump($SecondLeveType);
$FirstLeveType[$i]['customer_projects'] = $SecondLeveType;
}
//dump($FirstLeveType);
return $this->sendSuccess($FirstLeveType);
}
//根据资产类型获取资产列表
public function GetProjectInfoList()
{
$param = request()->post();
$ProjectInfoList = db('project_info')->alias('i')
->where('i.project_type', $param['type'])
->select();
return $this->sendSuccess($ProjectInfoList);
}
//添加合同类型
public function AddCustomerInfo()
{
$param = request()->post();
$insert = [];
$insert['customer_name'] = $param['customer_name'];
$insert['customer_type'] = $param['customer_type'];
$insert['create_time'] = date('Y-m-d H:i:s');
db('customer_info')->insert($insert);
}
public function updateProjectInfo()
{
$param = request()->post();
if($param != null){
$update = [];
$update['project_name'] = $param['project_name'];
$update['project_category'] = $param['project_category'];
$update['project_number'] = $param['project_number'];
if($param['project_url'] != '')
{
$update['project_url'] = $param['project_url'];
}
$update['project_price'] = $param['project_price'];
$update['create_time'] = $param['create_time'];
$ret = db('project_info')->where('project_id',$param['project_id'])->update($update);
if($ret){
return $this->sendSuccess('修改成功');
}else{
return $this->sendError('修改失败');
}
}
}
public function AddCustomerMemberInfo()
{
$param = request()->post();
if($param != null){
$param['create_time'] = date('Y-m-d H:i:s');
db('customer_contacts')->insert($param);
return $this->sendSuccess('添加成功');
}
}
public function GetCustomerMemberList()
{
$param = request()->post();
$MemberList = db('customer_contacts')->where('customer_id', $param['customer_id'])
->select();
return $this->sendSuccess($MemberList);
}
public function GetCustomerInfo()
{
$param = request()->post();
$ret = db('customer_info')->where('customer_id', $param['customer_id'])->find();
if ($ret != null)
{
$MemberList = db('customer_contacts')->where('customer_id', $param['customer_id'])
->select();
$ret['customer_member'] = $MemberList;
}
return $this->sendSuccess($ret);
}
}