<?php
namespace mobile\mvc\weixin\Action;
use mobile\mvc\weixin\pay_jsapi;
require_once RPC_DIR . '/pay/weixin/WxPayPubHelper/WxPayPubHelper.php';
Class Pay_jsapiAction extends pay_jsapi
{
/**
* 获取支付请求参数
*/
protected function ActionPayGasStation()
{
//判断订单的合法性 取消了获取store中的coupon_stack字段(S.coupon_stack),将优惠券可否叠加在coupon表中判断
$order = $this->DB('slave1')->query("SELECT O.*,S.name,S.wx_pay_method,S.wxsub_mch_id,S.cms_fluid,S.pay_method,S.wxsub_appid,"
. " M.wxfws_mch_id,M.wxfws_mchkey,M.appid,M.appsecret,M.wxmch_id,M.wxmchkey FROM " . TABLE_ORDER_WXGZH_TEMP . " AS O "
. " LEFT JOIN " . TABLE_STORE . " AS S ON O.store_id=S.id"
. " LEFT JOIN " . TABLE_MERCHANT_WX . " AS M ON M.id=1"
. " WHERE O.id='" . $this->data['id'] . "' "
. " AND O.order_status=1 "
. " AND O.wx_id='" . $_SESSION['wx_id'] . "'")->fetch(\PDO::FETCH_ASSOC);
if (empty($order)) {
return array("code" => 1, "msg" => "找不到该订单", "package" => "prepay_id=");
}
if ($order['order_status'] != '1') {
return array("code" => 1, "msg" => "订单已完成", "package" => "prepay_id=");
}
//特殊处理,或者结合中控处理
if ($order['cms_fluid'] && $order['store_id']<>13) {
$flu = new \comm\flu($this->data);
$array_fluid = $flu->FlowRecord($order['store_id'], $order['gun_id']);
if (empty($array_fluid['fluid'])) {
die(json_encode(array("code" => 1, "msg" => "找不到流水号或已被他人支付了", "package" => "prepay_id=")));
}
$fluid = 0;
foreach ($array_fluid['fluid'] as $item) {
if ($item['OilMount'] == $order['money']) {
//没锁定才给流水号
if ($item['PayState'] == 0 || $item['TempUserID'] == $order['wx_id']) {
if ($item['Fluid'] == $order['fluid']) {
$fluid = $order['fluid'];
break;
} else {
$fluid = $item['Fluid'];
}
}
}
}
if (empty($fluid)) {
die(json_encode(array("code" => 1, "msg" => "该流水已被他人锁定,请稍后再试!", "package" => "prepay_id=")));
}
//锁定支付
$parameter = array(
"StationID" => $order['store_id'],
"Fluid" => $fluid,
"WxID" => $order['wx_id'],
"machMount" => $order['money'],
"PrePayType" => 1
);
CommSentCMS($parameter, 'SetWXPrePay');
}
$need_payment = $order['need_payment'];
$discount_money = sprintf('%.2f', $order['money'] - $order['need_payment']);
$coupon_id = $coupon_money = 0;
if (!empty($this->data['coupon_id'])) {
$coupon = $this->DB('slave1')->get(TABLE_COUPON, "*", [
'AND' => [
'use_status' => 0,
'wx_id' => $_SESSION['wx_id'],
'id' => $this->data['coupon_id'],
'start_time[<=]' => date("Y-m-d H:i:s"),
'expire_time[>=]' => date("Y-m-d H:i:s")
]
]);
if (empty($coupon)) {
return array("code" => 1, "msg" => "优惠券无效6", "package" => "prepay_id=");
} else {
$user = parent::GetRegUserDetail($order['userid']);
if (empty($user)) {
$vip_level['vip_level'] = 0;
$user['car_type_id'] = 0;
} else {
$vip_level = $this->DB('slave1')->get(TABLE_VIP_LEVEL, ['vip_level'], [
'need_xp[<=]' => $user['vip_xp'],
'ORDER' => ['vip_level'],
'LIMIT' => [0, 1]
]);
}
$coupon_check = parent::CheckValidCoupon($coupon, $order['store_id'], $order['oil_type_id'], $order['money'], $vip_level['vip_level'], $user['car_type_id'], $order['oil_lit']);
if ($coupon_check['code'] == 1) {
return $coupon_check;
} else {
$coupon['coupon_money'] = $coupon_check['data']['coupon_money'];
//优惠券可用有效 原本是!$order['coupon_stack']
if (!$coupon['coupon_stack']) {
//可叠加支付
$need_payment = sprintf('%.2f', $order['need_payment'] - $coupon['coupon_money']);
$discount_money = $order['discount_money'];
} else {
//不可叠加支付
$need_payment = sprintf('%.2f', $order['money'] - $coupon['coupon_money']);
$discount_money = 0;
$order['who_discount'] = '用券用户';
}
if ($order['need_payment'] <= 0) {
return array("code" => 1, "msg" => "优惠金额不正确", "package" => "prepay_id=");
}
$coupon_id = $coupon['id'];
$coupon_money = $coupon['coupon_money'];
}
}
}
$order['orderid'] = sprintf("%03d", $order['store_id']) . sprintf("%03d", $order['gun_id']) . date("YmdHis") . rand(1000, 9999);
//更新订单信息
$res = $this->DB('master')->update(TABLE_ORDER_WXGZH_TEMP, [
'orderid' => $order['orderid'],
'coupon_id' => $coupon_id,
'coupon_money' => $coupon_money,
'discount_money' => $discount_money,
'who_discount' => $order['who_discount'],
'order_time' => date('Y-m-d H:i:s')
], [
'id' => $order['id']
])->rowCount();
if (!$res) {
return array("code" => 1, "msg" => "优惠券抵扣失败" . $coupon_id, "package" => "prepay_id=");
}
//特殊支付接入
if ($order['pay_method'] == 4) {
$order_temp_id = $order['id'];
$order['body'] = $order['name'] . '加油消费';
$order['remark'] = $order_temp_id;
$checkout_bank = $this->DB('slave1')->get(TABLE_MERCHANT_UNIONPAY, 'id', ['store_id' => $order['store_id'], 'active_status' => 1]);
if (empty($checkout_bank)) {
return ['code' => 1, 'msg' => '门店暂未支持本支付'];
}
//更新订单信息check_bank
$res = $this->DB('master')->update(TABLE_ORDER_WXGZH_TEMP, [
'checkout_bank' => $checkout_bank,
], [
'id' => $order['id']
])->rowCount();
//开启测试状态
if ($_SESSION['wx_id']=='66903') {
$order['need_payment'] = 0.5;
$order['pay_method'] = '4'; //测试默认银联商务
} else {
$order['need_payment'] = $need_payment;
}
switch ($order['pay_method']) {
case '4':
//汇聚支付
$pay = new \pay\weixin\Action\UnionpayAction([]);
break;
}
return $pay->CallPayAction($order);
}
//财付通普通支付
$config_array = array(
"appid" => $order['appid'],
"appsecret" => $order['appsecret'],
"curltimeout" => 10,
"sslsert_path" => '',
"sslkey_path" => '');
if (!empty($order['wx_pay_method'])) {
//使用子商户
$config_array['mchid'] = $order['wxfws_mch_id'];
$config_array['mchkey'] = $order['wxfws_mchkey'];
$config_array['sub_appid'] = $order['wxsub_appid'];
$config_array['sub_mch_id'] = $order['wxsub_mch_id'];
} else {
//使用本商户
$config_array['mchid'] = $order['wxmch_id'];
$config_array['mchkey'] = $order['wxmchkey'];
}
$jsApi = new \JsApi_pub($config_array); //H5调起支付
$unifiedOrder = new \UnifiedOrder_pub($config_array); //统一支付接口
$unifiedOrder->setParameter("openid", $_SESSION['openid']);
$unifiedOrder->setParameter("attach", $order['id']);
$unifiedOrder->setParameter("body", "" . $order['name'] . "油品费用");
$unifiedOrder->setParameter("out_trade_no", $order['orderid']);//商户订单号
$unifiedOrder->setParameter("total_fee", $need_payment * 100);//总金额
$unifiedOrder->setParameter("notify_url", WEBURL . "notify/wxgzh/wx_pay_oil_fee_notify.php"); //通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");//交易类型
$prepay_id = $unifiedOrder->getPrepayTdResult();
if ($prepay_id['code'] == 1) {
return array("code" => 1, "msg" => $prepay_id['msg'], "package" => "prepay_id=");
}
$jsApi->setPrepayId($prepay_id['prepay_id']);
$jsApiParameters = $jsApi->getParameters();
$jsApiParameters['orderid'] = $order['orderid'];
return $jsApiParameters;
}
}
微信支付或者接入多种支付思想
最新推荐文章于 2024-05-14 15:14:04 发布