TaskSystem/app/api/controller/IndexController.php

456 lines
18 KiB
PHP
Raw Normal View History

2023-07-15 10:16:32 +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-25 14:17:11 +08:00
use app\common\model\Company;
2023-08-24 11:21:33 +08:00
use app\common\model\company\CompanyProperty;
2023-08-29 17:23:36 +08:00
use app\common\model\contract\VehicleContract;
2023-08-29 19:21:15 +08:00
use app\common\model\vehicle\VehicleRent;
2023-07-23 23:17:29 +08:00
use think\facade\Db;
2023-08-25 14:17:11 +08:00
use think\facade\Log;
2023-07-15 10:16:32 +08:00
use think\response\Json;
/**
* index
* Class IndexController
* @package app\api\controller
*/
class IndexController extends BaseApiController
{
2023-09-02 20:01:59 +08:00
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate', 'notifyUrl', 'notifyProperty', 'notifyAuthentication', 'notifyVehicleContractUpdate', 'systemCarRent', 'selfCarRent', 'cancelRent'];
2023-08-25 17:02:47 +08:00
2023-07-15 10:16:32 +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()
{
2023-09-02 20:01:59 +08:00
$parmas = $this->request->param();
$group_id = $this->userInfo ? $this->userInfo['group_id'] : 1;
$result = IndexLogic::getConfigData($group_id, $parmas);
2023-07-15 10:16:32 +08:00
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-24 11:21:33 +08:00
/**签约回调 */
public function notifyUrl()
{
$a = Request()->get();
if ($a) {
$find = Db::name('contract')->where('id', $a['id'])->find();
if ($find) {
if ($find['signing_timer'] == 0) {
Db::name('contract')->where('id', $a['id'])->update(['signing_timer' => 1]);
2023-08-21 09:50:05 +08:00
return true;
2023-08-24 11:21:33 +08:00
} else if ($find['signing_timer'] == 1) {
Db::name('contract')->where('id', $a['id'])->update(['status' => 1, 'signing_timer' => 2]);
if ($find['type'] == 1) {
Db::name('company')->where('id', $find['party_a'])->update(['status' => 1, 'is_contract' => 1]);
Db::name('company')->where('id', $find['party_b'])->update(['status' => 1, 'is_contract' => 1]);
} else {
Db::name('company')->where('id', $find['party_a'])->update(['status' => 1, 'is_contract' => 1]);
Db::name('user')->where('id', $find['party_b'])->update(['is_contract' => 1]);
2023-08-21 09:50:05 +08:00
}
2023-07-23 23:17:29 +08:00
}
}
}
2023-08-24 11:21:33 +08:00
return json(['success' => true, 'msg' => '成功']);
2023-07-21 13:45:36 +08:00
}
2023-07-15 10:16:32 +08:00
//镇街车辆租赁回调
public function townCarRent() {
$id = Request()->get('id');
if(empty($id)){
return json(['success' => false, 'msg' => '缺少参数']);
}
//获取合同数据
$contract = VehicleContract::where('id', $id)->find();
if (empty($contract)) {
return json(['success' => false, 'msg' => '获取数据失败']);
}
if($contract['status'] != 2){
return json(['success' => false, 'msg' => '合同状态错误']);
}
if ($contract['signing_timer'] == 0) {
//更新本地合同状态
$updateLocalRes = VehicleContract::where('id',$contract['id'])->update(['signing_timer'=>1]);
//更新远程
$updateSverRes =curl_post(env('project.logistic_domain').'/api/index/notifyContractUpdate',[],[
'id' => $contract['contract_logistic_id'],
'signing_timer' => 1,
]);
if(!$updateLocalRes || $updateSverRes['code']==0){
return json(['success' => false, 'msg' => '更新失败']);
}
}else if($contract['signing_timer'] == 1){
//更新本地合同状态
$updateLocalRes = VehicleContract::where('id',$contract['id'])->update(['signing_timer'=>2,'status' => 3]);
//更新远程
$updateSverRes =curl_post(env('project.logistic_domain').'/api/index/notifyContractUpdate',[],[
'id' => $contract['contract_logistic_id'],
'signing_timer' => 2,
'status' => 3
]);
if(!$updateLocalRes || $updateSverRes['code']==0){
return json(['success' => false, 'msg' => '更新失败']);
}
}
}
2023-09-01 11:23:04 +08:00
//系统车辆租赁回来
2023-09-02 20:01:59 +08:00
public function systemCarRent()
{
2023-09-01 11:23:04 +08:00
//获取参数
$id = $this->request->get('id');
2023-09-02 20:01:59 +08:00
if (empty($id)) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败1.1']);
2023-09-01 11:23:04 +08:00
}
//获取合同数据
2023-09-02 20:01:59 +08:00
$contract = VehicleContract::where('id', $id)->find();
if (empty($contract)) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败1.2']);
2023-09-01 11:23:04 +08:00
}
2023-09-02 20:01:59 +08:00
if ($contract['type'] != 0) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败1.3']);
2023-09-01 11:23:04 +08:00
}
2023-09-02 20:01:59 +08:00
if ($contract['status'] != 2) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败1.4']);
2023-09-01 11:23:04 +08:00
}
//判断签约方
if ($contract['signing_timer'] == 0) {
//更新合同的签约次数
2023-09-02 20:01:59 +08:00
$res = VehicleContract::where('id', $id)->update(['signing_timer' => 1]);
if (!$res) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败1.5']);
2023-09-01 11:23:04 +08:00
}
return json(['success' => true, 'msg' => '成功']);
2023-09-02 20:01:59 +08:00
} else if ($contract['signing_timer'] == 1) {
2023-09-05 15:04:58 +08:00
//获取签约后的合同
$signContractFile = app(JunziqianController::class)->downloadVehicleContractFile($contract['contract_no']);
$signContractFile = $signContractFile ?? '';
2023-09-01 11:23:04 +08:00
//更改合同状态
2023-09-05 15:04:58 +08:00
VehicleContract::where('id', $id)->update(['signing_timer' => 2, 'status' => 3,'contract_url'=>$signContractFile]);
2023-09-01 11:23:04 +08:00
//添加车辆到租赁列表
2023-09-02 20:01:59 +08:00
$vehicle = json_decode($contract['cars_info'], true);
VehicleRent::where('car_id', $vehicle['id'])->update([
2023-09-01 11:23:04 +08:00
'status' => 2,
'rent_time' => time(),
'rent_company_id' => $contract['company_b_id'],
]);
2023-09-02 20:01:59 +08:00
$party_b = Company::where('id', $contract['company_b_id'])->find();
2023-09-01 11:23:04 +08:00
//通知物流系统跟新
2023-09-04 21:09:37 +08:00
curl_post(env('project.logistic_domain').'/api/updateVehicleRent', [], [
2023-09-01 13:29:44 +08:00
'car_id' => $vehicle['id'],
2023-09-01 14:59:08 +08:00
'use_user_id' => $party_b['user_id'],
'use_user_name' => $party_b['master_name'],
'use_user_phone' => $party_b['master_phone']
]);
CompanyProperty::create([
'company_id' => $contract['company_b_id'],
'object_id' => $vehicle['id'],
2023-09-04 21:09:37 +08:00
'type' => 1,
'create_time' => time(),
'update_time' => time(),
2023-09-01 11:23:04 +08:00
]);
return json(['success' => true, 'msg' => '成功']);
2023-09-02 20:01:59 +08:00
} else {
2023-09-01 11:23:04 +08:00
return json(['success' => true, 'msg' => '成功']);
}
}
2023-09-01 13:29:44 +08:00
//自有车辆租赁回答
2023-09-02 20:01:59 +08:00
public function selfCarRent()
{
2023-09-01 11:23:04 +08:00
//获取参数
$id = $this->request->get('id');
2023-09-02 20:01:59 +08:00
if (empty($id)) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败2.1']);
2023-09-01 11:23:04 +08:00
}
//获取合同数据
2023-09-02 20:01:59 +08:00
$contract = VehicleContract::where('id', $id)->find();
if (empty($contract)) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败2.2']);
2023-09-01 11:23:04 +08:00
}
2023-09-02 20:01:59 +08:00
if ($contract['type'] != 1) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败2.3']);
2023-08-30 15:49:41 +08:00
}
2023-09-02 20:01:59 +08:00
if ($contract['status'] != 2) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败2.4']);
2023-08-31 08:54:53 +08:00
}
2023-09-01 13:29:44 +08:00
//判断签约方
2023-08-30 15:49:41 +08:00
if ($contract['signing_timer'] == 0) {
2023-09-02 20:01:59 +08:00
$res = VehicleContract::where('id', $id)->update(['signing_timer' => 1]);
if (!$res) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败2.5']);
2023-09-01 11:23:04 +08:00
}
return json(['success' => true, 'msg' => '成功']);
2023-09-02 20:01:59 +08:00
} else if ($contract['signing_timer'] == 1) {
2023-08-31 09:32:38 +08:00
//添加车辆到物流系统
2023-09-02 20:01:59 +08:00
$vehicle = json_decode($contract['cars_info'], true);
2023-09-04 21:09:37 +08:00
$curl_res = curl_post(env('project.logistic_domain').'/api/addSelfCar', [], [
2023-09-02 20:01:59 +08:00
'license' => $vehicle['license'],
2023-09-07 13:39:28 +08:00
'pic' => $vehicle['pic'],
2023-09-01 13:29:44 +08:00
'company_id' => $contract['company_a_id'],
'company_name' => $contract['company_a_name'],
'company_user' => $contract['company_a_user'],
'company_phone' => $contract['company_a_phone'],
]);
2023-09-02 20:01:59 +08:00
if (!$curl_res || $curl_res['code'] == 0) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败2.6']);
2023-08-30 18:57:41 +08:00
}
2023-09-02 20:01:59 +08:00
$cars_info = json_encode(['id' => $curl_res['data']['car_id'], 'license' => $vehicle['license']]);
2023-09-05 15:04:58 +08:00
//获取签约后的合同
$signContractFile = app(JunziqianController::class)->downloadVehicleContractFile($contract['contract_no']);
$signContractFile = $signContractFile ?? '';
VehicleContract::where('id', $id)->update(['cars_info'=>$cars_info,'update_time'=>time(),'signing_timer'=>2,'status'=>3,'contract_url'=>$signContractFile]);
2023-09-01 13:29:44 +08:00
VehicleRent::create([
'car_id' => $curl_res['data']['car_id'],
'contract_id' => $contract['id'],
'company_id' => $contract['company_a_id'],
'car_license' => $vehicle['license'],
'status' => 2,
'rent_time' => time(),
'rent_company_id' => $contract['company_b_id'],
'create_time' => time(),
'type' => 1
]);
$car_id = $curl_res['data']['car_id'];
2023-09-02 20:01:59 +08:00
$party_b = Company::where('id', $contract['company_b_id'])->find();
2023-08-31 09:32:38 +08:00
//通知物流系统跟新
2023-09-04 21:09:37 +08:00
curl_post(env('project.logistic_domain').'/api/updateVehicleRent', [], [
2023-08-31 09:32:38 +08:00
'car_id' => $car_id,
'use_user_id' => $party_b['user_id'],
'use_user_name' => $party_b['master_name'],
'use_user_phone' => $party_b['master_phone']
]);
CompanyProperty::create([
'company_id' => $contract['company_b_id'],
'object_id' => $car_id,
2023-09-04 21:09:37 +08:00
'type' => 1,
'create_time' => time(),
'update_time' => time(),
2023-08-31 09:32:38 +08:00
]);
2023-09-01 11:23:04 +08:00
return json(['success' => true, 'msg' => '成功']);
2023-09-02 20:01:59 +08:00
} else {
2023-09-01 11:23:04 +08:00
return json(['success' => true, 'msg' => '成功']);
2023-08-30 15:49:41 +08:00
}
}
2023-09-01 13:29:44 +08:00
//解除合同回调
2023-09-02 20:01:59 +08:00
public function cancelRent()
{
2023-09-01 13:29:44 +08:00
//获取参数
$id = $this->request->get('id');
2023-09-02 20:01:59 +08:00
if (empty($id)) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败3.1']);
}
//获取合同数据
2023-09-02 20:01:59 +08:00
$contract = VehicleContract::where('id', $id)->find();
if (empty($contract)) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败3.2']);
}
2023-09-02 20:01:59 +08:00
if ($contract['type'] != 2) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败3.3']);
}
2023-09-02 20:01:59 +08:00
if ($contract['status'] != 2) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败3.4']);
}
2023-09-02 20:01:59 +08:00
if ($contract['signing_timer'] == 0) {
$res = VehicleContract::where('id', $id)->update(['signing_timer' => 1]);
if (!$res) {
2023-09-01 13:29:44 +08:00
return json(['success' => false, 'msg' => '失败3.5']);
}
return json(['success' => true, 'msg' => '成功']);
2023-09-02 20:01:59 +08:00
} else if ($contract['signing_timer'] == 1) {
2023-09-05 15:04:58 +08:00
//获取签约后的合同
$signContractFile = app(JunziqianController::class)->downloadVehicleContractFile($contract['contract_no']);
$signContractFile = $signContractFile ?? '';
2023-09-01 13:29:44 +08:00
//更改合同状态
2023-09-05 15:04:58 +08:00
VehicleContract::where('id', $id)->update(['signing_timer'=>2,'status'=>3,'contract_url'=>$signContractFile]);
2023-09-01 13:29:44 +08:00
//更改租赁列表车辆状态
2023-09-02 20:01:59 +08:00
$vehicle = json_decode($contract['cars_info'], true);
2023-09-01 21:14:53 +08:00
//获取租赁车辆信息
2023-09-02 20:01:59 +08:00
$vehicleRentInfo = VehicleRent::where('car_id', $vehicle['id'])->find();
2023-09-01 21:14:53 +08:00
//更新原始合同类型
2023-09-02 20:01:59 +08:00
VehicleContract::where('id', $vehicleRentInfo['contract_id'])->update(['type' => 2]);
VehicleRent::where('car_id', $vehicle['id'])->update([
2023-09-01 13:29:44 +08:00
'status' => 3,
]);
2023-09-01 14:59:08 +08:00
//通知物流系统跟新
2023-09-04 21:09:37 +08:00
curl_post(env('project.logistic_domain').'/api/cancelRent', [], [
2023-09-01 14:59:08 +08:00
'car_id' => $vehicle['id'],
'status' => 1
]);
2023-09-01 14:02:35 +08:00
return json(['success' => true, 'msg' => '成功']);
2023-09-02 20:01:59 +08:00
} else {
2023-09-01 13:29:44 +08:00
return json(['success' => true, 'msg' => '成功']);
}
}
2023-08-29 17:23:36 +08:00
//车辆租赁签约合同状态更改
2023-09-02 20:01:59 +08:00
public function notifyVehicleContractUpdate()
{
if (!$this->request->isPost()) {
2023-08-30 13:37:20 +08:00
return $this->fail('请求方式错误');
2023-08-29 17:23:36 +08:00
}
2023-08-30 13:37:20 +08:00
$param = $this->request->post();
2023-09-02 20:01:59 +08:00
if (empty($param['contract_logistic_id'])) {
2023-09-01 17:47:12 +08:00
return $this->fail('缺少必要参数');
}
2023-09-02 20:01:59 +08:00
$model = VehicleContract::where('contract_logistic_id', $param['contract_logistic_id'])->find();
if (empty($model)) {
2023-08-29 17:23:36 +08:00
return $this->fail('数据不存在');
}
2023-09-02 20:01:59 +08:00
$cars = json_decode($model['cars_info'], true);
$result = $model->where('id', $model['id'])->save($param);
if ($result && isset($param['status']) && $param['status'] == 3) {
$data = [];
foreach ($cars as $k => $v) {
2023-08-31 01:24:26 +08:00
$data[$k]['car_id'] = $v['id'];
$data[$k]['car_license'] = $v['license'];
$data[$k]['type'] = 0;
$data[$k]['status'] = 0;
$data[$k]['company_id'] = $model['company_b_id'];
2023-09-04 21:09:37 +08:00
$data[$k]['rent_time'] = 0;
$data[$k]['rent_company_id'] = 0;
2023-09-05 17:46:03 +08:00
$data[$k]['contract_id'] = $model['id'];
2023-08-31 01:24:26 +08:00
$data[$k]['create_time'] = strtotime($model['create_time']);
2023-08-29 19:21:15 +08:00
}
2023-08-31 01:24:26 +08:00
$vehicleRent = new VehicleRent();
2023-09-02 20:01:59 +08:00
$vehicleRent->saveAll($data);
2023-08-29 19:21:15 +08:00
}
2023-08-29 17:23:36 +08:00
//返回
return $result ? $this->success('更新成功') : $this->fail('更新失败');
}
2023-08-24 11:52:56 +08:00
/**
* 资产回调
*/
2023-08-24 11:21:33 +08:00
public function notifyProperty()
{
$parmas = Request()->post();
if ($parmas) {
if (!isset($parmas['company_id']) || $parmas['company_id'] < 0) {
return json(['success' => false, 'msg' => '公司id不能为空']);
}
if (!isset($parmas['object_id'])) {
return json(['success' => false, 'msg' => '对象id不能为空']);
}
2023-09-02 20:01:59 +08:00
$data = [];
$object_id = explode(',', $parmas['object_id']);
foreach ($object_id as $k => $v) {
if ($v > 0) {
$data[$k]['company_id'] = $parmas['company_id'];
$data[$k]['object_id'] = $v;
$data[$k]['type'] = 1;
2023-08-24 11:21:33 +08:00
}
}
2023-09-02 20:01:59 +08:00
if (count($data) <= 0) {
2023-09-01 11:23:04 +08:00
return json(['success' => false, 'msg' => '失败']);
2023-08-24 11:21:33 +08:00
}
2023-09-01 11:23:04 +08:00
$res = CompanyProperty::insertAll($data);
2023-08-24 11:21:33 +08:00
if ($res) {
return json(['success' => true, 'msg' => '成功']);
} else {
return json(['success' => false, 'msg' => '失败']);
}
}
return json(['success' => false, 'msg' => '失败,没有参数']);
}
2023-08-25 14:17:11 +08:00
2023-09-02 20:01:59 +08:00
/**
2023-08-25 14:17:11 +08:00
* 认证回调
*/
public function notifyAuthentication()
{
$parmas = Request()->param();
2023-09-07 18:03:49 +08:00
Log::info(['认证回调:',$parmas]);
2023-09-02 20:01:59 +08:00
try {
if ($parmas) {
2023-09-04 14:09:08 +08:00
$data=json_decode($parmas['data'],true);
// 成功回调标记
$redis = new \Redis();
$cache = $redis->get('authentication_company_id_'.$parmas['id']);
if (!empty($cache)) {
$data = json_decode($cache, true);
$data['is_callback'] = 1;
$redis->set('authentication_company_id_'.$parmas['id'], json_encode($data));
}
if($data['status']==1){
Company::where('id', $parmas['id'])->update(['is_authentication' => 1]);
}
2023-09-04 14:09:08 +08:00
if($data['status']==2){
// 记录认证失败原因
Db::name('company_authentication_fail_log')->insert(['company_id'=>$parmas['id'],'fail_reason'=>$data['msg']]);
2023-09-04 14:09:08 +08:00
}
2023-09-02 20:01:59 +08:00
return json(['success' => true, 'msg' => '成功']);
}
} catch (\Exception $e) {
2023-09-04 14:09:08 +08:00
Log::error('认证回调错误:'.$e->getMessage());
2023-08-25 14:17:11 +08:00
}
2023-09-02 20:01:59 +08:00
2023-08-25 14:17:11 +08:00
return json(['success' => false, 'msg' => '失败,没有参数']);
}
2023-08-24 11:21:33 +08:00
}