|
|
|
|
@ -5,6 +5,8 @@ namespace App\Http\Controllers;
|
|
|
|
|
use App\Models\Appointment;
|
|
|
|
|
use App\Models\Hospital;
|
|
|
|
|
use App\Models\HospitalExtra;
|
|
|
|
|
use App\Models\NoProfitsharing;
|
|
|
|
|
use App\Models\ProfitsharingActionLog;
|
|
|
|
|
use App\Models\ProfitsharingLog;
|
|
|
|
|
use App\Models\UserAccount;
|
|
|
|
|
use App\Models\UserOrder;
|
|
|
|
|
@ -38,69 +40,116 @@ class UserOrderController extends Controller
|
|
|
|
|
$user_order->check_status = 2;
|
|
|
|
|
$user_order->check_time = date('Y-m-d H:i:s');
|
|
|
|
|
$user_order->save();
|
|
|
|
|
if ($user_order->price == $user_order->true_price) {
|
|
|
|
|
$hospital_sharing_content = self::sharing_config($user_order->hospital, false);
|
|
|
|
|
if ($hospital_sharing_content['open'] == 1
|
|
|
|
|
|| $hospital_sharing_content['open'] == 3) {
|
|
|
|
|
$slc = ProfitsharingLog::where('order', $user_order->id)->first();
|
|
|
|
|
if (!$slc) {
|
|
|
|
|
$p = new ProfitsharingController();
|
|
|
|
|
$sharing = $p->sharing($user_order->id, $hospital_sharing_content['hospital']);
|
|
|
|
|
$receivers = [];
|
|
|
|
|
$sharing_map = [];
|
|
|
|
|
|
|
|
|
|
$hospital_sharing_content = self::sharing_config($user_order->hospital, false);
|
|
|
|
|
if ($hospital_sharing_content['open'] == 1
|
|
|
|
|
|| $hospital_sharing_content['open'] == 3) {
|
|
|
|
|
$slc = ProfitsharingLog::where('order', $user_order->id)->first();
|
|
|
|
|
if (!$slc) {
|
|
|
|
|
$p = new ProfitsharingController();
|
|
|
|
|
$sharing = $p->sharing($user_order->id, $hospital_sharing_content['hospital']);
|
|
|
|
|
$receivers = [];
|
|
|
|
|
$sharing_map = [];
|
|
|
|
|
$price = $user_order->true_price;
|
|
|
|
|
$surplus = $price;
|
|
|
|
|
foreach ($sharing as $item) {
|
|
|
|
|
$formula = $item->formula;
|
|
|
|
|
$amount = number_format($p->eval_action($formula, $price, $surplus), 2);
|
|
|
|
|
$receivers[] = [
|
|
|
|
|
'type' => $item->type == 1 ? 'MERCHANT_ID' : 'PERSONAL_OPENID',
|
|
|
|
|
'account' => $item->account,
|
|
|
|
|
'amount' => $amount * 100,
|
|
|
|
|
'description' => $item->desc
|
|
|
|
|
];
|
|
|
|
|
$surplus = $surplus - $amount;
|
|
|
|
|
$sharing_map[] = [
|
|
|
|
|
'amount' => $amount,
|
|
|
|
|
'surplus' => $surplus,
|
|
|
|
|
'formula' => $formula,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$np = NoProfitsharing::where('hospital', $user_order->hospital)->orderBy('id', 'desc')->get();
|
|
|
|
|
$mp_items = [];
|
|
|
|
|
foreach ($np as $item) {
|
|
|
|
|
$mp_items[] = $item->item_id;
|
|
|
|
|
}
|
|
|
|
|
$price = 0;
|
|
|
|
|
$hold = 0;
|
|
|
|
|
$buy_info = json_decode($user_order->buy_info, true);
|
|
|
|
|
if ($buy_info['combo']['id'] != 0) {
|
|
|
|
|
foreach ($buy_info['combo']['items'] as $item) {
|
|
|
|
|
if ($item['discount_type'] == '打折') {
|
|
|
|
|
$item_price = $item['price'] * $item['discount_value'];
|
|
|
|
|
} else {
|
|
|
|
|
$item_price = $item['price'] - $item['discount_value'];
|
|
|
|
|
}
|
|
|
|
|
$item_price = floor($item_price * 100) / 100;
|
|
|
|
|
if (!in_array($item['id'], $mp_items)) {
|
|
|
|
|
$price += $item_price;
|
|
|
|
|
} else {
|
|
|
|
|
$hold += $item_price;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($buy_info['items'] as $item) {
|
|
|
|
|
$item_price = $item['price'];
|
|
|
|
|
if (!in_array($item['id'], $mp_items)) {
|
|
|
|
|
$price += $item_price;
|
|
|
|
|
} else {
|
|
|
|
|
$hold += $item_price;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count($receivers) != 0) {
|
|
|
|
|
if ($hospital_sharing_content['open'] == 1) {
|
|
|
|
|
$sharing_data = [
|
|
|
|
|
'transaction_id' => $user_order->transaction,
|
|
|
|
|
'receivers' => $receivers
|
|
|
|
|
foreach ($sharing as $item) {
|
|
|
|
|
$formula = $item->formula;
|
|
|
|
|
$amount = $p->eval_action($formula, [
|
|
|
|
|
'price' => $price, // 参与分账的金额
|
|
|
|
|
'hold' => $hold, // 不参与分账的金额
|
|
|
|
|
]);
|
|
|
|
|
$receivers[] = [
|
|
|
|
|
'type' => $item->type == 1 ? 'MERCHANT_ID' : 'PERSONAL_OPENID',
|
|
|
|
|
'account' => $item->account,
|
|
|
|
|
'amount' => intval(bcmul($amount, 100, 0)),
|
|
|
|
|
'description' => $item->desc
|
|
|
|
|
];
|
|
|
|
|
$hospital_extra_content = self::pay_config($user_order->hospital);
|
|
|
|
|
$wcp = new WeChatPayController();
|
|
|
|
|
$builder_config = [
|
|
|
|
|
'appid' => env('WX_APP_ID'),
|
|
|
|
|
'pem_path' => base_path() . $hospital_extra_content['wxp']['key'],
|
|
|
|
|
'cer_path' => base_path() . $hospital_extra_content['wxp']['crt'],
|
|
|
|
|
'cer_num' => $hospital_extra_content['wxp']['number'],
|
|
|
|
|
'mchid' => $hospital_extra_content['wxp']['id'],
|
|
|
|
|
'v3' => $hospital_extra_content['wxp']['v3'],
|
|
|
|
|
$sharing_map[] = [
|
|
|
|
|
'amount' => $amount,
|
|
|
|
|
'formula' => $formula,
|
|
|
|
|
];
|
|
|
|
|
$wcp->builder($builder_config);
|
|
|
|
|
$res = $wcp->profitsharing($sharing_data);
|
|
|
|
|
} else {
|
|
|
|
|
$builder_config = [];
|
|
|
|
|
$res = [];
|
|
|
|
|
|
|
|
|
|
$pal = new ProfitsharingActionLog();
|
|
|
|
|
$pal->hospital = $item->hospital;
|
|
|
|
|
$pal->order = $user_order->id;
|
|
|
|
|
$pal->pro_id = $item->id;
|
|
|
|
|
$pal->formula = $formula;
|
|
|
|
|
$pal->price = $price;
|
|
|
|
|
$pal->hold = $hold;
|
|
|
|
|
$pal->money = $amount;
|
|
|
|
|
$pal->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sl = new ProfitsharingLog();
|
|
|
|
|
$sl->hospital = $user_order->hospital;
|
|
|
|
|
$sl->type = $hospital_sharing_content['open'];
|
|
|
|
|
$sl->order = $user_order->id;
|
|
|
|
|
$sl->builder = json_encode($builder_config, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->receivers = json_encode($receivers, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->sharing = json_encode($sharing_map, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->response = json_encode($res, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->recover = '{}';
|
|
|
|
|
$sl->status = 1;
|
|
|
|
|
$sl->save();
|
|
|
|
|
if (count($receivers) != 0) {
|
|
|
|
|
if ($hospital_sharing_content['open'] == 1) {
|
|
|
|
|
$sharing_data = [
|
|
|
|
|
'transaction_id' => $user_order->transaction,
|
|
|
|
|
'receivers' => $receivers
|
|
|
|
|
];
|
|
|
|
|
$hospital_extra_content = self::pay_config($user_order->hospital);
|
|
|
|
|
$wcp = new WeChatPayController();
|
|
|
|
|
$builder_config = [
|
|
|
|
|
'appid' => env('WX_APP_ID'),
|
|
|
|
|
'pem_path' => base_path() . $hospital_extra_content['wxp']['key'],
|
|
|
|
|
'cer_path' => base_path() . $hospital_extra_content['wxp']['crt'],
|
|
|
|
|
'cer_num' => $hospital_extra_content['wxp']['number'],
|
|
|
|
|
'mchid' => $hospital_extra_content['wxp']['id'],
|
|
|
|
|
'v3' => $hospital_extra_content['wxp']['v3'],
|
|
|
|
|
];
|
|
|
|
|
$wcp->builder($builder_config);
|
|
|
|
|
$res = $wcp->profitsharing($sharing_data);
|
|
|
|
|
} else {
|
|
|
|
|
$builder_config = [];
|
|
|
|
|
$res = [
|
|
|
|
|
'hold' => $hold,
|
|
|
|
|
'price' => $price,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sl = new ProfitsharingLog();
|
|
|
|
|
$sl->hospital = $user_order->hospital;
|
|
|
|
|
$sl->type = $hospital_sharing_content['open'];
|
|
|
|
|
$sl->order = $user_order->id;
|
|
|
|
|
$sl->builder = json_encode($builder_config, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->receivers = json_encode($receivers, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->sharing = json_encode($sharing_map, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->response = json_encode($res, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$sl->recover = '{}';
|
|
|
|
|
$sl->status = 1;
|
|
|
|
|
$sl->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -117,6 +166,79 @@ class UserOrderController extends Controller
|
|
|
|
|
return Yo::update_echo($appointment_number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function done_test(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$id = $request->post('id');
|
|
|
|
|
$user_order = UserOrder::where('id', $id)->first();
|
|
|
|
|
if (!$user_order) Yo::error_echo(100000, ['订单']);
|
|
|
|
|
$hospital_sharing_content = self::sharing_config($user_order->hospital, false);
|
|
|
|
|
$receivers = [];
|
|
|
|
|
$sharing_map = [];
|
|
|
|
|
$price = 0;
|
|
|
|
|
$hold = 0;
|
|
|
|
|
if ($hospital_sharing_content['open'] == 1
|
|
|
|
|
|| $hospital_sharing_content['open'] == 3) {
|
|
|
|
|
$p = new ProfitsharingController();
|
|
|
|
|
$sharing = $p->sharing($user_order->id, $hospital_sharing_content['hospital']);
|
|
|
|
|
$np = NoProfitsharing::where('hospital', $user_order->hospital)->orderBy('id', 'desc')->get();
|
|
|
|
|
$mp_items = [];
|
|
|
|
|
foreach ($np as $item) {
|
|
|
|
|
$mp_items[] = $item->item_id;
|
|
|
|
|
}
|
|
|
|
|
$price = 0;
|
|
|
|
|
$hold = 0;
|
|
|
|
|
$buy_info = json_decode($user_order->buy_info, true);
|
|
|
|
|
if ($buy_info['combo']['id'] != 0) {
|
|
|
|
|
foreach ($buy_info['combo']['items'] as $item) {
|
|
|
|
|
if ($item['discount_type'] == '打折') {
|
|
|
|
|
$item_price = $item['price'] * $item['discount_value'];
|
|
|
|
|
} else {
|
|
|
|
|
$item_price = $item['price'] - $item['discount_value'];
|
|
|
|
|
}
|
|
|
|
|
$item_price = floor($item_price * 100) / 100;;
|
|
|
|
|
if (!in_array($item['id'], $mp_items)) {
|
|
|
|
|
$price += $item_price;
|
|
|
|
|
} else {
|
|
|
|
|
$hold += $item_price;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($buy_info['items'] as $item) {
|
|
|
|
|
$item_price = $item['price'];
|
|
|
|
|
if (!in_array($item['id'], $mp_items)) {
|
|
|
|
|
$price += $item_price;
|
|
|
|
|
} else {
|
|
|
|
|
$hold += $item_price;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($sharing as $item) {
|
|
|
|
|
$formula = $item->formula;
|
|
|
|
|
$amount = $p->eval_action($formula, [
|
|
|
|
|
'price' => $price, // 参与分账的金额
|
|
|
|
|
'hold' => $hold, // 不参与分账的金额
|
|
|
|
|
]);
|
|
|
|
|
$receivers[] = [
|
|
|
|
|
'type' => $item->type == 1 ? 'MERCHANT_ID' : 'PERSONAL_OPENID',
|
|
|
|
|
'account' => $item->account,
|
|
|
|
|
'amount' => intval(bcmul($amount, 100, 0)),
|
|
|
|
|
'description' => $item->desc
|
|
|
|
|
];
|
|
|
|
|
$sharing_map[] = [
|
|
|
|
|
'amount' => $amount,
|
|
|
|
|
'formula' => $formula,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Yo::update_echo([
|
|
|
|
|
'$hold' => $hold,
|
|
|
|
|
'$price' => $price,
|
|
|
|
|
'a' => $receivers,
|
|
|
|
|
'b' => $sharing_map,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create_appointment($hospital, $data)
|
|
|
|
|
{
|
|
|
|
|
$peis = new PEISApiController();
|
|
|
|
|
@ -183,6 +305,7 @@ class UserOrderController extends Controller
|
|
|
|
|
'id' => 0,
|
|
|
|
|
'name' => '自选项目',
|
|
|
|
|
'price' => 0,
|
|
|
|
|
'items' => []
|
|
|
|
|
],
|
|
|
|
|
'items' => [],
|
|
|
|
|
'group' => [
|
|
|
|
|
@ -193,11 +316,13 @@ class UserOrderController extends Controller
|
|
|
|
|
$combo_info = $cic->combo_info($hospital, [
|
|
|
|
|
'套餐Id' => $combo,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$price += $combo_info['price'];
|
|
|
|
|
$buy_info['combo'] = [
|
|
|
|
|
'id' => $combo_info['id'],
|
|
|
|
|
'name' => $combo_info['name'],
|
|
|
|
|
'price' => $combo_info['price'],
|
|
|
|
|
'items' => $combo_info['items'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$items = $request->post('items');
|
|
|
|
|
@ -246,7 +371,9 @@ class UserOrderController extends Controller
|
|
|
|
|
}
|
|
|
|
|
$check_items = [];
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
$check_items[] = ['Id' => $item];
|
|
|
|
|
$check_items[] = [
|
|
|
|
|
'Id' => $item
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
if (!!($combo == 0 ? null : $combo) || count($check_items) != 0) {
|
|
|
|
|
$item_check = self::item_check($hospital, [
|
|
|
|
|
@ -467,7 +594,10 @@ class UserOrderController extends Controller
|
|
|
|
|
$buy_info = json_decode($order_info->buy_info, true);
|
|
|
|
|
$check_items = [];
|
|
|
|
|
foreach ($buy_info['items'] as $item) {
|
|
|
|
|
$check_items[] = ['Id' => $item['id']];
|
|
|
|
|
$check_items[] = [
|
|
|
|
|
'Id' => $item['id'],
|
|
|
|
|
'价格' => $item['price']
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$combo = $order_info->combo;
|
|
|
|
|
if (!!($combo == 0 ? null : $combo) || count($check_items) != 0) {
|
|
|
|
|
|