commit
28cfc62955
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Course;
|
||||
use App\Models\User;
|
||||
use App\Repositories\MeetRepository;
|
||||
use App\Repositories\YuanheRepository;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
||||
class PushCourses extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'push_courses';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '推送课程数据';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$courses = Course::where('sign_end_date', $today)->whereHas('typeDetail', function ($query) {
|
||||
$query->where('is_push', 1);
|
||||
})->get();
|
||||
if ($courses->isEmpty()) {
|
||||
$this->info('没有可推送的课程');
|
||||
return;
|
||||
}
|
||||
$YuanheRepository = new YuanheRepository();
|
||||
foreach ($courses as $course) {
|
||||
// 所有报名审核成功的用户id
|
||||
$userIds = $course->courseSigns()->where('status', 1)->pluck('user_id');
|
||||
$users = User::whereIn('id', $userIds)->whereNotNull('company_id')->get();
|
||||
foreach ($users as $user) {
|
||||
$result = $YuanheRepository->pushCourses($course, $user);
|
||||
if ($result) {
|
||||
$this->info("推送成功:{$course->name}-{$user->name}");
|
||||
} else {
|
||||
$this->info("推送失败:{$course->name}-{$user->name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->info('全部更新完成');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\AppointmentConfig;
|
||||
use App\Models\Course;
|
||||
use App\Models\ThirdAppointmentLog;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* 元禾控股
|
||||
*/
|
||||
class YuanheRepository
|
||||
{
|
||||
public $baseUrl;
|
||||
public $customerId;
|
||||
public $authKey;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// 测试地址
|
||||
$this->baseUrl = 'https://uat.oriza.com';
|
||||
$this->customerId = '1947941625517604864';
|
||||
$this->authKey = '59C8ED8584EE4BA7BC22FC63BE45C73D';
|
||||
}
|
||||
|
||||
|
||||
public function getHeader()
|
||||
{
|
||||
$timestamp = time() * 1000;
|
||||
$token = $this->customerId . $timestamp . $this->authKey;
|
||||
$token = md5($token);
|
||||
$token = strtoupper($token);
|
||||
|
||||
$header[] = 'Content-Type: application/json';
|
||||
$header[] = "customerId: {$this->customerId}";
|
||||
$header[] = "timestamp: {$timestamp}";
|
||||
$header[] = "token: {$token}";
|
||||
return $header;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 公司查询
|
||||
*/
|
||||
public function companyInfo($params)
|
||||
{
|
||||
$params = json_encode($params);
|
||||
$url = $this->baseUrl . '/master-service/openapi/businessCollege/enterprise/info';
|
||||
$header = $this->getHeader();
|
||||
try {
|
||||
$result = httpCurl($url, 'POST', $params, $header);
|
||||
$result = json_decode($result, true);
|
||||
if ($result['code'] == 200) {
|
||||
return $result['data'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据推送
|
||||
*/
|
||||
public function pushCourses(Course $course, User $user)
|
||||
{
|
||||
if (empty($user->company)) {
|
||||
return false;
|
||||
}
|
||||
$params = [
|
||||
'classTeacher' => $course->teacher->name,
|
||||
'courseName' => $course->name,
|
||||
'description' => $user->company->businessScope,
|
||||
'enterpriseName' => $user->company->company_name,
|
||||
'creditCode' => $user->company->credit_code,
|
||||
'groupId' => '1030004',
|
||||
'openTime' => $course->start_date
|
||||
];
|
||||
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||
$url = $this->baseUrl . '/master-service/openapi/businessCollege/shareInfo/push';
|
||||
$header = $this->getHeader();
|
||||
try {
|
||||
$result = httpCurl($url, 'POST', $params, $header);
|
||||
$result = json_decode($result, true);
|
||||
if ($result['code'] == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue