简化了患者端药品微信支付回调的再次发放优惠卷的方法调用、增加了发放优惠卷时数量的判断、增加了再次发放订单优惠卷的方法
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer;
|
||||
use App\Amqp\Producer\GrantUserCouponDelayDirectProducer;
|
||||
use App\Amqp\Producer\UserCouponExpiredDelayDirectProducer;
|
||||
use App\Amqp\Producer\UserCouponExpiredNoticeDelayDirectProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Model\Coupon;
|
||||
use App\Model\OrderCoupon;
|
||||
use App\Model\Popup;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserPatient;
|
||||
@@ -25,9 +27,10 @@ class CouponService extends BaseService
|
||||
* 发放优惠卷
|
||||
* @param string $coupon_id 优惠卷id
|
||||
* @param string $user_id 用户id
|
||||
* @param int $grant_quantity 发放数量
|
||||
* @return bool
|
||||
*/
|
||||
public function GrantUserCoupon(string $coupon_id,string $user_id): bool
|
||||
public function GrantUserCoupon(string $coupon_id,string $user_id,int $grant_quantity = 1): bool
|
||||
{
|
||||
// 获取患者数据
|
||||
$params = array();
|
||||
@@ -47,7 +50,13 @@ class CouponService extends BaseService
|
||||
|
||||
// 判断优惠卷数量是否充足
|
||||
if ($coupon['coupon_count'] <= $coupon['coupon_take_count']){
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 优惠卷剩余数量
|
||||
$remaining_quantity = $coupon['coupon_count'] - $coupon['coupon_take_count'];
|
||||
if ($remaining_quantity <= $grant_quantity){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断用户是否已有该优惠卷
|
||||
@@ -216,4 +225,66 @@ class CouponService extends BaseService
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 再次发放订单优惠卷
|
||||
* @param string $order_id
|
||||
* @return bool
|
||||
*/
|
||||
public function againGrantOrderCoupon(string $order_id): bool
|
||||
{
|
||||
try {
|
||||
// 获取订单优惠卷数据
|
||||
$params = array();
|
||||
$params['order_id'] = $order_id;
|
||||
$order_coupons = OrderCoupon::getList($params);
|
||||
if (empty($order_coupons)){
|
||||
// 无订单优惠卷。无需再次发放
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($order_coupons as $order_coupon) {
|
||||
// 获取用户优惠卷数据
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $order_coupon['user_coupon_id'];
|
||||
$user_coupon = UserCoupon::getOne($params);
|
||||
if (empty($user_coupon)){
|
||||
// 未查到患者历史优惠卷数据。无需再次发放
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取优惠卷数据
|
||||
$params = array();
|
||||
$params['coupon_id'] = $user_coupon['coupon_id'];
|
||||
$coupon = Coupon::getOne($params);
|
||||
if (empty($coupon)){
|
||||
// 未查到优惠卷数据。无需再次发放
|
||||
continue;
|
||||
}
|
||||
|
||||
// 确认收货后的再次发放间隔天数
|
||||
if ($coupon['reissue_interval_days'] == 0){
|
||||
// 无需再次发放
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['coupon_id'] = $coupon['coupon_id'];
|
||||
$data['user_id'] = $user_coupon['user_id'];
|
||||
|
||||
$time = $coupon['reissue_interval_days'] * 24 * 60 * 60 * 1000;
|
||||
$message = new GrantUserCouponDelayDirectProducer($data);
|
||||
$message->setDelayMs($time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Log::getInstance("CouponService-againGrantOrderCoupon")->error("再次发放优惠卷失败");
|
||||
}
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("CouponService-againGrantOrderCoupon")->error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1181,6 +1181,15 @@ class PatientOrderService extends BaseService
|
||||
$order_type = $this->request->input('order_type');
|
||||
$order_no = $this->request->input('order_no');
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_no'] = $order_no;
|
||||
$order = Order::getOne($params);
|
||||
if (empty($order))
|
||||
{
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
switch ($order_type) {
|
||||
@@ -1347,50 +1356,6 @@ class PatientOrderService extends BaseService
|
||||
$params['order_no'] = $order_product['order_product_no'];
|
||||
Order::edit($params, $data);
|
||||
|
||||
try {
|
||||
if ($order_product['coupon_amount_total'] > 0) {
|
||||
// 获取药品订单优惠卷数据
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
$order_product_coupons = OrderProductCoupon::getList($params);
|
||||
if (!empty($order_product_coupons)) {
|
||||
foreach ($order_product_coupons as $order_product_coupon) {
|
||||
// 获取用户优惠卷数据
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $order_product_coupon['user_coupon_id'];
|
||||
$user_coupon = UserCoupon::getOne($params);
|
||||
if (!empty($user_coupon)) {
|
||||
// 获取优惠卷数据
|
||||
$params = array();
|
||||
$params['coupon_id'] = $user_coupon['coupon_id'];
|
||||
$coupon = Coupon::getOne($params);
|
||||
if (!empty($coupon)) {
|
||||
if ($coupon['reissue_interval_days'] > 0) {
|
||||
$data = array();
|
||||
$data['coupon_id'] = $coupon['coupon_id'];
|
||||
$data['user_id'] = $user_coupon['user_id'];
|
||||
|
||||
$time = $coupon['reissue_interval_days'] * 24 * 60 * 60 * 1000;
|
||||
$message = new GrantUserCouponDelayDirectProducer($data);
|
||||
$message->setDelayMs($time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Log::getInstance("PatientOrderService-addPatientOrderPay")->error("再次发放优惠卷失败");
|
||||
}
|
||||
|
||||
Log::getInstance("PatientOrderService-addPatientOrderPay")->info("再次发放优惠卷成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// 此处异常不做处理
|
||||
Log::getInstance("PatientOrderService-addPatientOrderPay")->error($e->getMessage());
|
||||
}
|
||||
|
||||
break;
|
||||
case 3: // 检测订单
|
||||
Db::rollBack();
|
||||
@@ -1414,6 +1379,19 @@ class PatientOrderService extends BaseService
|
||||
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
if ($order['coupon_amount_total'] > 0) {
|
||||
$couponService = new CouponService();
|
||||
$res = $couponService->againGrantOrderCoupon($order['order_id']);
|
||||
if (!$res){
|
||||
Log::getInstance("PatientOrderService-addPatientOrderPay")->error("再次发放优惠卷失败");
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// 此处异常不做处理
|
||||
Log::getInstance("PatientOrderService-addPatientOrderPay")->error($e->getMessage());
|
||||
}
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user