去除获取处方平台状态退款消息推送(回调会推)。
This commit is contained in:
@@ -4,11 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\UserPatient;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Services\OrderProductService;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
use Hyperf\DbConnection\Db;
|
||||
@@ -41,20 +43,20 @@ class ReportPreProductOrderCommand extends HyperfCommand
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->line("上报处方平台商品订单开始");
|
||||
$this->line("开始");
|
||||
|
||||
try {
|
||||
// 获取可上报商品订单
|
||||
$order_product_ids = $this->getExecProductOrder();
|
||||
if (empty($order_product_ids)){
|
||||
$this->line("上报处方平台商品订单结束,无可上报的商品订单");
|
||||
$this->line("结束,无可上报的商品订单");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取缓存
|
||||
$redis = $this->container->get(Redis::class);
|
||||
} catch (\Exception $e) {
|
||||
$this->line("上报处方平台商品订单失败:" . $e->getMessage());
|
||||
$this->line("错误:" . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,62 +65,50 @@ class ReportPreProductOrderCommand extends HyperfCommand
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
$redis_key = "ReportPreProductOrder" . $item['order_product_id'];
|
||||
|
||||
// 处理超出最大执行次数/退款问题
|
||||
try {
|
||||
$redis_value = $redis->get($redis_key);
|
||||
$redis->incr($redis_key);
|
||||
if(!empty($redis_value)){
|
||||
if ($redis_value >= 2){
|
||||
// 存储上报失败
|
||||
$this->savaReportFail($item['order_product_id'],"超出最大上报次数");
|
||||
// 检测执行次数
|
||||
$res = $this->checkHandleNumber($item['order_product_id']);
|
||||
if (!$res) {
|
||||
Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:超出最大执行次数或检测错误");
|
||||
|
||||
// 修改失败时药品订单数据
|
||||
$this->savePreFailedOrderStatus($item['order_product_id'],"复核失败");
|
||||
// 修改药品订单表上报处方平台状态
|
||||
$this->saveOrderProductPeportPreStatus($item['order_product_id'],2,"超出最大上报次数");
|
||||
|
||||
// 退款
|
||||
$this->line("超出最大执行次数,执行退款");
|
||||
$OrderProductService = new OrderProductService();
|
||||
$OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款");
|
||||
// 修改失败时药品订单数据
|
||||
$this->savePreFailedOrderStatus($item['order_product_id'],"复核失败");
|
||||
|
||||
// 清空缓存
|
||||
$redis->del($redis_key);
|
||||
// 退款
|
||||
$OrderProductService = new OrderProductService();
|
||||
$OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款");
|
||||
|
||||
Db::commit();
|
||||
continue;
|
||||
}
|
||||
Db::commit();
|
||||
continue;
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
}catch(\Exception $e){
|
||||
Db::rollBack();
|
||||
// 记录失败次数
|
||||
$this->line("商品订单上报处方平台失败:失败原因" . $e->getMessage());
|
||||
$this->line("错误:" . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 处理上报处方平台问题
|
||||
try {
|
||||
// 上报处方平台
|
||||
$orderPrescriptionService = new OrderPrescriptionService();
|
||||
$orderPrescriptionService->reportPrescription($item['order_product_id']);
|
||||
|
||||
// 存储上报成功
|
||||
$this->savaReportSuccess($item['order_product_id']);
|
||||
// 修改药品订单表上报处方平台状态
|
||||
$this->saveOrderProductPeportPreStatus($item['order_product_id'],1);
|
||||
|
||||
// 清空缓存
|
||||
$redis->del($redis_key);
|
||||
|
||||
$this->line("商品订单上报处方平台成功");
|
||||
$this->line("成功");
|
||||
Db::commit();
|
||||
continue;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
$this->line("上报失败:失败原因" . $e->getMessage());
|
||||
$this->line("错误" . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$this->line("商品订单上报处方平台全部结束");
|
||||
$this->line("全部结束");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +125,9 @@ class ReportPreProductOrderCommand extends HyperfCommand
|
||||
|
||||
$fields = [
|
||||
'order_product_id',
|
||||
'user_id',
|
||||
'patient_id',
|
||||
'order_prescription_id',
|
||||
];
|
||||
|
||||
$order_product = OrderProduct::getList($params,$fields);
|
||||
@@ -147,38 +139,24 @@ class ReportPreProductOrderCommand extends HyperfCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储上报失败
|
||||
* @param string $order_product_id 商品订单id
|
||||
* @param string $report_pre_fail_reason 上报失败原因
|
||||
* 修改药品订单表上报处方平台状态
|
||||
* @param string $order_product_id
|
||||
* @param int $report_pre_status
|
||||
* @param string $report_pre_fail_reason
|
||||
* @return void
|
||||
*/
|
||||
protected function savaReportFail(string $order_product_id,string $report_pre_fail_reason = ""): void
|
||||
protected function saveOrderProductPeportPreStatus(string $order_product_id,int $report_pre_status,string $report_pre_fail_reason = ""): void
|
||||
{
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
|
||||
$data = array();
|
||||
$data['report_pre_status'] = 2; // 上报处方平台状态(0:未上报 1:已上报 2:上报失败))
|
||||
if (!empty($report_pre_fail_reason)){
|
||||
$data['report_pre_fail_reason'] = $report_pre_fail_reason;
|
||||
}
|
||||
OrderProduct::edit($params,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储上报成功
|
||||
* @param string $order_product_id 商品订单id
|
||||
* @return void
|
||||
*/
|
||||
protected function savaReportSuccess(string $order_product_id): void
|
||||
{
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
|
||||
$data = array();
|
||||
$data['report_pre_status'] = 1; // 上报处方平台状态(0:未上报 1:已上报 2:上报失败))
|
||||
$data['report_pre_status'] = $report_pre_status; // 上报处方平台状态(0:未上报 1:已上报 2:上报失败))
|
||||
$data['report_pre_time'] = date('Y-m-d H:i:s',time()); // 上报处方平台时间
|
||||
$data['report_pre_fail_reason'] = ""; // 上报失败原因 置为空
|
||||
if (!empty($report_pre_fail_reason)){
|
||||
$data['report_pre_fail_reason'] = ""; // 上报失败原因 置为空
|
||||
}
|
||||
|
||||
OrderProduct::edit($params,$data);
|
||||
}
|
||||
|
||||
@@ -200,4 +178,37 @@ class ReportPreProductOrderCommand extends HyperfCommand
|
||||
OrderProduct::edit($params,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测执行次数
|
||||
* @param string $order_product_id
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function checkHandleNumber(string $order_product_id): bool
|
||||
{
|
||||
try {
|
||||
$redis = $this->container->get(Redis::class);
|
||||
|
||||
$redis_key = "ReportPreProductOrder" . $order_product_id;
|
||||
$redis_value = $redis->get($redis_key);
|
||||
if (empty($redis_value)) {
|
||||
$redis->set($redis_key, 1, 60 * 60 * 24 * 5);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 执行次数过多
|
||||
if ($redis_value > 3) {
|
||||
// 加入短信队列,通知管理员
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$redis->incr($redis_key);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user