上报药品订单时,增加了药品实际金额
This commit is contained in:
parent
8afd0d91ed
commit
8443af52ee
@ -6,6 +6,8 @@ namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Relations\HasOne;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
@ -14,8 +16,8 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property int $user_coupon_id 用户优惠卷表id
|
||||
* @property string $coupon_name 优惠卷名称
|
||||
* @property string $coupon_use_price 优惠卷使用金额
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class OrderProductCoupon extends Model
|
||||
{
|
||||
@ -33,6 +35,14 @@ class OrderProductCoupon extends Model
|
||||
|
||||
protected string $primaryKey = "order_coupon_id";
|
||||
|
||||
/**
|
||||
* 关联优惠券表
|
||||
*/
|
||||
public function UserCoupon(): HasOne
|
||||
{
|
||||
return $this->hasOne(Coupon::class, 'user_coupon_id', 'user_coupon_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
|
||||
@ -41,7 +41,7 @@ class UserCoupon extends Model
|
||||
protected string $primaryKey = "user_coupon_id";
|
||||
|
||||
/**
|
||||
* 关联医院表
|
||||
* 关联优惠券表
|
||||
*/
|
||||
public function Coupon(): HasOne
|
||||
{
|
||||
|
||||
@ -4,9 +4,11 @@ namespace App\Services;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\Coupon;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderPrescriptionFile;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductCoupon;
|
||||
use App\Model\PatientFamily;
|
||||
use App\Model\Product;
|
||||
use App\Model\UserCaCert;
|
||||
@ -17,6 +19,7 @@ use App\Model\OrderPrescriptionIcd;
|
||||
use App\Model\OrderPrescriptionProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\User;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserDoctorInfo;
|
||||
use App\Model\UserPharmacist;
|
||||
@ -28,11 +31,12 @@ use Extend\Ca\CaOffline;
|
||||
use Extend\Ca\CaOnline;
|
||||
use Extend\Prescription\Prescription;
|
||||
use Hyperf\Contract\LengthAwarePaginatorInterface;
|
||||
use Hyperf\Utils\WaitGroup;
|
||||
use \Hyperf\Coroutine\WaitGroup;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Swoole\Coroutine\Channel;
|
||||
use TCPDF;
|
||||
use Hyperf\Coroutine;
|
||||
|
||||
class OrderPrescriptionService extends BaseService
|
||||
{
|
||||
@ -214,7 +218,7 @@ class OrderPrescriptionService extends BaseService
|
||||
}
|
||||
|
||||
$wg = new WaitGroup();
|
||||
$wg->add(8);
|
||||
$wg->add(9);
|
||||
|
||||
$user = []; // 就诊患者用户数据
|
||||
$patient_family = []; // 家庭成员-基本信息
|
||||
@ -224,15 +228,17 @@ class OrderPrescriptionService extends BaseService
|
||||
$user_pharmacist = []; // 药师数据
|
||||
$user_pharmacist_info = []; // 药师详数据
|
||||
$order_inquiry_case = []; // 病例数据
|
||||
$product_coupons = []; // 药品优惠券数据
|
||||
|
||||
$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'];
|
||||
$order_product_id = $order_product['order_product_id'];
|
||||
|
||||
// 获取就诊患者用户数据
|
||||
co(function () use ($wg, &$user, $user_id) {
|
||||
Coroutine\co(function () use ($wg, &$user, $user_id) {
|
||||
$params = array();
|
||||
$params['user_id'] = $user_id;
|
||||
$user = User::getOne($params)->toArray();
|
||||
@ -241,7 +247,7 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取家庭成员-基本信息
|
||||
co(function () use ($wg, &$patient_family, $family_id) {
|
||||
Coroutine\co(function () use ($wg, &$patient_family, $family_id) {
|
||||
$params = array();
|
||||
$params['family_id'] = $family_id;
|
||||
$patient_family = PatientFamily::getOne($params);
|
||||
@ -252,7 +258,7 @@ class OrderPrescriptionService extends BaseService
|
||||
|
||||
// 获取处方关联疾病数据
|
||||
$order_prescription_id = $order_prescription['order_prescription_id'];
|
||||
co(function () use ($wg, &$order_prescription_icd, $order_prescription_id) {
|
||||
Coroutine\co(function () use ($wg, &$order_prescription_icd, $order_prescription_id) {
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription_id;
|
||||
$order_prescription_icd = OrderPrescriptionIcd::getList($params);
|
||||
@ -262,7 +268,7 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取医生数据
|
||||
co(function () use ($wg, &$user_doctor, $doctor_id) {
|
||||
Coroutine\co(function () use ($wg, &$user_doctor, $doctor_id) {
|
||||
$params = array();
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
@ -272,7 +278,7 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取医生详情数据
|
||||
co(function () use ($wg, &$user_doctor_info, $doctor_id) {
|
||||
Coroutine\co(function () use ($wg, &$user_doctor_info, $doctor_id) {
|
||||
$params = array();
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
$user_doctor_info = UserDoctorInfo::getOne($params);
|
||||
@ -282,7 +288,7 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取药师数据
|
||||
co(function () use ($wg, &$user_pharmacist, $pharmacist_id) {
|
||||
Coroutine\co(function () use ($wg, &$user_pharmacist, $pharmacist_id) {
|
||||
$params = array();
|
||||
$params['pharmacist_id'] = $pharmacist_id;
|
||||
$user_pharmacist = UserPharmacist::getOne($params);
|
||||
@ -292,7 +298,7 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取药师详情数据
|
||||
co(function () use ($wg, &$user_pharmacist_info, $pharmacist_id) {
|
||||
Coroutine\co(function () use ($wg, &$user_pharmacist_info, $pharmacist_id) {
|
||||
$params = array();
|
||||
$params['pharmacist_id'] = $pharmacist_id;
|
||||
$user_pharmacist_info = UserPharmacistInfo::getOne($params);
|
||||
@ -302,7 +308,7 @@ class OrderPrescriptionService extends BaseService
|
||||
});
|
||||
|
||||
// 获取病例数据
|
||||
co(function () use ($wg, &$order_inquiry_case, $order_inquiry_id) {
|
||||
Coroutine\co(function () use ($wg, &$order_inquiry_case, $order_inquiry_id) {
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['status'] = 1;
|
||||
@ -312,6 +318,29 @@ class OrderPrescriptionService extends BaseService
|
||||
$wg->done();
|
||||
});
|
||||
|
||||
// 获取药品订单优惠券数据
|
||||
Coroutine\co(function () use ($wg, &$product_coupons, $order_product_id) {
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
$order_product_coupons = OrderProductCoupon::getList($params);
|
||||
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)){
|
||||
$product_coupons = array_push($product_coupons,$coupon->toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计数器减一
|
||||
$wg->done();
|
||||
});
|
||||
|
||||
$wg->wait();
|
||||
|
||||
if (empty($user)) {
|
||||
@ -438,8 +467,12 @@ class OrderPrescriptionService extends BaseService
|
||||
$arg['presList'][0]['orderDrugList'][$key]['price'] = $product['product_price']; // 药品单价
|
||||
$arg['presList'][0]['orderDrugList'][$key]['drugCount'] = $item['amount']; // 药品数量
|
||||
$arg['presList'][0]['orderDrugList'][$key]['packingUnit'] = $product['packaging_unit']; // 药品单位
|
||||
$arg['presList'][0]['orderDrugList'][$key]['actualSellingPrice'] = $product['actual_product_price']; // 药品实际销售单价
|
||||
}
|
||||
|
||||
// 处理上报处方平台药品优惠券相关数据
|
||||
$arg['promotion'] = $this->handleReportPrescriptionProductCouponData($product_coupons,$order_product_item,$order_product['order_product_no']);
|
||||
|
||||
$Prescription = new Prescription();
|
||||
$result = $Prescription->reportPrescription($arg);
|
||||
if ($result['resultCode'] != "1000"){
|
||||
@ -489,4 +522,50 @@ class OrderPrescriptionService extends BaseService
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理上报处方平台药品优惠券相关数据
|
||||
* @param array $product_coupons 药品订单优惠券,为coupon数据
|
||||
* @param array $order_product_item 药品订单明细
|
||||
* @param string $orderNo 药品订单编号
|
||||
* @return array
|
||||
*/
|
||||
public function handleReportPrescriptionProductCouponData(array $product_coupons,array $order_product_item,string $orderNo): array
|
||||
{
|
||||
$promotion = array();
|
||||
|
||||
if (empty($product_coupons)){
|
||||
return $promotion;
|
||||
}
|
||||
|
||||
foreach ($product_coupons as $product_coupon){
|
||||
// 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)
|
||||
if ($product_coupon["application_scope"] == 1 || $product_coupon["application_scope"] == 6){
|
||||
$result = array();
|
||||
$result["type"] = "orderCoupons";
|
||||
$result["objectId"] = $orderNo;
|
||||
$result["amount"] = $product_coupon["coupon_price"]; // 优惠金额
|
||||
$result["count"] = 1;
|
||||
|
||||
$promotion = array_push($promotion,$result);
|
||||
}
|
||||
|
||||
if ($product_coupon["application_scope"] == 5){
|
||||
$product_ids = explode(',',$product_coupon['product_id']);
|
||||
foreach ($order_product_item as $value){
|
||||
if (in_array($value['product_id'],$product_ids)){
|
||||
$result = array();
|
||||
$result["type"] = "productCoupons";
|
||||
$result["objectId"] = $value['product_platform_code'];
|
||||
$result["amount"] = bcsub($value["product_price"],$value["actual_product_price"],2); // 优惠金额
|
||||
$result["count"] = 1;
|
||||
|
||||
$promotion = array_push($promotion,$result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $promotion;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user