407 lines
20 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\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\TaskScheduling;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use app\job\TaskAdd;
use app\job\TaskInformationJob;
use think\facade\Log;
use app\job\TaskTenZehn;
use think\facade\Db;
use app\common\model\ShopMerchant;
use app\common\model\contract\ShopContract;
class CeshiController extends BaseApiController
{
public array $notNeedLogin = ['index', 'ceshi', 'ceshi1', 'ceshi2', 'service_group_task_add_test', 'service_group_task_settlement_test', 'town_task_add_ceshi', 'town_task_settlement_ceshi'];
public function index()
{ //1201
$id = 9;
$shopMerchant = ShopMerchant::find(['id', $id]);
// $data=json_decode($parmas['data'],true);
// if($data['status']==1){
// if($data['organizationRegNo']!=$shopMerchant->organization_code){
// Log::error(['认证回调错误:',$parmas]);
// return json(['success' => false, 'msg' => '认证回调错误']);
// }
$shopMerchant->save(['is_authentication' => 1]);
// 生成合同
$createContractData = [
'id' => $id,
'party_a' => 1,
'party_a_name' => '泸州市海之农科技有限公司',
'party_b' => $id,
'party_b_name' => $shopMerchant->company_name,
'contract_type' => 22,
];
$model = new ShopContract();
$model->contract_no = time();
$model->create_time = time();
$model->check_status = 1;
$model->update_time = time();
$model->setAttrs($createContractData);
$res = $model->save($createContractData);
// }
halt($res);
$select = Db::name('company_form')->where('type', 0)
->select();
$id = 0;
foreach ($select as $key => $value) {
$id = $value['id'];
if ($value['organization_code'] != '' || $value['organization_code'] != null) {
// $pattern = "/\*/";
$name = $value['master_name'];
// if(preg_match($pattern, $name)){
// $name=$value['master_name'];
// }
// if ($value['master_email']) {
$email = $value['master_email'];
// } else {
// $email = substr(md5(uniqid()), rand(0, 22), 10) . "@lihai.com";
// }
$shopMerchantCertificationData = [
'name' => $name,
'organization_code' => $value['organization_code'],
'business_license' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/561f8202305171526091317.png',
'master_name' => $value['master_name'],
'master_email' => $email,
'id' => $value['id'],
];
// Db::name('company_form')->where('id', $value['id'])->update(['master_email' => $email]);
queue(TaskTenZehn::class,$shopMerchantCertificationData);
} else {
Db::name('company_form')->where('id', $value['id'])->update(['type' => -1]);
continue;
}
// $a=app(JunziqianController::class)->ShopMerchantCertification($shopMerchantCertificationData);
}
halt($id);
}
public function ceshi1()
{
//认证一条龙
$shopMerchantCertificationData = [
'name' => 1212,
'organization_code' => 2323,
'business_license' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/561f8202305171526091317.png',
'master_name' => 3423,
'master_email' => 343,
'id' => 123,
];
app(JunziqianController::class)->ShopMerchantCertification($shopMerchantCertificationData);
halt(111);
}
public function ceshi2()
{
//重新认证
$shopMerchantCertificationData = [
'name' => 1212,
'organization_code' => 2323,
'business_license' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/561f8202305171526091317.png',
'master_name' => 3423,
'master_email' => 343,
'id' => 123,
];
app(JunziqianController::class)->organizationReapply($shopMerchantCertificationData);
halt(111);
}
/**
* 任务刷新
*/
public function ceshi(){
$time=strtotime(date('Y-m-d'));
// $time=strtotime(date('Y-m-d'));
// $tiem_end=$time+86399;where('cron_time','<',$time)->
$plan_all=TaskScheduling::where('id',8)->with('company_info')->select()->toArray();
foreach($plan_all as $k=>$v){
$all=TaskTemplate::where('status',1)->where('task_scheduling',$v['id'])->limit(30)->select()->toArray();
if($all){
$plan_all[$k]['template']=$all;
}else{
unset($plan_all[$k]);
}
}
$company_id=[];
foreach($plan_all as $k=>$v){
foreach($v['template'] as $kk=>$vv){
TaskLogic::CronAdd($vv,$v);
}
$company_id[]=$v['company_id'];
}
Company::where('id','in',$company_id)->inc('day_count')->update();
}
/**
* 小组服务公司任务下发 线上事故调试和紧急修复预案接口
*/
public function service_group_task_add_test()
{
//任务下发
$time = strtotime(date('Y-m-d')); // 今天的000000
// 注意 cron_time
$plan_all = TaskScheduling::where('cron_time', '<', $time)
->where('status', 1)
->where('company_type', 18)
->with('company_info')
->select()
->toArray();
dd($plan_all);
$plan_ids = [];
foreach ($plan_all as $k => $v) {
$all = TaskTemplate::where('status', 1)->where('task_scheduling', $v['id'])->limit(30)->select()->toArray();
$plan_ids[] = $v['id'];
if ($all) {
$plan_all[$k]['template'] = $all;
} else {
unset($plan_all[$k]);
}
}
$company_id = [];
foreach ($plan_all as $k => $v) {
foreach ($v['template'] as $kk => $vv) {
// queue(TaskAdd::class,['data'=>$vv,'data_two'=>$v]);
TaskLogic::CronAdd($vv, $v);
}
$company_id[] = $v['company_id'];
}
Company::where('id', 'in', $company_id)->inc('day_count')->update();
TaskScheduling::where('id', 'in', $plan_ids)->update(['cron_time' => time()]);
Log::info('小组服务公司定时任务下发执行成功' . date('Y-m-d H:i:s'));
return $this->success('定时任务下发执行成功');
}
/**
* 小组服务公司任务结算 线上事故调试和紧急修复预案接口
*/
public function service_group_task_settlement_test()
{
//
$all = TaskSchedulingPlan::whereDay('end_time','today')
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 18)
->where('is_pay',0)
->with(['template_info'])
->select()
->toArray();
dd($all);
foreach($all as $k=>$data){
try {
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]);
$company = Company::where('id', $data['company_id'])->field('id,deposit,responsible_area,company_money,shareholder_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
$arr['status'] = 0;
$arr['company_account_type'] = 1;
//信息更新
if ($data['template_info']['type'] == 31) {
if ($data['template_info']['information_count'] < $data['template_info']['information_day_count']) {
Log::info('信息更新任务,信息更新未达到要求:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
TaskTemplate::where('id',$data['template_id'])->update(['information_count'=>$data['template_info']['information_day_count']]);
return false;
}
$name = '小组队长';
$arr['status'] = 1;
$task = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->find();
$arr['money'] = $task['money'];
Task::where('id', $data['task_id'])->update(['status' => 3]);
} elseif
//交易金额
($data['template_info']['type'] == 33) {
$shang_date_total_price = App(RemoteController::class)->shang_date_total_price($company,[],$data['template_id']);
if ($shang_date_total_price == false) {
Log::info('交易金额任务,交易金额未达到要求:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
return false;
}
$transaction_pool=$data['template_info']['transaction_pool'];//交易金额剩余池
$count_money=bcadd($shang_date_total_price['arr']['total_price'],$transaction_pool,2);//交易金额加资金池金额
if($count_money>$shang_date_total_price['arr']['day_money']){
$day_money=bcsub($count_money,$shang_date_total_price['arr']['day_money'],2);//当计算剩余池before_transaction_pool
$shang_date_total_price['arr']['before_transaction_pool']=$transaction_pool;//变化前
$shang_date_total_price['arr']['after_count_transaction_pool']=$count_money;//变化后
$shang_date_total_price['arr']['after_transaction_pool']=$day_money;//变化后
Task::where('id', $data['task_id'])->update(['status' => 3,'extend'=>json_encode(['transaction'=>$shang_date_total_price])]);
TaskTemplate::where('id',$data['template_info']['id'])->update(['transaction_pool'=>$day_money]);
$shang_date_total_price['arr']['status']=1;
}else{
Log::info('交易金额任务,交易金额小于今日金额:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
return false;
}
$name = $shang_date_total_price['name'];
$arr['status'] = $shang_date_total_price['arr']['status'];
$task = Task::where('id', $data['task_id'])->field('money')->find();
$arr['money'] = $task['money'];
} elseif
//三轮车
($data['template_info']['type'] == 32){
$task = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->with('director_info')->find();
if(empty($task)){
Log::info('三轮车任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
return true;
}
$name=$task['director_info']['nickname'];
$arr['status'] = 1;
$arr['money'] = $task['money'];
}elseif
//入股任务
($data['template_info']['type'] == 35){
$task_35 = Task::where('id', $data['task_id'])->field('director_uid,status,money,start_time,end_time')->with('director_info')->find();
if($task_35){
$day= $data['template_info']['stage_day_one'] + $data['template_info']['stage_day_two'];
if($task_35['status']==3 && $data['template_info']['day_count']<=$day){
$name = $task_35['director_info']['nickname'];
$arr['status'] = 1;
$arr['money'] = $task_35['money'];
$arr['company_account_type'] = 2;
}else{
/**
* 判断入股任务 单次类型 是否超时
* 未超时时刷新开始结束时间
* 超时则关闭
*/
if($data['template_info']['day_count']<=$day){
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 0]);
try{
Task::where('id', $data['task_id'])->update(['create_time' => $task_35['start_time']+86400,'update_time' =>time(),'start_time'=>$task_35['start_time']+86400,'end_time'=>$task_35['start_time']+86400+86399]);
}catch(\Exception $e){
$start_time = strtotime(date('Y-m-d'));
Task::where('id', $data['task_id'])->update(['create_time' => $start_time+86400,'update_time' =>time(),'start_time'=>$start_time+86400,'end_time'=> $start_time + 86400+86399]);
}
return false;
}
if($data['template_info']['day_count']>$day){
Task::where('id', $data['task_id'])->update(['status' =>5]);
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data));
return false;
}
}
}else{
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
return false;
}
}
else {
//其他类型任务
$task = Task::where('id', $data['task_id'])->with('director_info')->find();
if ($task['status'] == 3) {
$name = $task['director_info']['nickname'];
$arr['status'] = 1;
$arr['money'] = $task['money'];
} else if ($task['status'] == 2) {
// 是否超时
$day= $data['template_info']['stage_day_one'] + $data['template_info']['stage_day_two'];
if($data['template_info']['day_count'] >= $day){
Task::where('id', $data['task_id'])->update(['status' =>5]);
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data));
return false;
}
if($data['template_info']['day_count'] < $day){
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 0]);
try{
Task::where('id', $data['task_id'])->update(['create_time' => $task['start_time']+86400,'update_time' =>time(),'start_time'=>$task['start_time']+86400,'end_time'=>$task['start_time']+86400+86399]);
}catch(\Exception $e){
$start_time = strtotime(date('Y-m-d'));
Task::where('id', $data['task_id'])->update(['create_time' => $start_time+86400,'update_time' =>time(),'start_time'=>$start_time+86400,'end_time'=> $start_time + 86400+86399]);
}
return false;
}
}
}
} catch (\Exception $e) {
Log::error('line:'.$e->getLine().'异常报错:任务结算失败:' . $data['template_info']['title'] . $e->getMessage() . json_encode($data));
return false;
}
if ($arr['status'] == 1) {
$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, $company,$data);
} else {
Task::where('id', $data['task_id'])->update(['status' => 5]);
Log::info('任务status=0结算失败' . $data['template_info']['title'] . '未完成' . json_encode($data));
}
// queue(TaskInformationJob::class,$v);
}
Log::info('小组服务公司定时任务结算执行成功'.date('Y-m-d H:i:s'));
return $this->success('小组服务公司定时任务结算执行成功');
}
/**
* 镇农科公司任务下发 线上事故调试和紧急修复预案接口
*/
public function town_task_add_ceshi()
{
//任务下发
$time = strtotime(date('Y-m-d'));
// 查询系统 所有镇农科公司 未下发 的 任务安排
$taskSchedulingList = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->where('company_type', 41)->with('company_info')->select()->toArray();
dd($taskSchedulingList);
$taskSchedulingIds = [];
$companyIds = [];
foreach ($taskSchedulingList as $k => $taskScheduling) {
$templateList = TaskTemplate::where('status', 1)->where('task_scheduling', $taskScheduling['id'])->limit(30)->select()->toArray();
$taskSchedulingIds[] = $taskScheduling['id'];
$companyIds[] = $taskScheduling['company_id'];
foreach ($templateList as $template) {
// queue(TownTaskAdd::class, $template);
TaskLogic::TownCronAdd($template); // 手动下发用
}
if (empty($templateList)) {
unset($taskSchedulingList[$k]);
}
}
Company::where('id', 'in', $companyIds)->inc('day_count')->update();
TaskScheduling::where('id', 'in', $taskSchedulingIds)->update(['cron_time' => time()]);
Log::info('定时任务下发执行成功' . date('Y-m-d H:i:s'));
}
/**
* 镇农科公司任务结算 线上事故调试和紧急修复预案接口
*/
public function town_task_settlement_ceshi()
{
// 今日未结算的任务计划
$taskSchedulingPlanList = TaskSchedulingPlan::whereDay('end_time','today')
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 41)
->where('is_pay',0)
->with(['template_info'])
->select()
->toArray();
dd($taskSchedulingPlanList);
foreach($taskSchedulingPlanList as $taskSchedulingPlan) {
if (in_array($taskSchedulingPlan['template_info']['type'], [44,45,46,47,48,49,50])) {
continue;
}
TaskLogic::townTaskSettlement($taskSchedulingPlan);
}
}
}