TaskSystem/app/api/controller/TaskController.php

148 lines
5.7 KiB
PHP
Raw Normal View History

2023-08-05 16:14:43 +08:00
<?php
namespace app\api\controller;
2023-08-22 15:43:46 +08:00
use app\common\logic\task\TaskLogic;
2023-08-16 15:44:36 +08:00
use app\common\model\Company;
2023-08-16 16:34:11 +08:00
use app\common\model\informationg\UserInformationg;
2023-08-05 16:14:43 +08:00
use app\common\model\task\Task;
2023-08-16 14:56:25 +08:00
use app\common\model\user\User;
2023-08-05 16:14:43 +08:00
2023-08-22 15:05:16 +08:00
class TaskController extends BaseApiController
{
2023-08-05 16:14:43 +08:00
2023-08-22 15:05:16 +08:00
public function lists()
{
2023-08-05 16:14:43 +08:00
$param = Request()->param();
[$page, $limit] = $this->getPage();
2023-08-22 15:05:16 +08:00
if ($this->userInfo['admin_id'] != 0) {
$where[] = ['company_id', '=', $this->userInfo['company_id']];
} else {
$is_captain = User::where('id', $this->userId)->value('is_captain');
if ($is_captain == 1) {
$where[] = ['type', '=', 31];
} else {
$where[] = ['director_uid', '=', $this->userId];
2023-08-16 14:56:25 +08:00
}
2023-08-22 15:05:16 +08:00
$where[] = ['company_id', '=', $this->userInfo['company_id']];
2023-08-22 14:32:57 +08:00
2023-08-15 17:41:31 +08:00
// $where[]=['status','in',[1,2,3,5]];
2023-08-05 16:14:43 +08:00
}
2023-08-22 15:05:16 +08:00
if (isset($param['date_time']) && $param['date_time'] != '') {
$time = strtotime($param['date_time']);
2023-08-22 16:12:34 +08:00
$param['start_time']=date('Y-m-d H:i:s',$time);
2023-08-22 15:05:16 +08:00
$end = $time + 86399;
2023-08-22 16:12:34 +08:00
$param['end_time']=date('Y-m-d H:i:s',$end);
2023-08-22 15:05:16 +08:00
$where[] = ['start_time', 'between', [$time, $end]];
} else {
$time = strtotime(date('Y-m-d'));
2023-08-22 16:12:34 +08:00
$param['start_time']=date('Y-m-d H:i:s',$time);
2023-08-22 15:05:16 +08:00
$end = $time + 86399;
2023-08-22 16:12:34 +08:00
$param['end_time']=date('Y-m-d H:i:s',$end);
2023-08-22 15:05:16 +08:00
$where[] = ['start_time', 'between', [$time, $end]];
2023-08-15 17:27:02 +08:00
}
2023-08-22 15:05:16 +08:00
if (isset($param['status']) && $param['status'] > 0) {
$where[] = ['status', '=', $param['status']];
2023-08-15 18:06:11 +08:00
}
2023-08-22 15:05:16 +08:00
$res = Task::where($where)
->field(['id', 'title', 'money', 'template_id', 'director_uid', 'company_id', 'start_time', 'end_time', 'director_uid', 'type', 'status', 'content', 'extend'])
->page($page, 25)
->order(['id' => 'desc', 'status' => 'asc'])
->select()->toArray();
foreach ($res as $k => $item) {
if ($item['type'] == 33) {
2023-08-16 15:44:36 +08:00
$company = Company::where('id', $item['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
2023-08-22 16:12:34 +08:00
$find = App(RemoteController::class)->shang_date_total_price($company,1,$param);
2023-08-22 15:05:16 +08:00
if ($find != false) {
$res[$k]['extend']['transaction'] = $find;
} else {
$res[$k]['extend']['transaction'] = '';
2023-08-16 15:44:36 +08:00
}
}
2023-08-16 15:54:30 +08:00
}
2023-08-05 16:14:43 +08:00
return $this->success('ok', $res);
}
2023-08-16 16:34:11 +08:00
2023-08-22 15:05:16 +08:00
//交易详情
public function order_detail()
{
$parmas = $this->request->param();
2023-08-22 15:45:50 +08:00
$company_id=Task::where('id',$parmas['id'])->value('company_id');
if(!$company_id){
return $this->fail('任务不存在');
}
$company = Company::where('id', $company_id)->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
2023-08-22 15:05:16 +08:00
$find = App(RemoteController::class)->shang_date_total_price($company);
2023-08-22 15:43:46 +08:00
$list = App(RemoteController::class)->shang_date_list($company, 1, $parmas);
2023-08-22 15:05:16 +08:00
if ($find != false) {
2023-08-22 15:43:46 +08:00
$find['list'] = $list;
2023-08-22 15:05:16 +08:00
return $this->success('ok', $find);
}
return $this->success('ok');
}
2023-08-22 15:43:46 +08:00
/**
* 三轮车详情
*/
public function tricycle_detail()
{
$parmas = $this->request->param();
$task = TaskLogic::detail($parmas);
return $this->success('ok', $task);
}
/**
* 三轮车坐标
*/
public function add_tricycle_coordinate()
{
$parmas = $this->request->param();
$task = Task::where('id', $parmas['id'])->find()->toArray();
2023-08-22 16:37:08 +08:00
$datas=[
'car_id'=>3,
'start_time'=>'2023-08-18',
'end_time'=>'2023-08-18 23:59:59'
];
2023-08-22 15:43:46 +08:00
$data['status'] = 2;
if (isset($parmas['terminus'])) {
2023-08-22 16:37:08 +08:00
$res = App(RemoteController::class)->coordinate($datas, $parmas['terminus']['lnglat'][0], $parmas['terminus']['lnglat'][1]);
2023-08-22 16:57:45 +08:00
$task['extend']['update']['terminus'] = $parmas['terminus'];
2023-08-22 15:43:46 +08:00
}
if (isset($parmas['transfer'])) {
2023-08-22 16:37:08 +08:00
$res = App(RemoteController::class)->coordinate($datas, $parmas['transfer']['lnglat'][0], $parmas['transfer']['lnglat'][1]);
2023-08-22 16:57:45 +08:00
$task['extend']['update']['transfer'] = $parmas['transfer'];
2023-08-22 15:43:46 +08:00
}
if (isset($task['extend']['update']['terminus']) && isset($task['extend']['update']['transfer'])) {
$data['status'] = 3;
}
2023-08-22 16:54:03 +08:00
// if($res<100){
2023-08-22 15:43:46 +08:00
$data['extend'] = json_encode($task['extend']);
2023-08-22 16:56:07 +08:00
Task::where('id', $parmas['id'])->update($data);
2023-08-22 15:43:46 +08:00
return $this->success('更新成功');
2023-08-22 16:54:03 +08:00
// }
2023-08-22 15:43:46 +08:00
return $this->fail('定位坐标大于100米请重新打卡');
}
2023-08-22 15:05:16 +08:00
public function informationg_list()
{
$parmas = Request()->param();
$find = Task::where('id', $parmas['id'])->find();
if ($find['type'] == 31) {
if (isset($find['extend']['informationg']['ids'])) {
$ids = $find['extend']['informationg']['ids'];
$list = UserInformationg::where('id', 'in', $ids)
->field(
'id,name,phone,sex,age,update_time,
2023-08-18 16:32:41 +08:00
area_id,area_id area_name,street_id,street_id street_name,village_id,village_id village_name,brigade_id,brigade_id brigade_name,address'
2023-08-22 15:05:16 +08:00
)->select()->toArray();
} else {
$list = [];
2023-08-18 16:32:41 +08:00
}
2023-08-22 15:05:16 +08:00
} else {
$list = [];
2023-08-16 16:34:11 +08:00
}
2023-08-22 15:05:16 +08:00
return $this->success('ok', $list);
2023-08-16 16:34:11 +08:00
}
2023-08-22 15:05:16 +08:00
}