diff --git a/app/Command/AdjustDoctorInquiryPriceCommand.php b/app/Command/AdjustDoctorInquiryPriceCommand.php new file mode 100644 index 0000000..178a663 --- /dev/null +++ b/app/Command/AdjustDoctorInquiryPriceCommand.php @@ -0,0 +1,106 @@ +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("全部结束"); + } +} diff --git a/app/Model/DoctorInquiryConfig.php b/app/Model/DoctorInquiryConfig.php index dc722de..8681fe7 100644 --- a/app/Model/DoctorInquiryConfig.php +++ b/app/Model/DoctorInquiryConfig.php @@ -6,6 +6,7 @@ namespace App\Model; +use Carbon\Carbon; use Hyperf\Database\Model\Relations\HasOne; use Hyperf\Snowflake\Concern\Snowflake; @@ -18,8 +19,8 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $last_enable_method 最后开启方式(1:自己 2:后台) * @property int $work_num_day 每日接诊数量 * @property string $inquiry_price 接诊价格(专家问诊-公益问诊) - * @property \Carbon\Carbon $created_at 创建时间 - * @property \Carbon\Carbon $updated_at 修改时间 + * @property Carbon $created_at 创建时间 + * @property Carbon $updated_at 修改时间 */ class DoctorInquiryConfig extends Model { @@ -35,11 +36,6 @@ class DoctorInquiryConfig extends Model */ protected array $fillable = ['inquiry_config_id', 'doctor_id', 'inquiry_type', 'inquiry_mode', 'is_enable', 'last_enable_method', 'work_num_day', 'inquiry_price', 'created_at', 'updated_at']; - /** - * The attributes that should be cast to native types. - */ - protected array $casts = ['inquiry_config_id' => 'string', 'doctor_id' => 'string', 'inquiry_type' => 'integer', 'inquiry_mode' => 'integer', 'work_num_day' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'is_enable' => 'integer', 'last_enable_method' => 'integer']; - protected string $primaryKey = "inquiry_config_id"; /** @@ -107,4 +103,28 @@ class DoctorInquiryConfig extends Model { return self::where($params)->min('inquiry_price'); } + + /** + * 自增 + * @param array $params + * @param string $field + * @param float $numeral + * @return int + */ + public static function inc(array $params,string $field,float $numeral = 1): int + { + return self::where($params)->increment($field,$numeral); + } + + /** + * 自减 + * @param array $params + * @param string $field + * @param float $numeral + * @return int + */ + public static function dec(array $params,string $field,float $numeral = 1): int + { + return self::where($params)->decrement($field,$numeral); + } } diff --git a/app/Model/DoctorInquiryConfigService.php b/app/Model/DoctorInquiryConfigService.php deleted file mode 100644 index b33ddad..0000000 --- a/app/Model/DoctorInquiryConfigService.php +++ /dev/null @@ -1,82 +0,0 @@ -first($fields); - } - - /** - * 获取信息-多条 - * @param array $params - * @param array $fields - * @return object|null - */ - public static function getList(array $params, array $fields = ['*']): object|null - { - return self::where($params)->get($fields); - } - - /** - * 新增 - * @param array $data - * @return DoctorInquiryConfigService|\Hyperf\Database\Model\Model - */ - public static function addDoctorInquiryConfigService(array $data): \Hyperf\Database\Model\Model|DoctorInquiryConfigService - { - return self::create($data); - } - - /** - * 修改 - * @param array $params - * @param array $data - * @return int - */ - public static function edit(array $params = [], array $data = []): int - { - return self::where($params)->update($data); - } -} diff --git a/app/Model/UserDoctor.php b/app/Model/UserDoctor.php index 177e938..e09ebe5 100644 --- a/app/Model/UserDoctor.php +++ b/app/Model/UserDoctor.php @@ -49,16 +49,17 @@ use Hyperf\Utils\Arr; * @property int $is_platform_deep_cooperation 是否平台深度合作医生(0:否 1:是) * @property int $is_enterprise_deep_cooperation 是否企业深度合作医生(0:否 1:是) * @property int $is_sys_diagno_cooperation 是否先思达合作医生(0:否 1:是) + * @property int $is_welfare_cooperation 是否公益问诊合作医生(可把公益问诊设为0元) * @property string $qr_code 分享二维码 * @property string $be_good_at 擅长 * @property string $brief_introduction 医生简介 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 - * @property-read \Hyperf\Database\Model\Collection|DoctorExpertise[]|null $DoctorExpertise - * @property-read \Hyperf\Database\Model\Collection|DoctorInquiryConfig[]|null $DoctorInquiryConfig * @property-read Hospital|null $Hospital - * @property-read \Hyperf\Database\Model\Collection|OrderInquiry[]|null $OrderInquiry * @property-read User|null $User + * @property-read \Hyperf\Database\Model\Collection|DoctorInquiryConfig[]|null $DoctorInquiryConfig + * @property-read \Hyperf\Database\Model\Collection|DoctorExpertise[]|null $DoctorExpertise + * @property-read \Hyperf\Database\Model\Collection|OrderInquiry[]|null $OrderInquiry */ class UserDoctor extends Model { @@ -72,7 +73,7 @@ class UserDoctor extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['doctor_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'iden_auth_status', 'iden_auth_time', 'iden_auth_fail_reason', 'multi_point_status', 'multi_point_time', 'multi_point_fail_reason', 'introduction_status', 'introduction_time', 'is_bind_bank', 'is_recommend', 'avatar', 'doctor_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'hospital_id', 'served_patients_num', 'praise_rate', 'avg_response_time', 'number_of_fans', 'is_img_expert_reception', 'is_img_welfare_reception', 'is_img_quick_reception', 'is_platform_deep_cooperation', 'is_enterprise_deep_cooperation', 'is_sys_diagno_cooperation', 'qr_code', 'be_good_at', 'brief_introduction', 'created_at', 'updated_at']; + protected array $fillable = ['doctor_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'iden_auth_status', 'iden_auth_time', 'iden_auth_fail_reason', 'multi_point_status', 'multi_point_time', 'multi_point_fail_reason', 'introduction_status', 'introduction_time', 'is_bind_bank', 'is_recommend', 'avatar', 'doctor_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'hospital_id', 'served_patients_num', 'praise_rate', 'avg_response_time', 'number_of_fans', 'is_img_expert_reception', 'is_img_welfare_reception', 'is_img_quick_reception', 'is_platform_deep_cooperation', 'is_enterprise_deep_cooperation', 'is_sys_diagno_cooperation', 'is_welfare_cooperation', 'qr_code', 'be_good_at', 'brief_introduction', 'created_at', 'updated_at']; protected string $primaryKey = "doctor_id"; @@ -119,7 +120,6 @@ class UserDoctor extends Model return $this->hasMany(OrderInquiry::class, "doctor_id", "doctor_id"); } - /** * 获取医生信息-单条 * @param array $params @@ -366,63 +366,6 @@ class UserDoctor extends Model return $data; } - /** - * 获取问诊医生列表 - * 专家问诊-公益问诊共用 - * @param string $keyword - * @param array $hospital_params 医院搜索条件 - * @param array $doctor_params 医生搜索条件 - * @param array $doctor_expertise_params - * @param int $is_search_welfare_reception 是否搜索公益问诊 - * @param string|int $is_first_online 是否优先在线(1:是) - * @param string|int $sort_order - * @param array $fields - * @param int|null $page - * @param int|null $per_page - * @return array - */ - public static function getInquiryDoctorPageTest(string $keyword = "", array $hospital_params = [], array $doctor_params = [], array $doctor_expertise_params = [],int $is_search_welfare_reception = 0,string|int $is_first_online = 0, string|int $sort_order = 1, array $fields = ["*"], int $page = null, ?int $per_page = 10): array - { - $doctors = UserDoctor::join('user', function ($query) { - $query->on('user_doctor.user_id', '=', 'user.user_id'); - }) - ->select("user_doctor.*") - ->orderBy('user.is_online', 'desc') - ->get(); - - dump($doctors->toArray()); - return array(); - -// $query = self::orderBy('served_patients_num', 'desc'); -// -// if ($is_first_online == 1){ -// $query = $query->join('user', function ($query) { -// $query->on('user_doctor.user_id', '=', 'user.user_id')s -// ->orderBy('user.is_online', 'desc'); -// }) -// ->select(['user_doctor.*','user.is_online']); -// }q - -// if (!empty($sort_order)){ -// if ($sort_order == 1) { -// // 综合-价格从低到高 -// $query->orderBy('served_patients_num', 'desc');// 服务数从多到少 -// } -// } - -// $result = $query->paginate($per_page, $fields, "page", $page); -// -// $data = array(); -// $data['current_page'] = $result->currentPage();// 当前页码 -// $data['total'] = $result->total();//数据总数 -// $data['data'] = $result->items();//数据 -// $data['per_page'] = $result->perPage();//每页个数 -// $data['last_page'] = $result->lastPage();//最后一页 - -// return $data; - } - - /** * 获取是否存在 * @param array $params diff --git a/app/Services/DoctorInquiryService.php b/app/Services/DoctorInquiryService.php index f109ae7..c8af56e 100644 --- a/app/Services/DoctorInquiryService.php +++ b/app/Services/DoctorInquiryService.php @@ -9,7 +9,6 @@ use App\Model\DoctorConfigFollowPackage; use App\Model\DoctorConfigFollowPackageItem; use App\Model\DoctorConfigHealthPackage; use App\Model\DoctorInquiryConfig; -use App\Model\DoctorInquiryConfigService; use App\Model\DoctorInquiryPriceRecord; use App\Model\HealthPackage; use App\Model\SystemInquiryConfig; diff --git a/app/Services/InquiryService.php b/app/Services/InquiryService.php index 14379bd..e682f08 100644 --- a/app/Services/InquiryService.php +++ b/app/Services/InquiryService.php @@ -14,7 +14,6 @@ use App\Model\DetectionProject; use App\Model\DiseaseClass; use App\Model\DoctorConfigDifficultConsultation; use App\Model\DoctorInquiryConfig; -use App\Model\DoctorInquiryConfigService; use App\Model\Hospital; use App\Model\InquiryCaseProduct; use App\Model\MessageIm; diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index 8353d02..c551b60 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -22,7 +22,6 @@ use App\Model\DoctorConfigHealthPackage; use App\Model\DoctorExpertise; use App\Model\DoctorInquiryConfig; use App\Model\DoctorInquiryConfig as DoctorInquiryConfigModel; -use App\Model\DoctorInquiryConfigService; use App\Model\DoctorInquiryTime; use App\Model\DoctorWord; use App\Model\Hospital;