TaskSystem/app/api/controller/TaskController.php
2023-09-08 21:29:35 +08:00

198 lines
8.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller;
use app\common\logic\task\TaskLogic;
use app\common\model\Company;
use app\common\model\company\CompanyProperty;
use app\common\model\informationg\UserInformationg;
use app\common\model\task\Task;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\User;
use think\facade\Log;
class TaskController extends BaseApiController
{
public function lists()
{
$param = Request()->param();
[$page, $limit] = $this->getPage();
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', 'in', [31,33]];
} else {
$where[] = ['type', '=', 33];
$where[] = ['director_uid', '=', $this->userId];
}
$where[] = ['company_id', '=', $this->userInfo['company_id']];
}
if (isset($param['date_time']) && $param['date_time'] != '') {
$time = strtotime($param['date_time']);
$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]];
} else {
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]];
}
}
if (isset($param['status']) && $param['status'] > 0) {
$where[] = ['status', '=', $param['status']];
}
$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) {
$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']);
if ($find != false) {
if($time<time()){
$transaction_pool=TaskTemplate::where('id',$item['template_id'])->value('transaction_pool');
if($transaction_pool==0){
$find['transaction_pool']=0;
}else{
$find['transaction_pool']=$transaction_pool;
}
$res[$k]['extend']['transaction'] = $find;
}
// Task::where('id',$item['id'])->update(['extend'=>json_encode(['transaction'=>$find],true)]);
} else {
$res[$k]['extend']['transaction'] = '';
}
}
}
return $this->success('ok', $res);
}
//交易详情
public function order_detail()
{
$parmas = $this->request->param();
$task=Task::where('id',$parmas['id'])->field('company_id,start_time,end_time,extend,type,template_id')->find();
if(!$task){
return $this->fail('任务不存在');
}
$transaction_pool=TaskTemplate::where('id',$task['template_id'])->value('transaction_pool');
$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);
$parmas['start_time']=date('Y-m-d',$task['start_time']);
$parmas['end_time']=$task['end_time'].' 23:59:59';
$list = App(RemoteController::class)->shang_date_list($company, 1, $parmas);
if ($task != false) {
$find['list'] = $list;
$find['extend']=$task['extend'];
if($transaction_pool==0){
$find['transaction_pool']=0;
}else{
$find['transaction_pool']=$transaction_pool;
}
return $this->success('ok', $find);
}
return $this->success('ok');
}
/**
* 入股
*/
public function shareholder(){
$parmas = $this->request->param();
$task = TaskLogic::detail($parmas);
return $this->success('ok', $task);
}
/**
* 三轮车详情
*/
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();
$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);
$datas=[
'car_id'=>$object_id,
'start_time'=>$start_time.' 00:00:00',
'end_time'=>$end_time
];
$data['status'] = 2;
if (isset($parmas['terminus'])) {
if( $parmas['terminus']['lnglat'][0]==null || $parmas['terminus']['lnglat'][0]<=0){
return $this->fail('定位不存在');
}
$res = App(RemoteController::class)->coordinate($datas, $parmas['terminus']['lnglat'][0], $parmas['terminus']['lnglat'][1]);
if($res===false){
return $this->fail('定位不存在|或GPS无轨迹');
}
$task['extend']['update']['terminus'] = $parmas['terminus'];
}
if (isset($parmas['transfer'])) {
if( $parmas['transfer']['lnglat'][0]==null || $parmas['transfer']['lnglat'][0]<=0){
return $this->fail('定位不存在');
}
$res = App(RemoteController::class)->coordinate($datas, $parmas['transfer']['lnglat'][0], $parmas['transfer']['lnglat'][1]);
if($res===false){
return $this->fail('定位不存在|或GPS无轨迹');
}
$task['extend']['update']['transfer'] = $parmas['transfer'];
}
if (isset($task['extend']['update']['terminus']) && isset($task['extend']['update']['transfer'])) {
$data['status'] = 3;
}
if($res<100){
$data['extend'] = json_encode($task['extend']);
Task::where('id', $parmas['id'])->update($data);
return $this->success('更新成功');
}
return $this->fail('定位坐标大于100米请重新打卡');
}
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,
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'
)->select()->toArray();
} else {
$list = [];
}
} else {
$list = [];
}
return $this->success('ok', $list);
}
}