修正医生体现数据2
This commit is contained in:
parent
18b6bf72ae
commit
37ca9c1e21
@ -7,6 +7,7 @@ use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer;
|
||||
use App\Amqp\Producer\AutoFinishInquiryDelayDirectProducer;
|
||||
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
||||
use App\Amqp\Producer\SendSmsMessageProducer;
|
||||
use App\Amqp\Producer\UserCouponExpiredDelayDirectProducer;
|
||||
use App\Constants\DoctorTitleCode;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
@ -86,7 +87,7 @@ class TestController extends AbstractController
|
||||
// $this->test_12();
|
||||
// $this->test_13();
|
||||
// $this->test_14();
|
||||
$this->test_14();
|
||||
$this->test_17();
|
||||
}
|
||||
|
||||
// 获取未接诊的医生
|
||||
@ -457,61 +458,26 @@ class TestController extends AbstractController
|
||||
}
|
||||
|
||||
public function test_17(){
|
||||
$coupon['valid_days'] = 90;
|
||||
$data['valid_end_time'] = date("Y-m-d H:i:s", strtotime($coupon['valid_days'] . " day"));
|
||||
|
||||
$valid_end_time = strtotime($data['valid_end_time']);
|
||||
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$data = array();
|
||||
$data['user_coupon_id'] = 1;
|
||||
|
||||
$year = $this->request->input('date');
|
||||
|
||||
$date = date('Y-m-d',strtotime("2024-04-15"));
|
||||
|
||||
// 获取医生数据
|
||||
$params = array();
|
||||
$params['doctor_id'] = "516900370252341248";
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
return fail();
|
||||
$time = $valid_end_time - time();
|
||||
dump($time);die;
|
||||
if ($time < 0){
|
||||
return false;
|
||||
}
|
||||
$message = new UserCouponExpiredDelayDirectProducer($data);
|
||||
$message->setDelayMs(1000 * $time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['doctor_id'] = "516900370252341248";
|
||||
|
||||
// 获取当天开始时间
|
||||
$start_date = date('Y-m-d 00:00:00', strtotime($date));
|
||||
|
||||
// 获取当天结束时间
|
||||
$end_date = date('Y-m-d 23:59:59', strtotime($date));
|
||||
|
||||
$date_params = [$start_date, $end_date];
|
||||
|
||||
|
||||
$inquiryService = new InquiryService();
|
||||
|
||||
// 获取医生当日接诊的订单金额
|
||||
$doctor_today_inquiry_total = Order::getDoctorDayAmountTotal($params,$date_params,1);
|
||||
|
||||
// 获取医生当日已完成待入帐的订单金额
|
||||
$doctor_day_completed_amount_total = Order::getDoctorDayCompletedAmountTotal($params,$date_params,0);
|
||||
|
||||
if ($user_doctor['is_platform_deep_cooperation'] == 0){
|
||||
// // 获取医生当日接诊的订单金额
|
||||
// $doctor_today_inquiry_total = $inquiryService->getDoctorDayAmountTotal($user_info['client_user_id'],$date);
|
||||
|
||||
// 获取医生当日已完成未结束的订单金额
|
||||
// $doctor_day_completed_amount_total = $inquiryService->getDoctorDayCompletedAmountTotal($user_info['client_user_id'],$date);
|
||||
}else{
|
||||
// // 获取医生当日接诊的订单金额-坐班医生
|
||||
// $doctor_today_inquiry_total = $inquiryService->getCooperationDoctorDayAmountTotal($user_info['client_user_id'],$date);
|
||||
|
||||
// 获取医生当日已完成未结束的订单金额-坐班医生
|
||||
// $doctor_day_completed_amount_total = $inquiryService->getCooperationDoctorCompletedAmountTotal($user_info['client_user_id'],$date);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$result = array();
|
||||
$result['doctor_today_inquiry_total'] = bcmul((string)$doctor_today_inquiry_total,"0.75",2); // 今日接诊收入
|
||||
|
||||
return success($result);
|
||||
}
|
||||
}
|
||||
@ -250,7 +250,7 @@ class Order extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可提现订单列表
|
||||
* 获取可提现订单列表-分页
|
||||
* @param array $params
|
||||
* @param string|int $is_platform_deep_cooperation
|
||||
* @param array $fields
|
||||
@ -258,7 +258,7 @@ class Order extends Model
|
||||
* @param int|null $per_page
|
||||
* @return array
|
||||
*/
|
||||
public static function getDoctorWithdrawalOrderList(array $params, string|int $is_platform_deep_cooperation,array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||||
public static function getDoctorWithdrawalOrderPage(array $params, string|int $is_platform_deep_cooperation,array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||||
{
|
||||
$query = self::with(['OrderInquiry', 'OrderServicePackage'])
|
||||
->where($params)
|
||||
@ -302,4 +302,47 @@ class Order extends Model
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可提现订单列表
|
||||
* @param array $params
|
||||
* @param string|int $is_platform_deep_cooperation
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
public static function getDoctorWithdrawalOrderList(array $params, string|int $is_platform_deep_cooperation,array $fields = ["*"]): array
|
||||
{
|
||||
$query = self::with(['OrderInquiry', 'OrderServicePackage'])
|
||||
->where($params)
|
||||
->whereIn('order_type',[1,4,5]);
|
||||
|
||||
// 问诊订单
|
||||
$query = $query->where(function ($query) use ($is_platform_deep_cooperation){
|
||||
$query->whereExists(function ($subQuery) use ($is_platform_deep_cooperation){
|
||||
$subQuery->from('order_inquiry');
|
||||
if ($is_platform_deep_cooperation == 1){
|
||||
$subQuery->whereNotIn('inquiry_type', [2,4]);
|
||||
}
|
||||
|
||||
$subQuery->whereNotIn('inquiry_mode', [7,8,9])
|
||||
->whereIn('inquiry_status', [6])
|
||||
->whereIn('inquiry_refund_status', [0,3])
|
||||
->whereRaw('gdxz_order.order_id = gdxz_order_inquiry.order_id');
|
||||
})
|
||||
->orWhereExists(function ($subQuery) {
|
||||
$subQuery->from('order_service_package')
|
||||
->whereRaw('gdxz_order.order_id = gdxz_order_service_package.order_id')
|
||||
->whereIn('refund_status', [0,3])
|
||||
->where('pay_status', 2)
|
||||
->where('start_time', 2)
|
||||
->whereIn('order_service_status', [4,5])
|
||||
->WhereExists(function ($subQuery){
|
||||
$subQuery->from("order_service_package_inquiry")
|
||||
->whereRaw('gdxz_order_service_package.order_service_id = gdxz_order_service_package_inquiry.order_service_id');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,6 +135,8 @@ class DoctorAccountService extends BaseService
|
||||
|
||||
$results = Order::getDoctorCreatedDateOrderInquiryPage($params, $date_params, $user_doctor['is_platform_deep_cooperation'], ['*'], $page, $per_page);
|
||||
if (!empty($results['data'])) {
|
||||
$OrderService = new OrderService();
|
||||
|
||||
foreach ($results['data'] as &$result) {
|
||||
// 填入字段
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
@ -161,80 +163,11 @@ class DoctorAccountService extends BaseService
|
||||
$result['finish_time'] = $result['OrderServicePackage']['finish_time'];
|
||||
}
|
||||
|
||||
// 默认退款金额为0;
|
||||
$result['refund_total'] = 0;
|
||||
// 计算退款金额
|
||||
if ($result['refund_status'] == 3){
|
||||
// 问诊订单
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $result['OrderInquiry']['inquiry_no'];
|
||||
$order_inquiry_refunds = OrderInquiryRefund::getList($params);
|
||||
if (!empty($order_inquiry_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_inquiry_refunds as $order_inquiry_refund) {
|
||||
$refund_total = $refund_total + $order_inquiry_refund['refund_total'];
|
||||
}
|
||||
// 获取订单退款金额
|
||||
$result['refund_total'] = $OrderService->getOrderRefundAmount($result['order_no']);
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
|
||||
// 服务包订单
|
||||
if (!empty($result['OrderServicePackage'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_refunds = OrderServicePackageRefund::getList($params);
|
||||
if (!empty($order_service_package_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_service_package_refunds as $order_service_package_refund) {
|
||||
$refund_total = $refund_total + $order_service_package_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算预计收入
|
||||
if ($result['order_type'] == 1){
|
||||
$result['estimate_income'] = bcmul(
|
||||
bcsub(
|
||||
$result['OrderInquiry']['amount_total'],
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
if ($result['order_type'] == 4 || $result['order_type'] == 5){
|
||||
// 获取订单详情数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||||
if (!empty($order_service_package_detail)){
|
||||
|
||||
$result['estimate_income'] = bcmul( // 可提现费用
|
||||
bcsub( // 退款费用
|
||||
bcmul( // 问诊费用
|
||||
(string)$order_service_package_detail['service_count'],
|
||||
(string)$order_service_package_detail['single_inquiry_price'],
|
||||
3
|
||||
),
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
// 获取订单可提现金额
|
||||
$result['expected_amount_total'] = $OrderService->getOrderWithdrawalAmount($result,$result['refund_total']);
|
||||
|
||||
// 处理入账状态
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
@ -349,6 +282,41 @@ class DoctorAccountService extends BaseService
|
||||
$amount_total = $doctor_account['balance_account'];
|
||||
}
|
||||
|
||||
// 获取可提现订单列表
|
||||
$orders = Order:: getDoctorWithdrawalOrderList($params, $user_doctor['is_platform_deep_cooperation'], ['*']);
|
||||
if (empty($orders)){
|
||||
// 无订单,账户余额强制赋0;
|
||||
$amount_total = 0;
|
||||
}
|
||||
|
||||
$OrderService = new OrderService();
|
||||
|
||||
// 可提现金额
|
||||
$expected_amount_total = 0;
|
||||
|
||||
// 订单号数据
|
||||
$order_nos = [];
|
||||
|
||||
foreach ($orders as $order){
|
||||
// 获取订单退款金额
|
||||
$refund_total = $OrderService->getOrderRefundAmount($order['order_no']);
|
||||
|
||||
// 获取订单可提现金额
|
||||
$expected_amount_total = bcadd(
|
||||
$expected_amount_total,
|
||||
$OrderService->getOrderWithdrawalAmount($order,$refund_total),
|
||||
2
|
||||
);
|
||||
|
||||
$order_nos[] = $order['order_no'];
|
||||
}
|
||||
|
||||
// 对比订单金额和账户金额;金额相差1元及以上返回错误
|
||||
$diff_amount_total = abs($amount_total - $expected_amount_total);
|
||||
if ($diff_amount_total >= 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "提现金额错误");
|
||||
}
|
||||
|
||||
// 计算医生个人所得税
|
||||
$income_tax = $this->computeIndividualIncomeTax($amount_total);
|
||||
|
||||
@ -361,6 +329,7 @@ class DoctorAccountService extends BaseService
|
||||
$result['amount_total'] = $amount_total; // 账户余额
|
||||
$result['withdrawal_amount'] = $withdrawal_amount; // 提现金额
|
||||
$result['income_tax'] = $income_tax; // 个人所得税
|
||||
$result['order_nos'] = $order_nos; // 订单号
|
||||
|
||||
return success($result);
|
||||
}
|
||||
@ -445,9 +414,11 @@ class DoctorAccountService extends BaseService
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$params['is_withdrawal'] = 0;
|
||||
|
||||
$results = Order:: getDoctorWithdrawalOrderList($params, $user_doctor['is_platform_deep_cooperation'], ['*'], $page, $per_page);
|
||||
$results = Order:: getDoctorWithdrawalOrderPage($params, $user_doctor['is_platform_deep_cooperation'], ['*'], $page, $per_page);
|
||||
|
||||
if (!empty($results['data'])) {
|
||||
$OrderService = new OrderService();
|
||||
|
||||
foreach ($results['data'] as &$result) {
|
||||
// 填入字段
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
@ -474,79 +445,11 @@ class DoctorAccountService extends BaseService
|
||||
$result['finish_time'] = $result['OrderServicePackage']['finish_time'];
|
||||
}
|
||||
|
||||
// 默认退款金额为0;
|
||||
$result['refund_total'] = 0;
|
||||
// 计算退款
|
||||
if ($result['refund_status'] == 3){
|
||||
// 问诊订单
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $result['OrderInquiry']['inquiry_no'];
|
||||
$order_inquiry_refunds = OrderInquiryRefund::getList($params);
|
||||
if (!empty($order_inquiry_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_inquiry_refunds as $order_inquiry_refund) {
|
||||
$refund_total = $refund_total + $order_inquiry_refund['refund_total'];
|
||||
}
|
||||
// 获取订单退款金额
|
||||
$result['refund_total'] = $OrderService->getOrderRefundAmount($result['order_no']);
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
|
||||
// 服务包订单
|
||||
if (!empty($result['OrderServicePackage'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_refunds = OrderServicePackageRefund::getList($params);
|
||||
if (!empty($order_service_package_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_service_package_refunds as $order_service_package_refund) {
|
||||
$refund_total = $refund_total + $order_service_package_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算可提现金额
|
||||
if ($result['order_type'] == 1){
|
||||
$result['expected_amount_total'] = bcmul(
|
||||
bcsub(
|
||||
$result['OrderInquiry']['amount_total'],
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
if ($result['order_type'] == 4 || $result['order_type'] == 5){
|
||||
// 获取订单详情数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||||
if (!empty($order_service_package_detail)){
|
||||
$result['expected_amount_total'] = bcmul( // 可提现费用
|
||||
bcsub( // 退款费用
|
||||
bcmul( // 问诊费用
|
||||
(string)$order_service_package_detail['service_count'],
|
||||
(string)$order_service_package_detail['single_inquiry_price'],
|
||||
3
|
||||
),
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
// 获取订单可提现金额
|
||||
$result['expected_amount_total'] = $OrderService->getOrderWithdrawalAmount($result,$result['refund_total']);
|
||||
|
||||
unset($result['OrderInquiry']);
|
||||
unset($result['OrderServicePackage']);
|
||||
|
||||
@ -15,6 +15,7 @@ use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductRefund;
|
||||
use App\Model\OrderRefund;
|
||||
use App\Model\OrderServicePackage;
|
||||
use App\Model\OrderServicePackageDetail;
|
||||
use App\Model\OrderServicePackageInquiry;
|
||||
use App\Model\OrderServicePackageRefund;
|
||||
use App\Utils\Log;
|
||||
@ -1009,4 +1010,79 @@ class OrderService extends BaseService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单退款金额
|
||||
* @param string|int $order_no
|
||||
* @return string|int
|
||||
*/
|
||||
public function getOrderRefundAmount(string|int $order_no): string|int
|
||||
{
|
||||
// 退款金额
|
||||
$refund_total = 0;
|
||||
|
||||
// 获取订单退款数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$order_refunds = OrderRefund::getList($params);
|
||||
if (!empty($order_refunds)) {
|
||||
foreach ($order_refunds as $order_refund) {
|
||||
$refund_total = bcadd(
|
||||
(string)$refund_total,
|
||||
(string)$order_refund['refund_total'],
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $refund_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单可提现金额
|
||||
* @param array|object $order
|
||||
* @param string|int $refund_total 订单退款金额
|
||||
* @return int|string
|
||||
*/
|
||||
public function getOrderWithdrawalAmount(array|object $order,string|int $refund_total): int|string
|
||||
{
|
||||
// 可提现金额
|
||||
$expected_amount_total = 0;
|
||||
|
||||
// 计算可提现金额
|
||||
if ($order['order_type'] == 1){
|
||||
$expected_amount_total = bcmul(
|
||||
bcsub(
|
||||
$order['amount_total'],
|
||||
$refund_total,
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
if ($order['order_type'] == 4 || $order['order_type'] == 5){
|
||||
// 获取订单详情数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $order['order_no'];
|
||||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||||
if (!empty($order_service_package_detail)){
|
||||
$expected_amount_total = bcmul( // 可提现费用
|
||||
bcsub( // 退款费用
|
||||
bcmul( // 问诊费用
|
||||
(string)$order_service_package_detail['service_count'],
|
||||
(string)$order_service_package_detail['single_inquiry_price'],
|
||||
3
|
||||
),
|
||||
$refund_total,
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $expected_amount_total;
|
||||
}
|
||||
}
|
||||
@ -892,7 +892,7 @@ Router::addGroup('/case', function () {
|
||||
|
||||
// 测试使用
|
||||
Router::addGroup('/test', function () {
|
||||
Router::get('', [TestController::class, 'test_16']);
|
||||
Router::get('', [TestController::class, 'test1111']);
|
||||
|
||||
//
|
||||
// Router::get('/uninquiry', [TestController::class, 'uninquiry']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user