修改创建问诊订单 优惠卷部分
This commit is contained in:
+28
-17
@@ -74,23 +74,6 @@ class UserCoupon extends Model
|
||||
->where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠卷信息-单条
|
||||
* @param array $params
|
||||
* @param array $coupon_params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getDateWithCouponOne(array $params, array $coupon_params, array $application_scope_params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::with(['Coupon'])
|
||||
->whereHas('Coupon' , function($query) use ($coupon_params,$application_scope_params){
|
||||
$query->where($coupon_params)->whereIn('application_scope',$application_scope_params);
|
||||
})
|
||||
->where($params)
|
||||
->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户优惠卷
|
||||
* @param array $data
|
||||
@@ -111,4 +94,32 @@ class UserCoupon extends Model
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取患者问诊可用的优惠卷
|
||||
* @param string|int $user_id 用户id
|
||||
* @param string|int $inquiry_type 关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
|
||||
* @param array $fields 字段
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getUserInquiryUsableCoupon(string|int $user_id, string|int $inquiry_type,array $fields = ['*']): Collection|array
|
||||
{
|
||||
$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())]; // 过期使用时间
|
||||
|
||||
return self::with(['Coupon'=> function($query) use($inquiry_type){
|
||||
$query->where("coupon_client",1)
|
||||
->where("coupon_status",1)
|
||||
->where("application_scope",2)
|
||||
->where(function ($query) use ($inquiry_type) {
|
||||
$query->orwhere("inquiry_type","like",'%' . $inquiry_type+1 . '%');
|
||||
$query->orwhere("inquiry_type","like",'%1%');
|
||||
});
|
||||
}])
|
||||
->where($params)
|
||||
->get($fields);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user