新增im清除会话接口,新增定时商品订单上报处方平台
This commit is contained in:
parent
179977ec26
commit
3e577c8cac
142
app/Command/ReportPreProductOrderCommand.php
Normal file
142
app/Command/ReportPreProductOrderCommand.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\OrderProduct;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
use Hyperf\Redis\Redis;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* 上报处方平台商品订单
|
||||
* 此处单商品订单上报两次
|
||||
*/
|
||||
#[Command]
|
||||
class ReportPreProductOrderCommand extends HyperfCommand
|
||||
{
|
||||
public function __construct(protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct('ReportPreProductOrder:command');
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setDescription('上报处方平台商品订单');
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->line("上报处方平台商品订单开始");
|
||||
|
||||
try {
|
||||
$order_product_ids = $this->getExecProductOrder();
|
||||
if (empty($order_product_ids)){
|
||||
$this->line("上报处方平台商品订单结束,无可上报的商品订单");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取缓存
|
||||
$redis = $this->container->get(Redis::class);
|
||||
} catch (\Exception $e) {
|
||||
$this->line("上报处方平台商品订单失败:" . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($order_product_ids as $item){
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
||||
// 上报处方平台
|
||||
$orderPrescriptionService = new OrderPrescriptionService();
|
||||
$orderPrescriptionService->reportPrescription($item['order_product_id']);
|
||||
|
||||
// 存储上报成功
|
||||
$this->savaReportSuccess($item['order_product_id']);
|
||||
|
||||
// 清空缓存
|
||||
$redis->del($redis_key);
|
||||
} catch (\Exception $e) {
|
||||
// 记录失败次数
|
||||
$redis->incr($redis_key);
|
||||
$this->line("上报处方平台商品订单失败:" . $e->getMessage());
|
||||
$this->savaReportFail($item['order_product_id'],$e->getMessage());
|
||||
}
|
||||
|
||||
$this->line("商品订单上报处方平台成功:商品单号" . $item['order_product_id']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可上报商品订单
|
||||
* @return array
|
||||
*/
|
||||
protected function getExecProductOrder(): array
|
||||
{
|
||||
$params = array();
|
||||
$params['order_product_status'] = 2; // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$params['pay_status'] = 2; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$params['refund_status'] = 0; // 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
$params['report_pre_status'] = 0; // 上报处方平台状态(0:未上报 1:已上报 2:上报失败))
|
||||
|
||||
$fields = [
|
||||
'order_product_id',
|
||||
];
|
||||
|
||||
$order_product = OrderProduct::getList($params,$fields);
|
||||
if (empty($order_product)){
|
||||
return [];
|
||||
}
|
||||
|
||||
return $order_product->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储上报失败
|
||||
* @param string $order_product_id 商品订单id
|
||||
* @param string $report_pre_fail_reason 上报失败原因
|
||||
* @return void
|
||||
*/
|
||||
protected function savaReportFail(string $order_product_id,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_time'] = date('Y-m-d H:i:s',time()); // 上报处方平台时间
|
||||
$data['report_pre_fail_reason'] = ""; // 上报失败原因 置为空
|
||||
OrderProduct::edit($params,$data);
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,16 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
try {
|
||||
// 获取需执行订单数据
|
||||
$params = array();
|
||||
$params['order_product_status'] = "";
|
||||
$params['order_product_status'] = 2; // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$params['pay_status'] = 2;
|
||||
$params['refund_status'] = 0;
|
||||
|
||||
$field = [
|
||||
'order_product_id',
|
||||
'order_inquiry_id',
|
||||
'order_inquiry_id',
|
||||
];
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->line("获取处方平台订单状态失败:" . $e->getMessage());
|
||||
|
||||
@ -11,6 +11,7 @@ use App\Model\MessageIm;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCoupon;
|
||||
use App\Model\OrderInquiryRefund;
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\OrderProductRefund;
|
||||
@ -22,6 +23,7 @@ use App\Model\UserPatient;
|
||||
use App\Services\BaseService;
|
||||
use App\Services\ImService;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Utils\Log;
|
||||
use Extend\TencentIm\Account;
|
||||
use Extend\TencentIm\Message;
|
||||
@ -416,8 +418,7 @@ class CallBackController extends AbstractController
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("药品微信支付回调数据验证成功");
|
||||
|
||||
Log::getInstance()->error("药品微信支付回调数据处理成功");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ use Extend\Alibaba\Oss;
|
||||
use Extend\Ca\Ca;
|
||||
use Extend\Prescription\Prescription;
|
||||
use Extend\RegulatoryPlatform\regulatoryPlatform;
|
||||
use Extend\TencentIm\RecentContact;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Utils\ApplicationContext;
|
||||
@ -753,6 +754,10 @@ class TestController extends AbstractController
|
||||
}
|
||||
|
||||
public function test_13(){
|
||||
// $RecentContact = new RecentContact();
|
||||
// $RecentContact->deleteRecentContact();
|
||||
// die;
|
||||
|
||||
$out_trade_no = $this->request->input('out_trade_no');
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $out_trade_no;
|
||||
@ -766,4 +771,5 @@ class TestController extends AbstractController
|
||||
$inquiryService->inquiryRefund($out_trade_no, "取消问诊");
|
||||
return success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -35,6 +35,9 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property int $refund_status 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
* @property string $cancel_time 订单取消时间
|
||||
* @property string $cancel_remarks 订单取消备注(自动添加)
|
||||
* @property int $report_pre_status 上报处方平台状态(0:未上报 1:已上报 2:上报失败))
|
||||
* @property string $report_pre_time 上报处方平台时间
|
||||
* @property string $report_pre_fail_reason 上报失败原因
|
||||
* @property int $province_id 省份id
|
||||
* @property string $province 省份
|
||||
* @property int $city_id 城市id
|
||||
@ -66,7 +69,7 @@ class OrderProduct extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
|
||||
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_product_id";
|
||||
|
||||
@ -191,7 +194,6 @@ class OrderProduct extends Model
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 患者用药记录查询
|
||||
* @param array $params
|
||||
|
||||
@ -4,6 +4,8 @@ namespace App\Services;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\PatientFamily;
|
||||
use App\Model\Product;
|
||||
use App\Model\UserCaCert;
|
||||
@ -569,9 +571,45 @@ class OrderPrescriptionService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
// 上报处方平台
|
||||
public function reportPrescription(array $order_inquiry, array $order_prescription, array $order_prescription_product, array $order_product): array
|
||||
/**
|
||||
* 上报处方平台
|
||||
* @param string $order_product_id 商品订单id
|
||||
* @return bool
|
||||
*/
|
||||
public function reportPrescription(string $order_product_id): bool
|
||||
{
|
||||
// 获取商品订单数据
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)) {
|
||||
throw new BusinessException("上报处方平台失败:商品订单数据错误");
|
||||
}
|
||||
|
||||
// 获取处方数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_product['order_prescription_id'];
|
||||
$order_prescription = OrderPrescription::getOne($params);
|
||||
if (empty($order_prescription)) {
|
||||
throw new BusinessException("上报处方平台失败:处方数据错误");
|
||||
}
|
||||
|
||||
// 获取问诊订单数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
throw new BusinessException("上报处方平台失败:问诊订单数据错误");
|
||||
}
|
||||
|
||||
// 获取商品订单列表数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||||
$order_product_item = OrderProductItem::getList($params);
|
||||
if (empty($order_product_item)) {
|
||||
throw new BusinessException("上报处方平台失败:商品订单列表数据错误");
|
||||
}
|
||||
|
||||
$wg = new WaitGroup();
|
||||
$wg->add(8);
|
||||
|
||||
@ -584,8 +622,13 @@ class OrderPrescriptionService extends BaseService
|
||||
$user_pharmacist_info = []; // 药师详数据
|
||||
$order_inquiry_case = []; // 病例数据
|
||||
|
||||
// 获取就诊患者用户数据
|
||||
$user_id = $order_inquiry['user_id'];
|
||||
$doctor_id = $order_prescription['doctor_id'];
|
||||
$family_id = $order_inquiry['family_id'];
|
||||
$pharmacist_id = $order_prescription['pharmacist_id'];
|
||||
$order_inquiry_id = $order_inquiry['order_inquiry_id'];
|
||||
|
||||
// 获取就诊患者用户数据
|
||||
co(function () use ($wg, &$user, $user_id) {
|
||||
$params = array();
|
||||
$params['user_id'] = $user_id;
|
||||
@ -595,7 +638,6 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取家庭成员-基本信息
|
||||
$family_id = $order_inquiry['family_id'];
|
||||
co(function () use ($wg, &$patient_family, $family_id) {
|
||||
$params = array();
|
||||
$params['family_id'] = $family_id;
|
||||
@ -617,7 +659,6 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取医生数据
|
||||
$doctor_id = $order_prescription['doctor_id'];
|
||||
co(function () use ($wg, &$user_doctor, $doctor_id) {
|
||||
$params = array();
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
@ -628,7 +669,6 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取医生详情数据
|
||||
$doctor_id = $order_prescription['doctor_id'];
|
||||
co(function () use ($wg, &$user_doctor_info, $doctor_id) {
|
||||
$params = array();
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
@ -639,7 +679,6 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取药师数据
|
||||
$pharmacist_id = $order_prescription['pharmacist_id'];
|
||||
co(function () use ($wg, &$user_pharmacist, $pharmacist_id) {
|
||||
$params = array();
|
||||
$params['pharmacist_id'] = $pharmacist_id;
|
||||
@ -650,7 +689,6 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取药师详情数据
|
||||
$pharmacist_id = $order_prescription['pharmacist_id'];
|
||||
co(function () use ($wg, &$user_pharmacist_info, $pharmacist_id) {
|
||||
$params = array();
|
||||
$params['pharmacist_id'] = $pharmacist_id;
|
||||
@ -661,7 +699,6 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取病例数据
|
||||
$order_inquiry_id = $order_inquiry['order_inquiry_id'];
|
||||
co(function () use ($wg, &$order_inquiry_case, $order_inquiry_id) {
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
@ -764,11 +801,11 @@ class OrderPrescriptionService extends BaseService
|
||||
$arg['presList'][0]['allergicHistory'] = $order_inquiry_case['allergy_history'] ?: "无"; // 过敏史
|
||||
|
||||
// 药品数据
|
||||
foreach ($order_prescription_product as $key => $item) {
|
||||
foreach ($order_product_item as $key => $item) {
|
||||
// 获取商品数据
|
||||
$pamras = array();
|
||||
$pamras['product_id'] = $item['product_id'];
|
||||
$product = Product::getOne($pamras);
|
||||
$params = array();
|
||||
$params['product_id'] = $item['product_id'];
|
||||
$product = Product::getOne($params);
|
||||
if (empty($product)) {
|
||||
throw new BusinessException("药品数据错误");
|
||||
}
|
||||
@ -778,7 +815,7 @@ class OrderPrescriptionService extends BaseService
|
||||
$arg['presList'][0]['drugList'][$key]['drugName'] = $product['product_name']; // 药品名称
|
||||
$arg['presList'][0]['drugList'][$key]['specifications'] = $product['product_spec']; // 药品规格
|
||||
$arg['presList'][0]['drugList'][$key]['price'] = $product['product_price']; // 药品单价
|
||||
$arg['presList'][0]['drugList'][$key]['packingCount'] = $item['prescription_product_num']; // 药品数量
|
||||
$arg['presList'][0]['drugList'][$key]['packingCount'] = $item['amount']; // 药品数量
|
||||
$arg['presList'][0]['drugList'][$key]['surplusPackingCount'] = 0; // 处方药品剩余使用数量
|
||||
$arg['presList'][0]['drugList'][$key]['packingUnit'] = $product['packaging_unit']; // 药品单位
|
||||
$arg['presList'][0]['drugList'][$key]['singleDosage'] = 1; // 单次用量
|
||||
@ -792,29 +829,23 @@ class OrderPrescriptionService extends BaseService
|
||||
$arg['presList'][0]['orderDrugList'][$key]['drugName'] = $product['product_name']; // 药品名称
|
||||
$arg['presList'][0]['orderDrugList'][$key]['specifications'] = $product['product_spec']; // 药品规格
|
||||
$arg['presList'][0]['orderDrugList'][$key]['price'] = $product['product_price']; // 药品单价
|
||||
$arg['presList'][0]['orderDrugList'][$key]['drugCount'] = $item['prescription_product_num']; // 药品数量
|
||||
$arg['presList'][0]['orderDrugList'][$key]['drugCount'] = $item['amount']; // 药品数量
|
||||
$arg['presList'][0]['orderDrugList'][$key]['packingUnit'] = $product['packaging_unit']; // 药品单位
|
||||
}
|
||||
|
||||
Log::getInstance()->info(json_encode($arg,JSON_UNESCAPED_UNICODE));
|
||||
dump($arg);
|
||||
$Prescription = new Prescription();
|
||||
$result = $Prescription->reportPrescription($arg);
|
||||
dump($result);
|
||||
if ($result['resultCode'] != "1000"){
|
||||
if ($result['resultCode'] == "1008"){
|
||||
// 没有相关药品或库存不足
|
||||
|
||||
}
|
||||
if(!empty($result['resultDesc'])){
|
||||
throw new BusinessException($result['resultDesc']);
|
||||
Log::getInstance()->info("上报处方平台失败:" , $result['resultDesc']);
|
||||
return false;
|
||||
}
|
||||
throw new BusinessException("上报处方平台失败");
|
||||
|
||||
Log::getInstance()->info("上报处方平台失败:操作编码:" , $result['resultCode']);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $arg;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -4,6 +4,7 @@ namespace Extend\Prescription;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Utils\Log;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@ -273,6 +274,7 @@ class Prescription
|
||||
// 返回值为空
|
||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
Log::getInstance()->info("处方平台请求结果:",$body);
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
@ -23,4 +23,19 @@ class RecentContact extends Base
|
||||
$result = $this->postRequest($path,$options);
|
||||
dump($result);die;
|
||||
}
|
||||
|
||||
// 清楚会话
|
||||
public function deleteRecentContact(){
|
||||
$options = [
|
||||
"json"=> [
|
||||
"From_Account"=>"497444475121803265",
|
||||
"Type"=> 1,
|
||||
// "To_Account"=>"502418068290932736",
|
||||
"ClearRamble"=> 1,
|
||||
]
|
||||
];
|
||||
|
||||
$path = $this->config['base_url'] . "v4/recentcontact/delete?" . $this->buildRequestParams();
|
||||
$result = $this->postRequest($path,$options);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user