172 lines
5.7 KiB
PHP
172 lines
5.7 KiB
PHP
<?php
|
||
namespace app\api\controller;
|
||
|
||
use app\common\logic\finance\ShareProfit;
|
||
use app\common\logic\task\TaskLogic;
|
||
use app\common\model\Company;
|
||
use app\common\model\task\Task;
|
||
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
||
use app\common\model\task_template\TaskTemplate;
|
||
use think\facade\Log;
|
||
use app\job\TaskInformationJob;
|
||
|
||
class CeshiController extends BaseApiController
|
||
{
|
||
public array $notNeedLogin = ['index','ceshi'];
|
||
|
||
public function index()
|
||
{
|
||
$all=TaskSchedulingPlan::whereDay('end_time','yesterday')->where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray();
|
||
halt($all);
|
||
$all=TaskSchedulingPlan::whereDay('start_time')->where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray();
|
||
foreach($all as $k=>$v){
|
||
queue(TaskInformationJob::class,$v);
|
||
}
|
||
halt(1);
|
||
//,'yesterday'
|
||
$all=TaskSchedulingPlan::whereDay('end_time')->where('is_pay',0)->with(['template_info','scheduling'])->select();
|
||
foreach($all as $k=>$data){
|
||
$task_id=explode(',',$data['task_id']);
|
||
$task_count=Task::where('id','in',$task_id)->field('director_uid')->with('director_info')->select();
|
||
if(empty($task_count)){
|
||
Log::error('任务结算失败,任务id:'.$task_id);
|
||
continue;
|
||
}
|
||
if(count($task_count)==count($task_id)){
|
||
$name_arr=[];
|
||
foreach ($task_count as $key => $value) {
|
||
$name_arr[$key]=$value['director_info']['nickname'];
|
||
}
|
||
$name=implode(',',$name_arr);
|
||
$arr['money']=$data['template_info']['money'];
|
||
$arr['company_id']=$data['scheduling']['company_id'];
|
||
$arr['msg']='来自任务【'.$data['template_info']['title'].'】,执行人:'.$name.',的任务结算';
|
||
$arr['proportion_one']=$data['template_info']['proportion_one'];
|
||
$arr['proportion_two']=$data['template_info']['proportion_two'];
|
||
$arr['sn']=$data['sn'];
|
||
$arr['id']=$data['id'];
|
||
(new ShareProfit())->first($arr);
|
||
}
|
||
}
|
||
halt(2);
|
||
}
|
||
|
||
public function ceshi(){
|
||
|
||
$time=strtotime(date('Y-m-d'));
|
||
// $time=strtotime(date('Y-m-d'));
|
||
// $tiem_end=$time+86399;
|
||
$all=TaskTemplate::where('cron_time','<',$time)->where('status',1)->with('company')->select()->toArray();
|
||
// $all=TaskTemplate::where('id',60)->with('company')->select()->toArray();
|
||
// $all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray();
|
||
$company_id=0;
|
||
foreach($all as $k=>$v){
|
||
TaskLogic::CronAdd($v);
|
||
$company_id=$v['company_id'];
|
||
}
|
||
halt(1);
|
||
$points = [
|
||
[
|
||
"lat"=> 28.914962,
|
||
"lon"=>105.442355
|
||
],
|
||
|
||
[
|
||
"lat"=> 28.915456,
|
||
"lon"=> 105.443891
|
||
],
|
||
[
|
||
"lat"=> 28.917516,
|
||
"lon"=> 105.443371
|
||
],
|
||
[
|
||
"lat"=> 28.917536,
|
||
"lon"=> 105.443415
|
||
],
|
||
[
|
||
"lat"=> 28.917001,
|
||
"lon"=> 105.442421
|
||
],
|
||
[
|
||
"lat"=> 28.917103,
|
||
"lon"=> 105.442291
|
||
],
|
||
[
|
||
"lat"=> 28.916658,
|
||
"lon"=> 105.442897
|
||
],
|
||
[
|
||
"lat"=> 28.916428,
|
||
"lon"=> 105.44278
|
||
],
|
||
[
|
||
"lat"=> 28.917073,
|
||
"lon"=> 105.443507
|
||
],
|
||
[
|
||
"lat"=> 28.917073,
|
||
"lon"=> 105.443522
|
||
],
|
||
[
|
||
"lat"=> 28.916796,
|
||
"lon"=> 105.443466
|
||
],
|
||
[
|
||
"lat"=> 28.916665,
|
||
"lon"=> 105.443357
|
||
],
|
||
[
|
||
"lat"=> 28.916674,
|
||
"lon"=> 105.442294
|
||
],
|
||
[
|
||
"lat"=> 28.916698,
|
||
"lon"=> 105.442268
|
||
],
|
||
[
|
||
"lat"=> 28.917279,
|
||
"lon"=> 105.443006
|
||
],
|
||
[
|
||
"lat"=> 28.917234,
|
||
"lon"=> 105.442979
|
||
]
|
||
];
|
||
$target =[
|
||
"lat"=> 28.917378,
|
||
"lon"=> 105.443005
|
||
];
|
||
|
||
$closestPoint = $this->getClosestPoint($points, $target);
|
||
halt($closestPoint);
|
||
// $time=strtotime(date('Y-m-d',strtotime('+1 day')));
|
||
$time=strtotime(date('Y-m-d'));
|
||
$tiem_end=$time+86399;
|
||
$all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling','company'])->select()->toArray();
|
||
$company_id=0;
|
||
foreach($all as $k=>$v){
|
||
TaskLogic::CronAdd($v);
|
||
$company_id=$v['company_id'];
|
||
}
|
||
if($company_id!=0){
|
||
Company::where('id',$company_id)->inc('day_count')->update();
|
||
}
|
||
halt(TaskLogic::getError());
|
||
}
|
||
|
||
function getClosestPoint($points, $target) {
|
||
$minDistance = PHP_INT_MAX;
|
||
$closestPoint = null;
|
||
foreach ($points as $point) {
|
||
// halt($point,$target);
|
||
$distance = sqrt(pow(($point['lat'] - $target['lat']), 2) + pow(($point['lon'] - $target['lon']), 2));
|
||
|
||
if ($distance < $minDistance) {
|
||
$minDistance = $distance;
|
||
$closestPoint = $point;
|
||
}
|
||
}
|
||
|
||
return [$closestPoint,$distance];
|
||
}
|
||
} |