From 3aed48b9a6160c76828fe135654f7130002a4f71 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 7 Nov 2023 16:46:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=98=E6=83=A0=E5=8D=B7?= =?UTF-8?q?=E8=A1=A8=E3=80=82=E9=87=8D=E5=86=99=E6=B3=A8=E5=86=8C=E5=8F=91?= =?UTF-8?q?=E6=94=BE=E4=BC=98=E6=83=A0=E5=8D=B7=E9=80=BB=E8=BE=91=E3=80=82?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=93=81=E7=89=8Cmodel=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...CouponExpiredNoticeDelayDirectConsumer.php | 3 +- app/Model/BasicBrand.php | 55 +++++ app/Model/Coupon.php | 42 +++- app/Services/CouponService.php | 212 ++++++++---------- app/Services/InquiryService.php | 6 +- app/Services/LoginService.php | 12 +- app/Services/UserCouponService.php | 70 ++++++ app/Services/UserPatientService.php | 4 +- 8 files changed, 261 insertions(+), 143 deletions(-) create mode 100644 app/Model/BasicBrand.php create mode 100644 app/Services/UserCouponService.php diff --git a/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php b/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php index d3ef4c7..cf23ed0 100644 --- a/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php +++ b/app/Amqp/Consumer/UserCouponExpiredNoticeDelayDirectConsumer.php @@ -87,8 +87,7 @@ class UserCouponExpiredNoticeDelayDirectConsumer extends ConsumerMessage // 患者-优惠卷即将过期 $MessagePush = new MessagePush($user_coupon['user_id']); $MessagePush->patientExpireCoupon($coupon['coupon_name']); - - }catch (\Exception $e){ + }catch (\Throwable $e){ Log::getInstance("queue-UserCouponExpiredNotice")->error("错误:" . $e->getMessage()); return Result::DROP; } diff --git a/app/Model/BasicBrand.php b/app/Model/BasicBrand.php new file mode 100644 index 0000000..9d33396 --- /dev/null +++ b/app/Model/BasicBrand.php @@ -0,0 +1,55 @@ +first($fields); + } + + /** + * 获取信息-多条 + * @param array $params + * @param array $fields + * @return Collection|array + */ + public static function getList(array $params, array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } +} diff --git a/app/Model/Coupon.php b/app/Model/Coupon.php index d4f464b..7863a30 100644 --- a/app/Model/Coupon.php +++ b/app/Model/Coupon.php @@ -6,28 +6,37 @@ namespace App\Model; +use Hyperf\Database\Model\Collection; use Hyperf\Snowflake\Concern\Snowflake; /** - * @property int $coupon_id 主键id + * @property string $coupon_id 主键id * @property string $coupon_name 优惠卷名称 * @property string $coupon_icon 优惠卷图片 * @property int $coupon_client 使用平台(1:小程序) - * @property int $coupon_type 优惠卷类型(1:无门槛 2:满减) - * @property int $coupon_status 状态(1:正常 2:强制失效 3:结束) - * @property int $distribution_object 发放对象(1:新注册用户 2:会员 3:近期消费 4:近期购药) - * @property int $application_scope 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) + * @property int $coupon_type 优惠卷类型(1:无门槛 2:满减 3:数量) + * @property int $coupon_status 状态(1:正常 2:强制失效 3:结束 4:删除) + * @property int $distribution_object 发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户) + * @property int $application_scope 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别类别适用 5:单品使用) + * @property int $inquiry_type 关联问诊类型,适用范围为问诊时存在生效(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测) + * @property int $brand_id 关联品牌id(如不限制品牌,此项为空) + * @property int $is_mutex 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用 * @property int $is_display 是否展示(0:否 1:是) - * @property int $distribution_with_day 发放关联时间(发放对象为近期消费等类型时规定天数) + * @property int $distribution_with_day 发放关联天数(发放对象为近期消费等类型时规定天数) + * @property int $min_usable_number 单商品最小可使用数量(默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处) * @property int $coupon_count 发放数量 - * @property int $coupon_take_count 领取数量 - * @property int $coupon_ used_count 使用数量 + * @property int $coupon_take_count 已领取数量 + * @property int $coupon_used_count 已使用数量 * @property string $coupon_price 优惠卷金额 * @property string $with_amount 符合满减标准金额(优惠卷类型为满减时使用) * @property int $valid_type 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效) * @property int $valid_days 自领取之日起有效天数 * @property string $valid_start_time 开始使用时间 * @property string $valid_end_time 结束使用时间 + * @property string $product_id 关联商品id,逗号分隔,指定商品时,填入此项。 + * @property int $reissue_interval_days 确认收货后的再次发放间隔天数(如果设置为 0,则表示不再次发放。当适用范围为商品时生效) + * @property int $is_reissuable_after_expire 过期之后是否允许再次发放(0:否 1:是) + * @property int $is_popup 是否首页弹窗(0:否 1:是) * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 */ @@ -43,12 +52,12 @@ class Coupon extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['coupon_id', 'coupon_name', 'coupon_icon', 'coupon_client', 'coupon_type', 'coupon_status', 'distribution_object', 'application_scope', 'is_display', 'distribution_with_day', 'coupon_count', 'coupon_take_count', 'coupon_used_count', 'coupon_price', 'with_amount', 'valid_type', 'valid_days', 'valid_start_time', 'valid_end_time', 'created_at', 'updated_at']; + protected array $fillable = ['coupon_id', 'coupon_name', 'coupon_icon', 'coupon_client', 'coupon_type', 'coupon_status', 'distribution_object', 'application_scope', 'inquiry_type', 'brand_id', 'is_mutex', 'is_display', 'distribution_with_day', 'min_usable_number', 'coupon_count', 'coupon_take_count', 'coupon_used_count', 'coupon_price', 'with_amount', 'valid_type', 'valid_days', 'valid_start_time', 'valid_end_time', 'product_id', 'reissue_interval_days', 'is_reissuable_after_expire', 'is_popup', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. */ - protected array $casts = ['coupon_id' => 'string', 'coupon_client' => 'integer', 'coupon_type' => 'integer', 'coupon_status' => 'integer', 'distribution_object' => 'integer', 'application_scope' => 'integer', 'is_display' => 'integer', 'distribution_with_day' => 'integer', 'coupon_count' => 'integer', 'coupon_take_count' => 'integer', 'coupon_used_count' => 'integer', 'valid_type' => 'integer', 'valid_days' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['coupon_id' => 'string', 'coupon_client' => 'integer', 'coupon_type' => 'integer', 'coupon_status' => 'integer', 'distribution_object' => 'integer', 'application_scope' => 'integer', 'is_display' => 'integer', 'distribution_with_day' => 'integer', 'coupon_count' => 'integer', 'coupon_take_count' => 'integer', 'coupon_used_count' => 'integer', 'valid_type' => 'integer', 'valid_days' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'is_mutex' => 'integer', 'brand_id' => 'integer', 'min_usable_number' => 'integer', 'reissue_interval_days' => 'integer', 'is_reissuable_after_expire' => 'integer', 'is_popup' => 'integer', 'inquiry_type' => 'integer']; protected string $primaryKey = "coupon_id"; @@ -67,9 +76,9 @@ class Coupon extends Model * 获取信息-多条 * @param array $params * @param array $fields - * @return object|null + * @return Collection|array */ - public static function getList(array $params, array $fields = ['*']): object|null + public static function getList(array $params, array $fields = ['*']): Collection|array { return self::where($params)->get($fields); } @@ -97,4 +106,13 @@ class Coupon extends Model { return self::where($params)->decrement($field,$numeral); } + + // 获取注册用户可领取的优惠卷列表 + public static function getRegisterCouponList(): Collection|array + { + return self::where("coupon_client",1) + ->where("coupon_status",1) + ->whereIn("distribution_object",[1,2]) + ->get(); + } } diff --git a/app/Services/CouponService.php b/app/Services/CouponService.php index e3f7efa..bdf2a14 100644 --- a/app/Services/CouponService.php +++ b/app/Services/CouponService.php @@ -9,6 +9,7 @@ use App\Constants\HttpEnumCode; use App\Model\Coupon; use App\Model\Popup; use App\Model\UserCoupon; +use App\Model\UserPatient; use App\Utils\Log; use Hyperf\Amqp\Producer; use Hyperf\DbConnection\Db; @@ -21,110 +22,58 @@ use Psr\Container\NotFoundExceptionInterface; class CouponService extends BaseService { /** - * 获取用户某状态全部优惠卷-列表 - * @param string|int $user_id 用户id - * @param array $inquiry_type [1,2,3,4,5]适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) - * @param int $user_coupon_status 状态(0:未使用 1:已使用 3:已过期) - * @return array - */ - public function getUserCouponStatusList(string|int $user_id, array $inquiry_type, int $user_coupon_status): array - { - $params = array(); - $params[] = ['user_id', '=', $user_id]; - $params[] = ['user_coupon_status', '=', $user_coupon_status];// 状态(0:未使用 1:已使用 3:已过期) - - $coupon_params = array(); - $coupon_params[] = ['coupon_client', '=', 1]; - $coupon_params[] = ['coupon_status', '=', 1]; // 状态(1:正常 2:强制失效 3:结束 4:删除) - - $application_scope_params = $inquiry_type; // 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) - - $user_coupon = UserCoupon::getWithCouponList($params, $coupon_params, $application_scope_params); - if (empty($user_coupon)) { - return array(); - } - - return $user_coupon->toArray(); - } - - /** - * 获取用户可用优惠卷-单条 - * @param string|int $user_id 用户id - * @param string|int $inquiry_type 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) - * @param int $coupon_client 使用平台(1:小程序) - * @return array - */ - public function getUserUsableCouponOne(string|int $user_id, string|int $inquiry_type, int $coupon_client = 1): array - { - // 问诊类型需加1 - $inquiry_type = $inquiry_type + 1; - - $params = array(); - $params[] = ['user_id', '=', $user_id]; - $params[] = ['user_coupon_status', '=', 0];// 状态(0:未使用 1:已使用 3:已过期) - $params[] = ['valid_start_time', '<', date('Y-m-d H:i:s', time())]; // 有效使用时间 - $params[] = ['valid_end_time', '>', date('Y-m-d H:i:s', time())]; // 过期使用时间 - - $coupon_params = array(); - $coupon_params[] = ['coupon_client', '=', $coupon_client]; - $coupon_params[] = ['coupon_status', '=', 1]; // 状态(1:正常 2:强制失效 3:结束 4:删除) - - $application_scope_params = [1, $inquiry_type]; // 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) - - $user_coupon = UserCoupon::getDateWithCouponOne($params, $coupon_params, $application_scope_params); - if (empty($user_coupon)) { - return array(); - } - - return $user_coupon->toArray(); - } - - /** - * 发放用户优惠卷 - * @param int $distribution_object 发放对象(1:新注册用户 2:会员 3:近期消费 4:近期购药) - * @param string $user_id - * @param string $patient_id - * @param int $coupon_client 使用平台(1:小程序) + * 发放优惠卷 + * @param string $coupon_id 优惠卷id + * @param string $user_id 用户id * @return bool - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface */ - public function DistributeCoupon(int $distribution_object, string $user_id, string $patient_id, int $coupon_client = 1): bool + protected function GrantUserCoupon(string $coupon_id,string $user_id): bool { + // 获取患者数据 $params = array(); - $params['coupon_client'] = $coupon_client; - $params['coupon_status'] = 1; - $params['distribution_object'] = $distribution_object; // 发放对象(1:新注册用户 2:会员 3:近期消费 4:近期购药) + $params['user_id'] = $user_id; + $user_patient = UserPatient::getOne($params); + if (empty($user_patient)){ + return false; + } - $coupon = Coupon::getList($params); - if (empty($coupon)) { + // 获取优惠卷数据 + $params = array(); + $params['coupon_id'] = $coupon_id; + $coupon = Coupon::getOne($params); + if (empty($coupon)){ + return false; + } + + // 判断优惠卷数量是否充足 + if ($coupon['coupon_count'] <= $coupon['coupon_take_count']){ return true; } - foreach ($coupon as $key => $value) { - // 判断发放数量 - if ($value['coupon_count'] == $value['coupon_take_count']) { - continue; - } + // 判断用户是否已有该优惠卷 + $params = array(); + $params['user_id'] = $user_id; + $params['coupon_id'] = $coupon['coupon_id']; + $user_coupon = UserCoupon::getOne($params); + if (!empty($user_coupon)){ + return true; + } + try { // 添加用户优惠卷表 $data = array(); $data['user_id'] = $user_id; - $data['patient_id'] = $patient_id; - $data['coupon_id'] = $value['coupon_id']; - - if ($value['valid_type'] == 1) { + $data['patient_id'] = $user_patient['patient_id']; + $data['coupon_id'] = $coupon_id; + if ($coupon['valid_type'] == 1) { // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效) - $data['valid_start_time'] = $value['valid_start_time']; // 有效使用时间 - $data['valid_end_time'] = $value['valid_end_time']; // 过期使用时间 - } elseif ($value['valid_type'] == 2) { + $data['valid_start_time'] = $coupon['valid_start_time']; // 有效使用时间 + $data['valid_end_time'] = $coupon['valid_end_time']; // 过期使用时间 + } elseif ($coupon['valid_type'] == 2) { // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效) $data['valid_start_time'] = date('Y-m-d H:i:s', time()); // 有效使用时间 - $data['valid_end_time'] = date("Y-m-d H:i:s", strtotime($value['valid_days'] . " day")); - } else { - return false; + $data['valid_end_time'] = date("Y-m-d H:i:s", strtotime($coupon['valid_days'] . " day")); } - $user_coupon = UserCoupon::addUserCoupon($data); if (empty($user_coupon)) { return false; @@ -132,33 +81,35 @@ class CouponService extends BaseService // 增加优惠卷发放数量 $params = array(); - $params['coupon_id'] = $value['coupon_id']; + $params['coupon_id'] = $coupon['coupon_id']; Coupon::inc($params,'coupon_take_count'); // 添加弹窗表 - $data = array(); - $data['user_id'] = $user_id; - $data['app_type'] = 1; - $data['client_type'] = 1;// 客户端类型(1:患者端 2:医生端 3:药师端) - $data['popup_type'] = 2;// 弹窗类型(1:结算费用规则 2:新优惠卷弹窗) - $data['popup_title'] = "新人红包福利"; + if ($coupon['is_popup'] == 1){ + $data = array(); + $data['user_id'] = $user_id; + $data['app_type'] = 1; + $data['client_type'] = 1;// 客户端类型(1:患者端 2:医生端 3:药师端) + $data['popup_type'] = 2;// 弹窗类型(1:结算费用规则 2:新优惠卷弹窗) + $data['popup_title'] = "新人红包福利"; - $popup_content = [ - 'user_coupon_id' => (string)$user_coupon->user_coupon_id, // 优惠卷金额 - 'coupon_price' => $value['coupon_price'], // 优惠卷金额 - 'application_scope' => $value['application_scope'], // 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) - 'valid_type' => $value['valid_type'], // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效) - 'valid_days' => $value['valid_days'], // 自领取之日起有效天数 - 'valid_start_time' => $value['valid_start_time'], // 开始使用时间 - 'valid_end_time' => $value['valid_end_time'], // 结束使用时间 - ]; - $data['popup_content'] = json_encode($popup_content, JSON_UNESCAPED_UNICODE); - $popup = Popup::addPopup($data); - if (empty($popup)) { - return false; + $popup_content = [ + 'user_coupon_id' => (string)$user_coupon->user_coupon_id, // 优惠卷金额 + 'coupon_price' => $coupon['coupon_price'], // 优惠卷金额 + 'application_scope' => $coupon['application_scope'], // 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别类别适用 5:单品使用) + 'inquiry_type' => $coupon['inquiry_type'], // 关联问诊类型,逗号分隔,适用范围为问诊时存在生效(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测) + 'valid_type' => $coupon['valid_type'], // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效) + 'valid_days' => $coupon['valid_days'], // 自领取之日起有效天数 + 'valid_start_time' => $coupon['valid_start_time'], // 开始使用时间 + 'valid_end_time' => $coupon['valid_end_time'], // 结束使用时间 + ]; + $data['popup_content'] = json_encode($popup_content, JSON_UNESCAPED_UNICODE); + $popup = Popup::addPopup($data); + if (empty($popup)) { + return false; + } } - // 添加用户优惠卷自动过期队列 // 添加优惠卷过期队列 $valid_end_time = strtotime($user_coupon->valid_end_time); @@ -173,7 +124,12 @@ class CouponService extends BaseService if (!$res) { return false; } + }catch (\Throwable $e){ + Log::getInstance("CouponService-GrantUserCoupon")->error($e->getMessage()); + return false; + } + try { // 添加优惠卷即将过期提醒队列 if ($time > 60 * 60 * 24 * 2) { $time = 60 * 60 * 24 * 2; @@ -187,16 +143,38 @@ class CouponService extends BaseService $producer = $this->container->get(Producer::class); $res = $producer->produce($message); if (!$res) { - return false; + Log::getInstance("CouponService-GrantUserCoupon")->error("添加优惠卷即将过期提醒队列"); } - try { - // 患者-优惠卷发放 - $MessagePush = new MessagePush($user_id); - $MessagePush->patientDistributeCoupon($value['coupon_name']); - } catch (\Exception $e) { - // 不做处理 - Log::getInstance()->error($e->getMessage()); + // 通知-患者-优惠卷发放 + $MessagePush = new MessagePush($user_id); + $MessagePush->patientDistributeCoupon($coupon['coupon_name']); + }catch (\Throwable $e){ + Log::getInstance("CouponService-GrantUserCoupon")->error($e->getMessage()); + } + + return true; + } + + /** + * 发放注册用户优惠卷 + * @param string $user_id 用户id + * @return bool + */ + public function GrantRegisterCoupon(string $user_id): bool + { + // 获取注册用户可领取的优惠卷列表 + $coupon = Coupon::getRegisterCouponList(); + if (empty($coupon)) { + return true; + } + + foreach ($coupon as $value){ + // 发放优惠卷 + $res = $this->GrantUserCoupon($value['coupon_id'],$user_id); + if (!$res){ + // 发放失败 + Log::getInstance("CouponService-GrantRegisterCoupon")->error("发放注册用户优惠卷"); } } diff --git a/app/Services/InquiryService.php b/app/Services/InquiryService.php index 519cc19..73b3c8b 100644 --- a/app/Services/InquiryService.php +++ b/app/Services/InquiryService.php @@ -155,9 +155,9 @@ class InquiryService extends BaseService $inquiry_price = $DoctorInquiryService->getDoctorInquiryPrice($request_params['inquiry_type'], $request_params['inquiry_mode'], $request_params['doctor_id'] ?: ""); if ($inquiry_price > 0) { - // 获取可用优惠卷 - $CouponService = new CouponService(); - $user_coupon = $CouponService->getUserUsableCouponOne($user_info['user_id'], $request_params['inquiry_type']); + // 获取用户可用优惠卷 + $userCouponService = new UserCouponService(); + $user_coupon = $userCouponService->getUserUsableCouponOne($user_info['user_id'], $request_params['inquiry_type']); } // 确定支付渠道 diff --git a/app/Services/LoginService.php b/app/Services/LoginService.php index c733fa6..7fde8dc 100644 --- a/app/Services/LoginService.php +++ b/app/Services/LoginService.php @@ -145,10 +145,9 @@ class LoginService extends BaseService $account->createAccount($user->user_id, $user->user_name, addAliyunOssWebsite($avatar)); if ($user['user_type'] == 1) { - // 发放用户优惠卷 + // 发放注册用户优惠卷 $CouponService = new CouponService(); - - $res = $CouponService->DistributeCoupon(1, (string)$user->user_id, $user_patient['patient_id']); + $res = $CouponService->GrantRegisterCoupon($user->user_id); if (!$res) { Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR); @@ -411,10 +410,9 @@ class LoginService extends BaseService $account->createAccount($user->user_id, $user->user_name, addAliyunOssWebsite($avatar)); if ($user['user_type'] == 1) { - // 发放用户优惠卷 + // 发放注册用户优惠卷 $CouponService = new CouponService(); - - $res = $CouponService->DistributeCoupon(1, (string)$user->user_id, $user_patient['patient_id']); + $res = $CouponService->GrantRegisterCoupon($user->user_id); if (!$res) { Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR); @@ -545,7 +543,7 @@ class LoginService extends BaseService Db::commit(); return success($data); - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollBack(); return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage()); } diff --git a/app/Services/UserCouponService.php b/app/Services/UserCouponService.php new file mode 100644 index 0000000..1a383eb --- /dev/null +++ b/app/Services/UserCouponService.php @@ -0,0 +1,70 @@ +', date('Y-m-d H:i:s', time())]; // 过期使用时间 + + $coupon_params = array(); + $coupon_params[] = ['coupon_client', '=', $coupon_client]; + $coupon_params[] = ['coupon_status', '=', 1]; // 状态(1:正常 2:强制失效 3:结束 4:删除) + + $application_scope_params = [1, $inquiry_type]; // 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) + + $user_coupon = \App\Model\UserCoupon::getDateWithCouponOne($params, $coupon_params, $application_scope_params); + if (empty($user_coupon)) { + return array(); + } + + return $user_coupon->toArray(); + } + + /** + * 获取用户某状态全部优惠卷-列表 + * @param string|int $user_id 用户id + * @param array $inquiry_type [1,2,3,4,5]适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) + * @param int $user_coupon_status 状态(0:未使用 1:已使用 3:已过期) + * @return array + */ + public function getUserCouponStatusList(string|int $user_id, array $inquiry_type, int $user_coupon_status): array + { + $params = array(); + $params[] = ['user_id', '=', $user_id]; + $params[] = ['user_coupon_status', '=', $user_coupon_status];// 状态(0:未使用 1:已使用 3:已过期) + + $coupon_params = array(); + $coupon_params[] = ['coupon_client', '=', 1]; + $coupon_params[] = ['coupon_status', '=', 1]; // 状态(1:正常 2:强制失效 3:结束 4:删除) + + $application_scope_params = $inquiry_type; // 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) + + $user_coupon = UserCoupon::getWithCouponList($params, $coupon_params, $application_scope_params); + if (empty($user_coupon)) { + return array(); + } + + return $user_coupon->toArray(); + } +} \ No newline at end of file diff --git a/app/Services/UserPatientService.php b/app/Services/UserPatientService.php index 1df621b..91d9da0 100644 --- a/app/Services/UserPatientService.php +++ b/app/Services/UserPatientService.php @@ -140,9 +140,9 @@ class UserPatientService extends BaseService return fail(HttpEnumCode::HTTP_ERROR, "非法用户"); } - $CouponService = new CouponService(); + $userCouponService = new UserCouponService(); - $user_coupon = $CouponService->getUserCouponStatusList($user_patient['user_id'],[1,2,3,4,5],$user_coupon_status); + $user_coupon = $userCouponService->getUserCouponStatusList($user_patient['user_id'],[1,2,3,4,5],$user_coupon_status); $result = []; foreach ($user_coupon as $item){