logistics/app/api/controller/IndexController.php

158 lines
5.3 KiB
PHP
Raw Normal View History

2023-08-07 16:12:28 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\api\controller;
use app\api\logic\IndexLogic;
2023-08-29 17:19:11 +08:00
use app\common\model\contract\Contract;
use app\common\model\vehicle\Vehicle;
2023-08-30 20:52:12 +08:00
use app\common\model\vehicle\VehicleRent;
2023-08-07 16:12:28 +08:00
use think\response\Json;
/**
* index
* Class IndexController
* @package app\api\controller
*/
class IndexController extends BaseApiController
{
2023-08-29 17:19:11 +08:00
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate','notifyUrl'];
2023-08-07 16:12:28 +08:00
2023-08-31 01:19:57 +08:00
private $domain = 'https://worker-task.lihaink.cn';
2023-08-07 16:12:28 +08:00
/**
* @notes 首页数据
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/21 19:15
*/
public function index()
{
$result = IndexLogic::getIndexData();
return $this->data($result);
}
/**
* @notes 全局配置
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/21 19:41
*/
public function config()
{
$result = IndexLogic::getConfigData();
return $this->data($result);
}
/**
* @notes 政策协议
* @return Json
* @author 段誉
* @date 2022/9/20 20:00
*/
public function policy()
{
$type = $this->request->get('type/s', '');
$result = IndexLogic::getPolicyByType($type);
return $this->data($result);
}
/**
* @notes 装修信息
* @return Json
* @author 段誉
* @date 2022/9/21 18:37
*/
public function decorate()
{
$id = $this->request->get('id/d');
$result = IndexLogic::getDecorate($id);
return $this->data($result);
}
2023-08-29 17:19:11 +08:00
public function notifyUrl()
{
$params = Request()->get(['id']);
if(empty($params['id'])){
return json(['success' => false, 'msg' => '缺少参数']);
}
//获取合同数据
$contract = Contract::where('id',$params['id'])->find();
2023-08-31 01:19:57 +08:00
if(empty($contract)){
2023-08-29 17:19:11 +08:00
return json(['success' => false, 'msg' => '参数错误']);
}
2023-08-31 01:19:57 +08:00
if($contract['status'] != 2){
return json(['success' => false, 'msg' => '合同状态错误']);
}
2023-08-29 17:19:11 +08:00
if ($contract['signing_timer'] == 0) {
2023-08-31 01:19:57 +08:00
//更新本地合同状态
2023-09-01 09:49:27 +08:00
$updateLocalRes = Contract::where('id',$contract['id'])->update(['signing_timer'=>1]);
2023-08-31 01:19:57 +08:00
//更新远程
2023-09-01 09:49:27 +08:00
$updateSverRes =curl_post($this->domain.'/api/index/notifyVehicleContractUpdate',[],[
2023-08-30 13:36:12 +08:00
'contract_logistic_id' => $contract['id'],
2023-08-29 17:19:11 +08:00
'signing_timer' => 1,
]);
2023-09-01 09:49:27 +08:00
if(!$updateLocalRes || $updateSverRes['code']==0){
return json(['success' => false, 'msg' => '更新失败']);
}
2023-08-29 17:19:11 +08:00
}else if($contract['signing_timer'] == 1) {
2023-09-01 09:49:27 +08:00
$vehicle = json_decode($contract['cars_info'],true);
if(empty($vehicle)){
return json(['success' => false, 'msg' => '更新失败']);
}
2023-08-31 01:19:57 +08:00
//更新本地合同状态
2023-08-30 13:36:12 +08:00
Contract::where('id',$params['id'])->update(['signing_timer'=>2,'status'=>3]);
2023-09-01 09:49:27 +08:00
//更新本地车辆状态
2023-08-31 09:49:28 +08:00
Vehicle::where('id','in',array_column($vehicle,'id'))->update(['status'=>2]);
2023-08-30 20:52:12 +08:00
$data = [];
2023-08-31 01:19:57 +08:00
foreach($vehicle as $v){
2023-08-30 20:52:12 +08:00
$data[] = [
'car_id' => $v['id'],
2023-08-31 13:53:18 +08:00
'contract_id' => $contract['id'],
2023-08-30 20:52:12 +08:00
'company_id' => $contract['company_b_id'],
'company_name' => $contract['company_b_name'],
'company_user' => $contract['company_b_user'],
'company_phone' => $contract['company_b_phone'],
2023-09-01 09:03:03 +08:00
'create_time' => time(),
'status' => 0
2023-08-30 20:52:12 +08:00
];
}
2023-08-31 01:19:57 +08:00
$vehicleRent = new VehicleRent();
$vehicleRent -> saveAll($data);
curl_post($this->domain.'/api/index/notifyVehicleContractUpdate',[],[
2023-08-30 13:36:12 +08:00
'contract_logistic_id' => $contract['id'],
2023-08-29 19:07:31 +08:00
'signing_timer' => 2,
2023-08-30 13:36:12 +08:00
'status' => 3
2023-08-29 17:19:11 +08:00
]);
2023-08-31 01:19:57 +08:00
curl_post($this->domain.'/api/v1/notify_property',[],[
2023-08-29 17:19:11 +08:00
'company_id' => $contract['company_b_id'],
2023-08-31 01:19:57 +08:00
'object_id' => implode(',',array_column($vehicle,'id'))
2023-08-29 17:19:11 +08:00
]);
}
return json(['success' => true, 'msg' => '成功']);
}
2023-08-07 16:12:28 +08:00
}