新增药品订单退款

This commit is contained in:
2023-04-11 18:02:31 +08:00
parent 3e577c8cac
commit 532c9f909f
5 changed files with 168 additions and 8 deletions
+20 -2
View File
@@ -6,13 +6,17 @@ namespace App\Command;
use App\Model\OrderProduct;
use App\Services\OrderPrescriptionService;
use App\Services\OrderProductService;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Hyperf\DbConnection\Db;
use Hyperf\Redis\Redis;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* 上报处方平台商品订单
* 商品订单上报处方平台
* 此处单商品订单上报两次
*/
#[Command]
@@ -29,6 +33,10 @@ class ReportPreProductOrderCommand extends HyperfCommand
$this->setDescription('上报处方平台商品订单');
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle()
{
$this->line("上报处方平台商品订单开始");
@@ -48,14 +56,21 @@ class ReportPreProductOrderCommand extends HyperfCommand
}
foreach ($order_product_ids as $item){
Db::beginTransaction();
$redis_key = "ReportPreProductOrder" . $item['order_product_id'];
try {
$redis_value = $redis->get($redis_key);
if(!empty($redis_value)){
// 超出最大执行次数
if ($redis_value > 2){
// 超出最大执行次数
// 存储上报失败
$this->savaReportFail($item['order_product_id']);
// 退款
$OrderProductService = new OrderProductService();
$OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款");
}
}
@@ -68,7 +83,10 @@ class ReportPreProductOrderCommand extends HyperfCommand
// 清空缓存
$redis->del($redis_key);
Db::commit();
} catch (\Exception $e) {
Db::rollBack();
// 记录失败次数
$redis->incr($redis_key);
$this->line("上报处方平台商品订单失败:" . $e->getMessage());