Merge branch 'dev'
This commit is contained in:
commit
bdd1af5bb3
103
app/Amqp/Consumer/CouponExpiredDelayDirectConsumer.php
Normal file
103
app/Amqp/Consumer/CouponExpiredDelayDirectConsumer.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Amqp\Producer\CouponExpiredDelayDirectProducer;
|
||||
use App\Model\Coupon;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
/**
|
||||
* 处理优惠卷过期
|
||||
*/
|
||||
#[Consumer(nums: 1)]
|
||||
class CouponExpiredDelayDirectConsumer extends ConsumerMessage
|
||||
{
|
||||
use ProducerDelayedMessageTrait;
|
||||
use ConsumerDelayedMessageTrait;
|
||||
|
||||
protected string $exchange = 'amqp.delay.direct';
|
||||
|
||||
protected ?string $queue = 'coupon.expired.delay.queue';
|
||||
|
||||
protected string $type = Type::DIRECT; //Type::FANOUT;
|
||||
|
||||
protected string|array $routingKey = 'CouponExpired';
|
||||
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
{
|
||||
Log::getInstance("queue-CouponExpired")->info("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// 检测参数
|
||||
if (!isset($data['coupon_id'])){
|
||||
Log::getInstance("queue-CouponExpired")->error("入参错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 获取优惠卷数据
|
||||
$params = array();
|
||||
$params['coupon_id'] = $data['coupon_id'];
|
||||
$coupon = Coupon::getOne($params);
|
||||
if (empty($coupon)){
|
||||
Log::getInstance("queue-CouponExpired")->info("错误优惠卷,无需处理");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 检测优惠卷状态
|
||||
if ($coupon['coupon_status'] != 1){
|
||||
Log::getInstance("queue-CouponExpired")->info("优惠卷非正常状态,无需处理");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 检测优惠卷过期时间
|
||||
if ($coupon['valid_type'] == 2){
|
||||
Log::getInstance("queue-CouponExpired")->info("优惠卷类型为相对时效,无需处理");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
$valid_end_time = strtotime($coupon['valid_end_time']);
|
||||
|
||||
try {
|
||||
// 处理未过期事件
|
||||
// 先删除-重新添加队列
|
||||
$time = $valid_end_time - time();
|
||||
if ($time > 0) {
|
||||
$queue_data = array();
|
||||
$queue_data['coupon_id'] = $coupon['coupon_id'];
|
||||
$message = new CouponExpiredDelayDirectProducer($queue_data);
|
||||
$message->setDelayMs(1000 * $time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Log::getInstance("queue-CouponExpired")->error("未到过期时间,重新添加队列失败");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 修改优惠卷
|
||||
$params = array();
|
||||
$params['coupon_id'] = $coupon['coupon_id'];
|
||||
|
||||
$data = array();
|
||||
$data['coupon_status'] = 3;
|
||||
Coupon::edit($params, $data);
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("queue-CouponExpired")->error($e->getMessage());
|
||||
return Result::REQUEUE; // 重回队列
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Model\Coupon;
|
||||
use App\Model\CouponGrant;
|
||||
use App\Services\CouponService;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
@ -17,7 +18,7 @@ use Hyperf\DbConnection\Db;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
/**
|
||||
* 再次发放用户优惠卷
|
||||
* 发放用户优惠卷
|
||||
*/
|
||||
#[Consumer(nums: 1)]
|
||||
class GrantUserCouponDelayDirectConsumer extends ConsumerMessage
|
||||
@ -37,20 +38,28 @@ class GrantUserCouponDelayDirectConsumer extends ConsumerMessage
|
||||
{
|
||||
Log::getInstance("queue-GrantUserCoupon")->info("开始执行 延迟发放用户优惠卷 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// 获取优惠卷数据
|
||||
$params = array();
|
||||
$params['coupon_id'] = $data["coupon_id"];
|
||||
$coupon = Coupon::getOne($params);
|
||||
if (empty($coupon)){
|
||||
Log::getInstance("queue-GrantUserCoupon")->error("无优惠卷数据");
|
||||
// 检测入参参数
|
||||
if (empty($data['coupon_id'])) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-GrantUserCoupon")->error("参数错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
if (empty($data['user_id'])) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-GrantUserCoupon")->error("参数错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
$grant_quantity = 1;
|
||||
if (!empty($data['grant_quantity'])) {
|
||||
$grant_quantity = $data['grant_quantity'];
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$couponService = new CouponService();
|
||||
$res = $couponService->GrantUserCoupon($data["coupon_id"],$data['user_id']);
|
||||
$res = $couponService->GrantUserCoupon($data["coupon_id"],$data['user_id'],$grant_quantity);
|
||||
if (!$res){
|
||||
// 发放失败
|
||||
Db::rollBack();
|
||||
|
||||
@ -77,11 +77,6 @@ class UserCouponExpiredDelayDirectConsumer extends ConsumerMessage
|
||||
// 先删除-重新添加队列
|
||||
$time = $valid_end_time - time();
|
||||
if ($time > 0){
|
||||
$time = $valid_end_time - time();
|
||||
if ($time <= 0){
|
||||
$time = 60 * 5;
|
||||
}
|
||||
|
||||
$queue_data = array();
|
||||
$queue_data['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||||
$message = new UserCouponExpiredDelayDirectProducer($queue_data);
|
||||
|
||||
27
app/Amqp/Producer/CouponExpiredDelayDirectProducer.php
Normal file
27
app/Amqp/Producer/CouponExpiredDelayDirectProducer.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Producer;
|
||||
|
||||
use Hyperf\Amqp\Annotation\Producer;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerMessage;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
|
||||
#[Producer]
|
||||
class CouponExpiredDelayDirectProducer extends ProducerMessage
|
||||
{
|
||||
use ProducerDelayedMessageTrait;
|
||||
|
||||
protected string $exchange = 'amqp.delay.direct';
|
||||
|
||||
protected string $type = Type::DIRECT;
|
||||
|
||||
protected string|array $routingKey = 'CouponExpired';
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->payload = $data;
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,7 @@ use Hyperf\Amqp\Message\ProducerMessage;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
|
||||
/**
|
||||
* 再次发放用户优惠卷
|
||||
* 发放用户优惠卷
|
||||
*/
|
||||
#[Producer]
|
||||
class GrantUserCouponDelayDirectProducer extends ProducerMessage
|
||||
|
||||
101
app/Command/AddCouponExpiredQueueCommand.php
Normal file
101
app/Command/AddCouponExpiredQueueCommand.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Amqp\Producer\CouponExpiredDelayDirectProducer;
|
||||
use App\Model\Coupon;
|
||||
use App\Model\UserCoupon;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
#[Command]
|
||||
class AddCouponExpiredQueueCommand extends HyperfCommand
|
||||
{
|
||||
public function __construct(protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct('AddCouponExpiredQueue');
|
||||
}
|
||||
|
||||
public function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
$this->setDescription('添加系统即将过期优惠卷添加至优惠卷过期队列');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$this->line('开始');
|
||||
|
||||
try {
|
||||
// 获取需执行的用户优惠卷
|
||||
$coupons = $this->getExecUserCoupon();
|
||||
if (empty($coupons)){
|
||||
$this->line("结束,无优惠卷可执行");
|
||||
return;
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
$this->line($e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($coupons as $coupon){
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 添加优惠卷过期队列
|
||||
$valid_end_time = strtotime($coupon['valid_end_time']);
|
||||
|
||||
$data = array();
|
||||
$data['coupon_id'] = $coupon['coupon_id'];
|
||||
|
||||
$time = $valid_end_time - time();
|
||||
if ($time < 0){
|
||||
$time = 60 * 5;
|
||||
}
|
||||
|
||||
$message = new CouponExpiredDelayDirectProducer($data);
|
||||
$message->setDelayMs(1000 * $time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
$this->line("添加队列失败");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
}catch (\Throwable $e){
|
||||
// 修改优惠卷执行失败
|
||||
Db::rollBack();
|
||||
$this->line($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需执行的优惠卷
|
||||
* @return array
|
||||
*/
|
||||
public function getExecUserCoupon(): array
|
||||
{
|
||||
// 过期使用时间
|
||||
$valid_end_time_1 = date('Y-m-d 00:00:00',time());
|
||||
$valid_end_time_2 = date('Y-m-d 23:59:59',time());
|
||||
$valid_end_time = [$valid_end_time_1,$valid_end_time_2];
|
||||
|
||||
$params = array();
|
||||
$params['coupon_status'] = 1;
|
||||
$params['valid_type'] = 1;
|
||||
|
||||
$coupons = Coupon::getTodayExpiredCoupon($params,$valid_end_time);
|
||||
if (empty($coupons)){
|
||||
return [];
|
||||
}
|
||||
|
||||
return $coupons->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,7 +27,7 @@ class AddUserCouponExpiredQueueCommand extends HyperfCommand
|
||||
public function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
$this->setDescription('添加即将过期优惠卷添加至优惠卷过期队列');
|
||||
$this->setDescription('添加用户即将过期优惠卷添加至优惠卷过期队列');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
|
||||
@ -509,41 +509,10 @@ class CallBackController extends AbstractController
|
||||
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("CallBack-wxPayProductSuccess")->error("再次发放优惠卷失败");
|
||||
}
|
||||
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->info("再次发放优惠卷成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$couponService = new CouponService();
|
||||
$res = $couponService->againGrantOrderCoupon($order_product['order_id']);
|
||||
if (!$res){
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("再次发放优惠卷失败");
|
||||
}
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
|
||||
@ -123,4 +123,29 @@ class Coupon extends Model
|
||||
->whereIn("distribution_object",[7])
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日过期优惠卷
|
||||
* @param array $params
|
||||
* @param array $valid_end_time
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getTodayExpiredCoupon(array $params,array $valid_end_time,array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)
|
||||
->whereBetween('valid_end_time', $valid_end_time)
|
||||
->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
}
|
||||
|
||||
93
app/Model/CouponGrant.php
Normal file
93
app/Model/CouponGrant.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
|
||||
/**
|
||||
* @property int $grant_id 主键id
|
||||
* @property int $coupon_id 优惠卷id
|
||||
* @property int $grant_type 发放类型(1:具体用户 2:未拥有用户)
|
||||
* @property int $user_id 用户id(发放类型为具体用户时存在)
|
||||
* @property int $total_quantity 目标发放数量
|
||||
* @property int $grant_quantity 已发放数量
|
||||
* @property int $grant_result 发放结果(1:成功 2:发放中 3:失败)
|
||||
* @property string $stop_reason 停止原因
|
||||
* @property int $admin_user_id 后台操作用户id
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class CouponGrant extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'coupon_grant';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['grant_id', 'coupon_id', 'grant_type', 'user_id', 'total_quantity', 'grant_quantity', 'grant_result', 'stop_reason', 'admin_user_id', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "grant_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增-批量
|
||||
* @param array $data 新增数据
|
||||
* @return \Hyperf\Database\Model\Model|CouponGrant
|
||||
*/
|
||||
public static function addCouponGrant(array $data): \Hyperf\Database\Model\Model|CouponGrant
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改-批量
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function editCouponGrant(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自增
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@ -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,20 +50,26 @@ class CouponService extends BaseService
|
||||
|
||||
// 判断优惠卷数量是否充足
|
||||
if ($coupon['coupon_count'] <= $coupon['coupon_take_count']){
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断用户是否已有该优惠卷
|
||||
$params = array();
|
||||
$params['user_id'] = $user_id;
|
||||
$params['coupon_id'] = $coupon['coupon_id'];
|
||||
$user_coupon = UserCoupon::getOne($params);
|
||||
if (!empty($user_coupon)){
|
||||
if ($user_coupon['user_coupon_status'] == 0){
|
||||
return true;
|
||||
}
|
||||
// 优惠卷剩余数量
|
||||
$remaining_quantity = $coupon['coupon_count'] - $coupon['coupon_take_count'];
|
||||
if ($remaining_quantity <= $grant_quantity){
|
||||
return false;
|
||||
}
|
||||
|
||||
// // 判断用户是否已有该优惠卷
|
||||
// $params = array();
|
||||
// $params['user_id'] = $user_id;
|
||||
// $params['coupon_id'] = $coupon['coupon_id'];
|
||||
// $user_coupon = UserCoupon::getOne($params);
|
||||
// if (!empty($user_coupon)){
|
||||
// if ($user_coupon['user_coupon_status'] == 0){
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 判断该优惠卷状态
|
||||
if ($coupon['coupon_status'] != 1){
|
||||
// 优惠卷状态异常
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -122,7 +122,7 @@ class DoctorAuthService extends BaseService
|
||||
// 网易易盾认证
|
||||
// 实人认证-生产环境开启
|
||||
$app_env = config('app_env','dev');
|
||||
if ($app_env == "dev"){
|
||||
if ($app_env != "dev"){
|
||||
$IdCard = new IdCard();
|
||||
|
||||
$params = array();
|
||||
|
||||
@ -175,7 +175,7 @@ class PatientFamilyService extends BaseService
|
||||
|
||||
// 实人认证-生产环境开启
|
||||
$app_env = config('app_env', 'dev');
|
||||
if ($app_env == "dev") {
|
||||
if ($app_env != "dev") {
|
||||
$IdCard = new IdCard();
|
||||
|
||||
$params = array();
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user