TaskSystem/app/api/controller/TaskController.php

231 lines
9.6 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-24 16:08:13 +08:00
use app\common\model\company\CompanyProperty;
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-30 10:25:31 +08:00
use app\common\model\task_template\TaskTemplate;
2023-08-16 14:56:25 +08:00
use app\common\model\user\User;
2023-08-30 17:34:51 +08:00
use think\facade\Log;
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();
$time = strtotime(date('Y-m-d'));
2023-08-22 15:05:16 +08:00
if ($this->userInfo['admin_id'] != 0) {
$where[] = ['company_id', '=', $this->userInfo['company_id']];
} else {
2023-08-28 09:31:13 +08:00
2023-08-22 15:05:16 +08:00
$is_captain = User::where('id', $this->userId)->value('is_captain');
if ($is_captain == 1) {
2023-08-28 09:31:13 +08:00
$where[] = ['type', 'in', [31,33]];
2023-08-22 15:05:16 +08:00
} else {
2023-08-28 09:31:13 +08:00
$where[] = ['type', '=', 33];
2023-08-22 15:05:16 +08:00
$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-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 {
2023-08-26 17:15:01 +08:00
if(!isset($param['status'])){
$time = strtotime(date('Y-m-d'));
$param['start_time']=date('Y-m-d H:i:s',$time);
$end = $time + 86399;
$param['end_time']=date('Y-m-d H:i:s',$end);
$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-30 17:34:51 +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,responsible_area')->find(); // 可能要判断预存金是否满足
$find = App(RemoteController::class)->shang_date_total_price($company,$param,$item['template_id']);
2023-08-22 15:05:16 +08:00
if ($find != false) {
if($time<time()){
$transaction_pool=TaskTemplate::where('id',$item['template_id'])->value('transaction_pool');
2023-09-13 14:29:48 +08:00
$res[$k]['extend']['transaction'] = $find;
if($transaction_pool==0){
2023-09-13 14:29:48 +08:00
$res[$k]['extend']['transaction']['arr']['transaction_pool']=$find['arr']['total_price'];
}else{
2023-09-13 14:29:48 +08:00
$res[$k]['extend']['transaction']['arr']['transaction_pool']=bcadd($res[$k]['extend']['transaction']['arr']['total_price'],$transaction_pool,2);
}
2023-08-30 10:57:37 +08:00
}
// Task::where('id',$item['id'])->update(['extend'=>json_encode(['transaction'=>$find],true)]);
2023-08-22 15:05:16 +08:00
} 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-30 10:25:31 +08:00
$task=Task::where('id',$parmas['id'])->field('company_id,start_time,end_time,extend,type,template_id')->find();
2023-08-24 11:52:56 +08:00
if(!$task){
2023-08-22 15:45:50 +08:00
return $this->fail('任务不存在');
}
2023-09-11 13:42:32 +08:00
$task=$task->toArray();
2023-08-30 10:25:31 +08:00
$transaction_pool=TaskTemplate::where('id',$task['template_id'])->value('transaction_pool');
2023-08-30 21:08:12 +08:00
$company = Company::where('id', $task['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade,responsible_area')->find(); // 可能要判断预存金是否满足
// $list = App(RemoteController::class)->shang_date_list($company, 1, $parmas);
2023-08-24 12:07:04 +08:00
$parmas['start_time']=date('Y-m-d',$task['start_time']);
$parmas['end_time']=$task['end_time'].' 23:59:59';
2023-09-13 14:29:48 +08:00
$list = App(RemoteController::class)->shang_date_list($company, $parmas);
$shang_date_total_price = App(RemoteController::class)->shang_date_total_price($company,$parmas,$task['template_id']);
2023-08-26 16:56:02 +08:00
if ($task != false) {
2023-08-22 15:43:46 +08:00
$find['list'] = $list;
2023-08-30 10:57:37 +08:00
if($transaction_pool==0){
2023-09-13 14:29:48 +08:00
$task['extend']['transaction']['arr']['transaction_pool']=$shang_date_total_price['arr']['total_price'];
2023-08-30 10:57:37 +08:00
}else{
2023-09-13 14:29:48 +08:00
$task['extend']['transaction']['arr']['transaction_pool']=bcadd($shang_date_total_price['arr']['total_price'],$transaction_pool,2);
2023-08-30 10:57:37 +08:00
}
2023-09-13 15:09:33 +08:00
if($task['start_time']<strtotime(date('Y-m-d'))){
$task['extend']['transaction']['arr']['is_show']=false;
}else{
$task['extend']['transaction']['arr']['is_show']=true;
}
2023-09-11 13:42:32 +08:00
$find['extend']=$task['extend'];
2023-08-22 15:05:16 +08:00
return $this->success('ok', $find);
}
return $this->success('ok');
}
2023-08-28 18:46:43 +08:00
/**
* 入股
*/
public function shareholder(){
$parmas = $this->request->param();
$task = TaskLogic::detail($parmas);
return $this->success('ok', $task);
}
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-24 16:08:13 +08:00
$object_id=CompanyProperty::where('company_id',$this->userInfo['company_id'])->value('object_id');
if(!$object_id){
return $this->fail('该公司没有三轮车,请先租赁三轮车');
}
$start_time = date('Y-m-d');
$time=strtotime($start_time)+86399;
$end_time=date('Y-m-d H:i:s',$time);
2023-08-22 16:37:08 +08:00
$datas=[
2023-08-24 16:08:13 +08:00
'car_id'=>$object_id,
2023-08-25 14:05:14 +08:00
'start_time'=>$start_time.' 00:00:00',
'end_time'=>$end_time
2023-08-22 16:37:08 +08:00
];
2023-08-22 15:43:46 +08:00
$data['status'] = 2;
if (isset($parmas['terminus'])) {
2023-08-24 18:27:54 +08:00
if( $parmas['terminus']['lnglat'][0]==null || $parmas['terminus']['lnglat'][0]<=0){
return $this->fail('定位不存在');
}
2023-08-22 16:37:08 +08:00
$res = App(RemoteController::class)->coordinate($datas, $parmas['terminus']['lnglat'][0], $parmas['terminus']['lnglat'][1]);
2023-08-25 13:50:03 +08:00
if($res===false){
2023-08-24 18:35:29 +08:00
return $this->fail('定位不存在|或GPS无轨迹');
}
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-25 11:11:45 +08:00
if( $parmas['transfer']['lnglat'][0]==null || $parmas['transfer']['lnglat'][0]<=0){
2023-08-24 18:27:54 +08:00
return $this->fail('定位不存在');
}
2023-08-22 16:37:08 +08:00
$res = App(RemoteController::class)->coordinate($datas, $parmas['transfer']['lnglat'][0], $parmas['transfer']['lnglat'][1]);
2023-08-25 13:50:03 +08:00
if($res===false){
2023-08-24 18:35:29 +08:00
return $this->fail('定位不存在|或GPS无轨迹');
}
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-30 18:28:57 +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-25 16:56:15 +08:00
}
2023-08-30 18:28:57 +08:00
return $this->fail('定位坐标大于100米请重新打卡');
2023-08-22 15:43:46 +08:00
}
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
}
/**
* 其他任务详情
*/
public function other_task_detail(){
$parmas = $this->request->param();
$task = TaskLogic::detail($parmas);
return $this->success('ok', $task);
}
/**
* 其他任务 -提交
*/
2023-09-14 14:42:16 +08:00
public function cimmit_other_task()
{
$parmas = $this->request->param(); //id note annex
$task = TaskLogic::detail($parmas);
if (empty($task)) {
$this->fail('任务不存在');
}
$extend = ['other' => ['is_commit' => 1, 'note' => $parmas['note'], 'annex'=>$parmas['annex']]];
Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend)]);
return $this->success('ok', []);
}
2023-08-22 15:05:16 +08:00
}