master
cody 3 months ago
parent b19ae475b8
commit f43a69aae1

@ -16,7 +16,7 @@ class UpdateCompany extends Command
*
* @var string
*/
protected $signature = 'update_company {--user_id=} {--course_id=} {--address=0} {--market=0}';
protected $signature = 'update_company {--user_id=}';
/**
* The console command description.
@ -43,44 +43,25 @@ class UpdateCompany extends Command
public function handle()
{
$user_id = $this->option('user_id');
$course_id = $this->option('course_id');
$updateLocal = (int)$this->option('address');
$updateMarket = (int)$this->option('market');
// 更新公司信息
$this->compnay($user_id, $course_id);
// 更新经纬度信息(可选)
if ($updateLocal) {
$this->local($user_id);
}
// 更新上市状态(可选)
if ($updateMarket) {
$this->updateMarketStatus();
}
$this->compnay($user_id);
return $this->info('全部更新完成');
}
/**
* 更新公司信息
*/
public function compnay($user_id = null, $course_id = null)
public function compnay($user_id = null)
{
if ($user_id) {
// 强制单个更新
$users = User::whereHas('courseSigns', function ($query) {
$query->where('status', 1);
})->where('id', $user_id)->get();
} else {
// 批量更新(只更新有报名审核通过的用户)
$users = User::whereHas('courseSigns', function ($query) use ($course_id) {
$query->where('status', 1);
if ($course_id) {
$query->where('course_id', $course_id);
// 更新
$users = User::whereNotNull('company_name')
->where(function ($query) use ($user_id) {
if ($user_id) {
$query->where('id', $user_id);
}
})->whereNotNull('company_name')
->whereNull('company_id')
->orderBy('id', 'desc')
->get();
}
})->whereNull('company_id')
->orderBy('id', 'desc')
->get();
$total = $users->count();
if ($total == 0) {
@ -96,17 +77,24 @@ class UpdateCompany extends Command
// 获取公司详细信息
$result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]);
if (!$result) {
// 标识一下为匹配到公司,后续可以根据这个字段筛选出未匹配到公司的用户
$user->company_id = 0;
$user->save();
$bar->setMessage($user->company_name . ' 公司不存在', 'status');
$bar->advance();
continue;
}
// 如果$result['enterpriseName']存在数字,跳过
if (preg_match('/\d/', $result['enterpriseName'])) {
$user->company_id = 0;
$user->save();
$bar->setMessage($user->company_name . ' 公司名称包含数字,跳过', 'status');
$bar->advance();
continue;
}
if ($result['status'] == '未注册') {
$user->company_id = 0;
$user->save();
$bar->setMessage($user->company_name . ' 公司未注册,跳过', 'status');
$bar->advance();
continue;
@ -151,6 +139,8 @@ class UpdateCompany extends Command
$user->save();
// 更新上市状态
$this->updateMarketStatus($company->id);
// 更新位置
$this->local($company->id);
$bar->setMessage($result['enterpriseName'] . ' 更新成功', 'status');
$bar->advance();
}
@ -163,22 +153,16 @@ class UpdateCompany extends Command
/**
* 更新经纬度信息
*/
public function local($user_id = null)
public function local($companyId = null)
{
if ($user_id) {
// 强制单个更新
$user = User::find($user_id);
if (empty($user->company_id)) {
return $this->error('用户没有关联公司');
}
$companys = Company::where('id', $user->company_id)->get();
} else {
// 批量更新
$companys = Company::whereNull('company_longitude')
->whereNotNUll('company_address')
->where('company_address', '!=', '')
->get();
}
$companys = Company::whereNull('company_longitude')
->whereNotNull('company_address')
->where('company_address', '!=', '')
->where(function ($query) use ($companyId) {
if ($companyId) {
$query->where('id', $companyId);
}
})->get();
$total = $companys->count();
if ($total == 0) {
@ -217,13 +201,13 @@ class UpdateCompany extends Command
$this->info('开始更新上市状态...');
// 获取所有有 company_tag 的公司
if ($companyId) {
$companies = Company::where('id', $companyId)->get();
} else {
$companies = Company::whereNotNull('company_tag')
->where('company_tag', '!=', '')
->get();
}
$companies = Company::whereNotNull('company_tag')
->where(function ($query) use ($companyId) {
if ($companyId) {
$query->where('id', $companyId);
}
})->where('company_tag', '!=', '')
->get();
$total = $companies->count();
if ($total == 0) {

@ -181,13 +181,13 @@ class UserController extends CommonController
if (isset($all['name']) && !empty($all['name'])) {
$all['letter'] = strtoupper(Pinyin::abbr(mb_substr($all['name'], 0, 1))[0]);
}
$model->fill($all);
$model->save();
// 如果有公司信息,就更新一下公司
if (isset($all['company_name']) && !empty($all['company_name']) && $model->company_name != $all['company_name']) {
// 调用命令行更新
Artisan::call("update_company --user_id={$model->id}");
}
$model->fill($all);
$model->save();
// 判断下,如果用户新加入车牌号,并且有未开始或者进行中的预约,则直接预约车牌号
$appointmentModel = Appointment::where('user_id', $this->getUserId())
->where('status', 1)
@ -235,10 +235,10 @@ class UserController extends CommonController
$query->whereIn('status', [0, 1]);
}
])->with([
'courseSigns' => function ($query) {
$query->whereHas('course')->with('course.typeDetail')->where('status', 1)->where('fee_status', 1);
}
])->find($this->getUserId());
'courseSigns' => function ($query) {
$query->whereHas('course')->with('course.typeDetail')->where('status', 1)->where('fee_status', 1);
}
])->find($this->getUserId());
$doorRepository = new DoorRepository();
$door_appointments = Appointment::where('user_id', $this->getUserId())

Loading…
Cancel
Save