@ -15,6 +15,7 @@ use App\Models\WeChatPay;
use App\Models\WeChatRefund;
use App\Models\WeChatRefund;
use Illuminate\Http\Request;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Yo;
use Yo;
use Login;
use Login;
use Lu;
use Lu;
@ -460,8 +461,48 @@ class UserOrderController extends Controller
->orderBy('id', 'desc')->get();
->orderBy('id', 'desc')->get();
return Yo::echo(['list' => $list]);
return Yo::echo(['list' => $list]);
}
}
public function mp_info(Request $request)
public function mp_info(Request $request)
{
Login::user();
$id = $request->post('id');
$order_info = UserOrder::where('id', $id)
->where('user', Login::$info->id)
->orderBy('id', 'desc')->first();
if (!$order_info) Yo::error_echo(100000, ['订单']);
if ($order_info->status == 1 & & $order_info->pay_type == 1) {
$TongLianPay = new TongLianPayController(); //通联支付
$check = $TongLianPay->PayCheck($order_info->show);
$we_chat_pay = WeChatPay::where('out_trade_no', $order_info->show)->first();
if (!!$we_chat_pay) {
$we_chat_pay->callback = json_encode([
'type' => 'auto',
'input' => '',
'headers' => '',
'res' => $check,
], JSON_UNESCAPED_UNICODE);
$we_chat_pay->save();
}
if($check['retcode']==='SUCCESS'){
if($check['trxstatus']=='0000'){
$ret = self::done($order_info->id, $check['trxid']);
if ($ret == 'status') {
$order_info = UserOrder::where('id', $id)
->where('user', Login::$info->id)
->orderBy('id', 'desc')->first();
}
}else{
Yo::error_echo(999999, ['支付失败,'.$check['errmsg']]);
}
}else{
Yo::error_echo(999999, ['支付失败,'.$check['retmsg']]);
}
}
return Yo::echo(['info' => $order_info]);
}
public function mp_info_WeiXin(Request $request)
{
{
Login::user();
Login::user();
$id = $request->post('id');
$id = $request->post('id');
@ -541,7 +582,37 @@ class UserOrderController extends Controller
if (count($res['data']) < 1 ) Yo::error_echo ( 200052 ) ;
if (count($res['data']) < 1 ) Yo::error_echo ( 200052 ) ;
if ($res['data'][0]['当前状态'] !== '未登记') Yo::error_echo(200052);
if ($res['data'][0]['当前状态'] !== '未登记') Yo::error_echo(200052);
switch ($order_info->pay_type) {
switch ($order_info->pay_type) {
case 1:
case 1://通联支付
$hospital_extra_content = self::pay_config($order_info->hospital);
$TongLianPay= new TongLianPayController();
$refund_date=[
'show' => $order_info->show,
'true_price' => $order_info->true_price * 100,
'transaction' => $order_info->transaction,
];
$tl_res = $TongLianPay->Refund($refund_date);
$out_trade_no = $order_info->show;
$wcr = new WeChatRefund();
$post_data = [
'transaction_id' => $order_info->transaction,
'out_refund_no' => $out_trade_no,
'total' =>(int) bcmul($order_info->true_price, '100', 0)
];
$wcr->out_trade_no = $out_trade_no;
$wcr->post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE);
$wcr->params = json_encode($tl_res, JSON_UNESCAPED_UNICODE);
$wcr->save();
$err_msg= empty($tl_res['retmsg'])?' ':$tl_res['retmsg'];
if($tl_res['retcode']!=='SUCCESS') Yo::error_echo(999999, ['退款失败,'.$tl_res['retmsg']]);
if($tl_res['trxstatus']!=='0000') Yo::error_echo(999999, ['退款失败,'.$err_msg]);
$order_info->status = 5;
$order_info->refund = $wcr->id;
$order_info->refund_time = date('Y-m-d H:i:s');
$order_info->save();
break;
case 111111111://微信支付,暂时停用
$hospital_extra_content = self::pay_config($order_info->hospital);
$hospital_extra_content = self::pay_config($order_info->hospital);
$wcp = new WeChatPayController();
$wcp = new WeChatPayController();
$wcp->builder([
$wcp->builder([
@ -828,7 +899,45 @@ class UserOrderController extends Controller
return Yo::echo($list);
return Yo::echo($list);
}
}
public function callback($id)
public function callback()//通联支付回调
{
$params = array();
foreach($_POST as $key=>$val) {//动态遍历获取所有收到的参数,此步非常关键,因为收银宝以后可能会加字段,动态获取可以兼容由于收银宝加字段而引起的签名异常
$params[$key] = $val;
}
if(count($params)< 1 ) { / / 如 果 参 数 为 空 , 则 不 进 行 处 理
echo "error";
exit();
}
$TongLianPay=new TongLianPayController();
$res=$TongLianPay->CallBack($params);
if($res['status']){
$order_info = UserOrder::where('show', $res['body']['cusorderid'])->first();
if (!!$order_info and $order_info->status ==1) {
$we_chat_pay = WeChatPay::where('out_trade_no', $res['body']['cusorderid'])->first();
if (!!$we_chat_pay) {
$we_chat_pay->callback = json_encode([
'type' => 'callback',
'input' => $params,
'headers' => [],
'res' => $res,
], JSON_UNESCAPED_UNICODE);
$we_chat_pay->save();
}
if($res['body']['trxstatus']=='0000'){
self::done($order_info->id, $res['body']['trxid']);
}
echo "success";
}
if (!!$order_info and $order_info->status ==2) {
echo "success";
}
}else{
echo "error";
}
}
public function callback_WeiXin($id)
{
{
$input = file_get_contents('php://input');
$input = file_get_contents('php://input');
$headers = request()->header();
$headers = request()->header();
@ -906,8 +1015,36 @@ class UserOrderController extends Controller
$hospital_extra_content = self::pay_config($order_info->hospital, false);
$hospital_extra_content = self::pay_config($order_info->hospital, false);
$hospital_sharing_content = self::sharing_config($order_info->hospital, false);
$hospital_sharing_content = self::sharing_config($order_info->hospital, false);
if ($pay_type == 1 & & $hospital_extra_content['wxp']['open'] == 2) $pay_type = 3;
if ($pay_type == 1 & & $hospital_extra_content['wxp']['open'] == 2) $pay_type = 3;
$user_account_info = UserAccount::where('user', Login::$info->id)->first();
switch ($pay_type) {
switch ($pay_type) {
case 1:
case 1:
$we_chat_pay = WeChatPay::where('out_trade_no', $order_info->show)->first();
if (!!$we_chat_pay) {
$pay = json_decode($we_chat_pay->params, true);
}else{
$TongLianPay=new TongLianPayController();
$data=[
'true_price' =>(int) bcmul($order_info->true_price, '100', 0),
'show' => $order_info->show,//订单号
'openid' => $user_account_info->account,
];
$pay=$TongLianPay->StartPay($data);
$order_info->pay_type = 1;
$order_info->save();
}
$pay2 = [
'appid' => $pay['appId'],
'timestamp' => $pay['timeStamp'],
'nonce_str' => $pay['nonceStr'],
'package' => $pay['package'],
'pay_sign' => $pay['paySign'],
'sign_type' => $pay['signType'],
];
return Yo::echo([
'action' => 'wxp',
'pay' => $pay2
]);
case 1111111111://暂时不用了,对接第三方了
$we_chat_pay = WeChatPay::where('out_trade_no', $order_info->show)->first();
$we_chat_pay = WeChatPay::where('out_trade_no', $order_info->show)->first();
if (!!$we_chat_pay) {
if (!!$we_chat_pay) {
$params = json_decode($we_chat_pay->params, true);
$params = json_decode($we_chat_pay->params, true);
@ -930,7 +1067,7 @@ class UserOrderController extends Controller
'v3' => $hospital_extra_content['wxp']['v3'],
'v3' => $hospital_extra_content['wxp']['v3'],
]);
]);
$out_trade_no = $order_info->show;
$out_trade_no = $order_info->show;
$user_account_info = UserAccount::where('user', Login::$info->id)->first();
$pay = $wcp->create([
$pay = $wcp->create([
'description' => '体检预约',
'description' => '体检预约',
'out_trade_no' => $out_trade_no,
'out_trade_no' => $out_trade_no,