TaskSystem/app/api/controller/CeshiController.php
2023-09-19 14:58:52 +08:00

180 lines
6.6 KiB
PHP

<?php
namespace app\api\controller;
use app\common\logic\CompanyLogic;
use app\common\logic\task\TaskLogic;
use app\common\model\Company;
use app\common\model\company\CompanyAccountLog;
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\common\model\user\User as UserModel;
use app\common\model\user\UserAccountLog;
use think\facade\Log;
use app\job\TaskAdd;
use app\job\TaskInformationJob;
use app\job\TaskTenZehn;
use app\api\controller\JunziqianController;
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', 'task_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 task_ceshi()
{
$time = strtotime(date('Y-m-d'));
// $tiem_end=$time+86399;
$plan_all = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->where('company_type', 18)->with('company_info')->select()->toArray();
$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]);
}
$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'));
}
}