master
cody 5 months ago
parent f153a87e99
commit 64675e5319

@ -0,0 +1,74 @@
<?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 {--course_id=}';
/**
* 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()
{
$course_id = $this->option('course_id');
$courses = Course::where(function ($query) use ($course_id) {
if ($course_id) {
$query->where('id', $course_id);
}
})->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('全部更新完成');
}
}

@ -11,6 +11,7 @@ use App\Models\CustomForm;
use App\Models\User;
use App\Notifications\CourseContentNotify;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Validator;
@ -238,6 +239,11 @@ class CourseController extends BaseController
if ($model->status == 1 && $model->start_date) {
CourseAppointmentTotal::addByCourse($model->id);
}
// 如果添加了开课时间,就推送数据
if ($model->start_date) {
// 调用命令行更新
Artisan::call("push_courses --course_id={$model->id}");
}
// 记录日志
$this->saveLogs($original, $model);
return $this->success($model);

@ -164,6 +164,11 @@ class User extends Authenticatable implements Auditable
return $this->hasMany(Appointment::class, 'user_id', 'id');
}
public function company()
{
return $this->hasOne(Company::class, 'id', 'company_id');
}
/**
* 获取预约剩余次数
*/

@ -3,7 +3,9 @@
namespace App\Repositories;
use App\Models\AppointmentConfig;
use App\Models\Course;
use App\Models\ThirdAppointmentLog;
use App\Models\User;
/**
* 元禾控股
@ -59,4 +61,37 @@ class YuanheRepository
}
}
/**
* 数据推送
*/
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;
}
}
}

@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*
@ -16,6 +15,8 @@ return new class extends Migration
Schema::table('course_types', function (Blueprint $table) {
// 是否参与统计
$table->boolean('is_chart')->default(true)->comment('是否参与统计0否1是');
// 是否推送
$table->boolean('is_push')->default(false)->comment('是否推送0否1是');
});
}

Loading…
Cancel
Save