Files
oms/back/application/api/controller/Supplier.php

158 lines
5.3 KiB
PHP
Raw Normal View History

2026-03-10 18:45:36 +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 Supplier extends Common
{
//获取资产类型列表
public function GetSupplierTypeList()
{
$FirstLeveType = db('supplier_type')->where('super_type_id', 0)->field('type_id as id, type_name as name')->select();
for ($i = 0; $i < count($FirstLeveType); $i++) {
$SecondLeveType = db('supplier_type')->where('super_type_id', $FirstLeveType[$i]['id'])->field('type_id as id, type_name as name')->select();
/*for ($m = 0; $m < count($SecondLeveType); $m++)
{
$count = db('supplier_info')->where('supplier_type', $SecondLeveType[$m]['type_id'])->count();
if ($count>0)
{
$SecondLeveType[$m]['type_name'] .= '【'.$count.'】';
}
}*/
for ($j = 0; $j < count($SecondLeveType); $j++) {
$ThridLeveType = db('supplier_info')->where('supplier_type', $SecondLeveType[$j]['id'])->field('supplier_id as id, supplier_name as name')->select();
/*for ($k = 0; $k < count($ThridLeveType); $k++)
{
$count = db('supplier_info')->where('supplier_type', $ThridLeveType[$k]['type_id'])->count();
if ($count>0)
{
$ThridLeveType[$k]['type_name'] .= '【'.$count.'】';
}
}*/
$SecondLeveType[$j]['sub_type'] = $ThridLeveType;
}
$FirstLeveType[$i]['sub_type'] = $SecondLeveType;
}
//dump($FirstLeveType);
return $this->sendSuccess($FirstLeveType);
}
//根据资产类型获取资产列表
public function GetSupplierInfo()
{
$param = request()->post();
$SupplierInfo = db('supplier_info')->where('supplier_id', $param['supplier_id'])->find();
$contacts = db('supplier_contacts')->where('customer_id', $param['supplier_id'])->select();
$SupplierInfo['contacts'] = $contacts;
return $this->sendSuccess($SupplierInfo);
}
//添加合同类型
public function AddSupplierType()
{
$param = request()->post();
$ret = [];
if ($param['type_id']>0)
{
//添加子类型
$ret = db('supplier_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('supplier_type')->insert($insert);
}
}
public function AddSupplierInfo()
{
$param = request()->post();
$ret = db('supplier_type')->where('type_id', $param['supplier_type'])->field('type_id,super_type_id')->find();
if ($ret != null)
{
$insert_info = [];
$insert_info['supplier_type'] = $param['supplier_type'];
$insert_info['supplier_name'] = $param['supplier_name'];
$insert_info['supplier_intro'] = $param['supplier_intro'];
$insert_info['create_time'] = $param['create_time'];
if($param['supplier_url'] == '')
{
$insert_info['supplier_url'] = '';
}
else
{
$insert_info['supplier_url'] = $param['supplier_url'];
}
db('supplier_info')->insert($insert_info);
}
}
public function UpdateSupplierInfo()
{
$param = request()->post();
if($param != null){
$update = [];
$update['supplier_name'] = $param['supplier_name'];
$update['contacts_name'] = $param['contacts_name'];
$update['contacts_phone'] = $param['contacts_phone'];
if($param['supplier_url'] != '')
{
$update['supplier_url'] = $param['supplier_url'];
}
$update['create_time'] = $param['create_time'];
$ret = db('supplier_info')->where('supplier_id',$param['supplier_id'])->update($update);
if($ret){
return $this->sendSuccess('修改成功');
}else{
return $this->sendError('修改失败');
}
}
}
public function AddContractsInfo()
{
$param = request()->post();
if($param != null)
{
$param['create_time'] = date('Y-m-d H:i:s');
db('supplier_contacts')->insert($param);
return $this->sendSuccess('添加成功');
}
}
}