TaskSystem/app/api/controller/IndexController.php

237 lines
8.4 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-08-30 15:49:41 +08:00
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate', 'notifyUrl','notifyProperty','notifyAuthentication','notifyVehicleContractUpdate','notifyVillageCarRent'];
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-08-28 09:31:13 +08:00
$group_id=$this->userInfo?$this->userInfo['group_id']:1;
2023-08-26 18:19:46 +08:00
$result = IndexLogic::getConfigData($group_id);
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
2023-08-30 15:49:41 +08:00
public function notifyVillageCarRent(){
//获取参数
$id = $this->request->get('id');
if(empty($id)){
return json(['success' => false, 'msg' => '缺少参数']);
}
//获取合同数据
$contract = VehicleContract::where('id',$id)->find();
if(!$contract || $contract->isEmpty()){
return json(['success' => false, 'msg' => '参数错误']);
}
$car = json_decode($contract['cars_info']);
if ($contract['signing_timer'] == 0) {
VehicleContract::where('id',$id)->update(['signing_timer'=>1]);
}else if($contract['signing_timer'] == 1) {
2023-08-30 18:57:41 +08:00
//更改合同状态
2023-08-30 15:49:41 +08:00
VehicleContract::where('id',$id)->update(['signing_timer'=>2,'status'=>3]);
2023-08-30 18:57:41 +08:00
if($contract['type'] == 0){
//更改车辆状态
VehicleRent::where('car_id',$car[0]['id'])->where('company_id',$contract['company_a_id'])->update([
'rent_company_id' => $contract['company_b_id'],
'status' => 1,
'rent_time' => time()
]);
$party_b_company = Company::field('user_id,master_name,master_phone')->where('id',$contract['company_b_id'])->find();
//通知物流系统添加车辆使用人
curl_post('http://logistics.lihaink.cn/api/createRentCarUser',[],[
'car_id' => $car[0]['id'],
'user_id' => $party_b_company['user_id'],
'user_name' => $party_b_company['master_name'],
'user_phone' => $party_b_company['master_phone'],
]);
}
2023-08-30 15:49:41 +08:00
}
return json(['success' => true, 'msg' => '成功']);
}
2023-08-29 17:23:36 +08:00
//车辆租赁签约合同状态更改
public function notifyVehicleContractUpdate(){
2023-08-30 13:37:20 +08:00
if(!$this->request->isPost()){
return $this->fail('请求方式错误');
2023-08-29 17:23:36 +08:00
}
2023-08-30 13:37:20 +08:00
$param = $this->request->post();
$model = VehicleContract::where('contract_logistic_id',$param['contract_logistic_id'])->find();
2023-08-29 17:23:36 +08:00
if(!$model || $model->isEmpty()){
return $this->fail('数据不存在');
}
2023-08-30 13:37:20 +08:00
$result = $model->where('id',$model['id'])->save($param);
if($result && isset($param['status']) && $param['status'] == 3){
2023-08-29 19:21:15 +08:00
$cars = json_decode($model['cars_info'],true);
foreach($cars as $k=>$v) {
2023-08-30 13:37:20 +08:00
$cars[$k]['type'] = 0;
2023-08-29 19:21:15 +08:00
$cars[$k]['status'] = 0;
$cars[$k]['company_id'] = $model['company_b_id'];
2023-08-30 13:37:20 +08:00
$cars[$k]['create_time'] = $model['create_time'];
2023-08-29 19:21:15 +08:00
}
VehicleRent::saveAll($cars);
}
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不能为空']);
}
$data=[];
2023-08-24 14:17:16 +08:00
$object_id = explode(',',$parmas['object_id']);
foreach($object_id as $k=>$v){
2023-08-24 11:21:33 +08:00
if($v>0){
$data[$k]['company_id']=$parmas['company_id'];
2023-08-24 14:17:16 +08:00
$data[$k]['object_id']=$v;
2023-08-24 11:21:33 +08:00
$data[$k]['type']=1;
}
}
if (count($data)>0){
$res = CompanyProperty::insertAll($data);
}
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
/**
* 认证回调
*/
public function notifyAuthentication()
{
$parmas = Request()->param();
Log::error('notifyAuthentication', $parmas);
if ($parmas) {
Company::where('id',$parmas['id'])->update(['is_authentication'=>1]);
return json(['success' => true, 'msg' => '成功']);
}
return json(['success' => false, 'msg' => '失败,没有参数']);
}
2023-08-24 11:21:33 +08:00
}