80 lines
3.2 KiB
PHP
80 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\model\contract\Contract;
|
|
use app\common\model\platform\Platform;
|
|
use app\common\model\vehicle\Vehicle;
|
|
|
|
class ContractController extends BaseApiController
|
|
{
|
|
public array $notNeedLogin = ['signContract','updateContract'];
|
|
public function signContract() {
|
|
//获取参数
|
|
$params = $this->request->post(['num','company_id','company_name','company_code','company_user','company_phone','company_email']);
|
|
//验证参数
|
|
if(empty($params['num']) || empty($params['company_id']) || empty($params['company_name']) || empty($params['company_code']) || empty($params['company_user']) || empty($params['company_phone']) || empty($params['company_email'])){
|
|
return $this->fail('缺少必要参数');
|
|
}
|
|
//获取平台公司数据
|
|
$platform = Platform::find(1);
|
|
if(!$platform || $platform->isEmpty()){
|
|
return $this->fail('甲方公司不存在');
|
|
}
|
|
//获取车辆数据
|
|
$cars = Vehicle::field('id,license')->where([
|
|
['type','=',1],
|
|
['status','=',1],
|
|
['is_check','=',2],
|
|
['is_del','=',1],
|
|
])->limit($params['num'])->select();
|
|
if($cars->isEmpty() || $cars->count() < $params['num']){
|
|
return $this->fail('车辆数量不足');
|
|
}
|
|
//设置数据
|
|
$data = [
|
|
'contract_no' => time(),
|
|
'company_a_name' => $platform['company_name'],
|
|
'company_a_code' => $platform['company_organization_code'],
|
|
'company_a_user' => $platform['company_user'],
|
|
'company_a_phone' => $platform['company_phone'],
|
|
'company_a_email' => $platform['company_email'],
|
|
'company_b_id' => $params['company_id'],
|
|
'company_b_name' => $params['company_name'],
|
|
'company_b_code' => $params['company_code'],
|
|
'company_b_user' => $params['company_user'],
|
|
'company_b_phone' => $params['company_phone'],
|
|
'company_b_email' => $params['company_email'],
|
|
'num' => $params['num'],
|
|
'cars_info' => $cars->toJson(),
|
|
'status' => 0,
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
];
|
|
//写入数据
|
|
$result = Contract::create($data);
|
|
//更改车辆状态
|
|
$carStatus = Vehicle::where('id','in',array_column($cars->toArray(),'id'))->update(['status'=>2,'update_time'=>time()]);
|
|
//返回
|
|
if($result->id && $carStatus) {
|
|
$data['contract_logistic_id'] = $result->id;
|
|
$data['type'] = 0;
|
|
return $this->success('合同发起成功,等待审核',$data);
|
|
}else{
|
|
return $this->fail('请求失败');
|
|
}
|
|
}
|
|
|
|
public function updateContract() {
|
|
//获取参数
|
|
$params = $this->request->post();
|
|
if(empty($params['id'])){
|
|
return $this->fail('缺少必要参数');
|
|
}
|
|
//更新数据
|
|
$model = Contract::where('id',$params['id'])->find();
|
|
$result = $model->save($params);
|
|
//返回
|
|
return $result ? $this->success('更新成功') : $this->fail('更新失败');
|
|
}
|
|
} |