更新
This commit is contained in:
parent
c492cdb38c
commit
3a492b431f
@ -2,6 +2,37 @@
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
class RemoteController extends BaseApiController{
|
||||
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use think\facade\Log;
|
||||
|
||||
class RemoteController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['index'];
|
||||
public function index()
|
||||
{
|
||||
$parmas = [
|
||||
"brigade_id" => "3",
|
||||
"city_code" => "510500",
|
||||
"district_code" => "510502",
|
||||
"street_code" => "510502106",
|
||||
"village_code" => "510502106201",
|
||||
"start_date" => "2023-08-12",
|
||||
"end_date" => "2023-08-12"
|
||||
];
|
||||
try {
|
||||
$res = HttpClient::create()->request('GET', 'https://crmeb-test.shop.lihaink.cn/api/order/statistics', [
|
||||
'query' => $parmas,
|
||||
]);
|
||||
$arr = json_decode($res->getContent(), true);
|
||||
if ($arr['status'] == 200) {
|
||||
$data['total_price'] = $arr['data']['total_price'];
|
||||
} else {
|
||||
$data['total_price'] = 0;
|
||||
Log::error('获取订单金额失败:' . $arr . '参数:' . json_encode($parmas));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
halt($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,8 @@ use think\facade\Log;
|
||||
|
||||
class ShareProfit
|
||||
{
|
||||
public function first($data)
|
||||
public function first($data,$company)
|
||||
{
|
||||
$company=Company::where('id',$data['company_id'])->field('id,deposit,company_money,user_id,day_count')->find();// 可能要判断预存金是否满足
|
||||
if($company['day_count']<=$data['proportion_one']){
|
||||
$proportion=$data['proportion_one'];
|
||||
}else{
|
||||
|
@ -4,8 +4,10 @@ namespace app\job;
|
||||
|
||||
use app\common\logic\finance\ShareProfit;
|
||||
use app\common\model\task\Task;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use think\queue\Job;
|
||||
use think\facade\Log;
|
||||
use app\common\model\Company;
|
||||
|
||||
/**
|
||||
* 任务结算执行的具体逻辑
|
||||
@ -15,35 +17,106 @@ class TaskInformationJob
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
if ($job->attempts() > 3) {
|
||||
//通过这个方法可以检查这个任务已经重试了几次了
|
||||
}
|
||||
$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);
|
||||
}
|
||||
if(count($task_count)==count($task_id)){
|
||||
$name_arr=[];
|
||||
foreach ($task_count as $key => $value) {
|
||||
$name_arr[$key]=$value['director_info']['nickname'];
|
||||
// if ($job->attempts() > 1) {
|
||||
// //通过这个方法可以检查这个任务已经重试了几次了
|
||||
// }
|
||||
$company = Company::where('id', $data['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
|
||||
|
||||
if ($data['template_info']['type'] == 31) {
|
||||
$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);
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
}else{
|
||||
Log::error('任务结算失败,任务id:' . $task_id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($data['template_info']['type'] == 32) {
|
||||
$yesterday = date('Y-m-d', strtotime('-1 day', time()));
|
||||
// "brigade_id" => "3",
|
||||
// "city_code" => "510500",
|
||||
// "district_code" => "510502",
|
||||
// "street_code" => "510502106",
|
||||
// "village_code" => "510502106201",
|
||||
$parmas = [
|
||||
"start_date" => $yesterday,
|
||||
"end_date" => $yesterday
|
||||
];
|
||||
switch ($company['company_type']) {
|
||||
case 18:
|
||||
$parmas['brigade_id'] = $company['brigade'];
|
||||
$parmas['village_code'] = $company['village'];
|
||||
$parmas['street_code'] = $company['street'];
|
||||
$parmas['district_code'] = $company['area'];
|
||||
$parmas['city_code'] = $company['city'];
|
||||
break;
|
||||
case 17:
|
||||
$parmas['village_code'] = $company['village'];
|
||||
$parmas['street_code'] = $company['street'];
|
||||
$parmas['district_code'] = $company['area'];
|
||||
$parmas['city_code'] = $company['city'];
|
||||
break;
|
||||
case 16:
|
||||
$parmas['street_code'] = $company['street'];
|
||||
$parmas['district_code'] = $company['area'];
|
||||
$parmas['city_code'] = $company['city'];
|
||||
break;
|
||||
case 15:
|
||||
$parmas['district_code'] = $company['area'];
|
||||
$parmas['city_code'] = $company['city'];
|
||||
break;
|
||||
case 14:
|
||||
$parmas['city_code'] = $company['city'];
|
||||
break;
|
||||
default:
|
||||
Log::error('任务结算失败,公司类型错误:' . $company['company_type']);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$res = HttpClient::create()->request('GET', 'https://crmeb-test.shop.lihaink.cn/api/order/statistics', [
|
||||
'query' => $parmas,
|
||||
]);
|
||||
$json = json_decode($res->getContent(), true);
|
||||
if ($json['status'] == 200) {
|
||||
$arr['total_price'] = $json['data']['total_price'];
|
||||
} else {
|
||||
$arr['total_price'] = 0;
|
||||
Log::error('获取订单金额失败:' . $json . '参数:' . json_encode($parmas));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('获取订单金额失败:' . $e->getMessage() . '参数:' . json_encode($parmas));
|
||||
return false;
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
try{
|
||||
$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'];
|
||||
} catch (\Exception $e) {
|
||||
Log::error('任务结算失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
(new ShareProfit())->first($arr, $company);
|
||||
//如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法
|
||||
$job->delete();
|
||||
}
|
||||
public function failed($data){
|
||||
Log::error('任务结算失败'.$data);
|
||||
public function failed($data)
|
||||
{
|
||||
Log::error('任务结算失败' . $data);
|
||||
// ...任务达到最大重试次数后,失败了
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user