107 lines
3.4 KiB
PHP
107 lines
3.4 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Command;
|
||
|
||
use App\Model\DoctorInquiryConfig;
|
||
use App\Model\UserDoctor;
|
||
use Hyperf\Command\Command as HyperfCommand;
|
||
use Hyperf\Command\Annotation\Command;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Redis\Redis;
|
||
use Psr\Container\ContainerExceptionInterface;
|
||
use Psr\Container\ContainerInterface;
|
||
use Psr\Container\NotFoundExceptionInterface;
|
||
|
||
#[Command]
|
||
class AdjustDoctorInquiryPriceCommand extends HyperfCommand
|
||
{
|
||
public function __construct(protected ContainerInterface $container)
|
||
{
|
||
parent::__construct('AdjustDoctorInquiryPriceCommand');
|
||
}
|
||
|
||
public function configure()
|
||
{
|
||
parent::configure();
|
||
$this->setDescription('调整医生问诊价格/每日接诊数量-公益问诊');
|
||
}
|
||
|
||
public function handle(): void
|
||
{
|
||
$this->line("开始");
|
||
|
||
// 获取需执行的医生列表
|
||
$params = array();
|
||
$params[] = ['inquiry_mode', '=', 1];// 接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)
|
||
$doctor_inquiry_configs = DoctorInquiryConfig::getInquiryConfigListByInquiryType($params,['*'],[3]);
|
||
if (empty($doctor_inquiry_configs)){
|
||
$this->line("无数据可执行");
|
||
}
|
||
|
||
try {
|
||
$redis = $this->container->get(Redis::class);
|
||
} catch (\Throwable $e) {
|
||
$this->line($e->getMessage());
|
||
return;
|
||
}
|
||
|
||
foreach ($doctor_inquiry_configs as $doctor_inquiry_config){
|
||
$redis_key = "DoctorInquiryConfig" . $doctor_inquiry_config['doctor_id'];
|
||
$redis_value = $redis->get($redis_key);
|
||
if (!empty($redis_value)){
|
||
// 此医生已处理过,跳过
|
||
continue;
|
||
}
|
||
|
||
// 价格不为0不处理
|
||
if ($doctor_inquiry_config['inquiry_price'] != 0){
|
||
continue;
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_inquiry_config['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)){
|
||
Db::rollBack();
|
||
$this->line("存在一个错误医生:" . $doctor_inquiry_config['doctor_id']);
|
||
continue;
|
||
}
|
||
|
||
// 公益合作医生不处理
|
||
if ($user_doctor['is_welfare_cooperation'] == 1){
|
||
Db::rollBack();
|
||
continue;
|
||
}
|
||
|
||
// 调整该医生价格
|
||
$params = array();
|
||
$params['inquiry_config_id'] = $doctor_inquiry_config['inquiry_config_id'];
|
||
DoctorInquiryConfig::inc($params,"inquiry_price",5);
|
||
|
||
// 调整该医生每日接诊数量
|
||
$params = array();
|
||
$params['inquiry_config_id'] = $doctor_inquiry_config['inquiry_config_id'];
|
||
|
||
$data = array();
|
||
$data['work_num_day'] = 3;
|
||
DoctorInquiryConfig::editInquiryConfig($params,$data);
|
||
|
||
// 添加缓存记录该医生已处理
|
||
$redis->set($redis_key, 1, 60 * 60 * 24 * 1);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
$this->line($e->getMessage());
|
||
}
|
||
}
|
||
|
||
$this->line("全部结束");
|
||
}
|
||
}
|