|
|
@@ -2,10 +2,8 @@
|
|
|
|
|
|
namespace ghs\controllers;
|
|
|
|
|
|
-use biz\sj\services\MerchantExtendService;
|
|
|
use bizGhs\express\services\DadaExpressServices;
|
|
|
use bizHd\wx\classes\WxOpenClass;
|
|
|
-use bizGhs\admin\classes\AdminClass;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
use bizGhs\merchant\services\ShopService;
|
|
|
use bizGhs\order\classes\OrderClass;
|
|
|
@@ -15,10 +13,8 @@ use bizGhs\product\classes\ProductClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\dateUtil;
|
|
|
use common\components\httpUtil;
|
|
|
-use common\services\xhPayToolService;
|
|
|
use Yii;
|
|
|
use common\components\util;
|
|
|
-use common\components\stringUtil;
|
|
|
|
|
|
class OrderController extends BaseController
|
|
|
{
|
|
|
@@ -358,168 +354,6 @@ class OrderController extends BaseController
|
|
|
util::complete();
|
|
|
}
|
|
|
|
|
|
- //快捷付款订单
|
|
|
- public function actionFastPay()
|
|
|
- {
|
|
|
- ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
|
|
|
- $post['shopId'] = 2;
|
|
|
- //默认门店订单
|
|
|
- $store = isset($post['store']) ? $post['store'] : 1;
|
|
|
- $post['store'] = $store;
|
|
|
- $fromType = $post['fromType'] ?? 1;
|
|
|
- $post['userId'] = $this->adminId;
|
|
|
- $admin = $this->admin;
|
|
|
- $post['bookName'] = isset($admin['name']) ? $admin['name'] : '';
|
|
|
- $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
|
|
|
- $bookMobile = empty($bookMobile) && isset($admin['mobile']) && !empty($admin['mobile']) ? $admin['mobile'] : $bookMobile;
|
|
|
- $post['bookMobile'] = $bookMobile;
|
|
|
- $prePrice = round($post['prePrice'], 2);
|
|
|
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
- $sourceType = 0;
|
|
|
- $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
|
|
|
- $actPrice = $discountData['price'];
|
|
|
- $post['discountType'] = $discountData['discountType'];
|
|
|
- $post['discountAmount'] = $discountData['discountAmount'];
|
|
|
- $post['actPrice'] = $actPrice;
|
|
|
- $post['payStyle'] = 0;
|
|
|
- $post['merchantId'] = $this->sjId;
|
|
|
- $now = time();
|
|
|
- //订单5分钟后过期
|
|
|
- $expireTime = $now + 300;
|
|
|
- $post['createTime'] = date("Y-m-d H:i:s", $now);
|
|
|
- $post['deadline'] = $expireTime;
|
|
|
- if ($actPrice <= 0) {
|
|
|
- util::fail('请填写正确的金额');
|
|
|
- }
|
|
|
- //微信支付订单提交不能修改价格
|
|
|
- $post['modPrice'] = $this->isWx ? 0 : 1;
|
|
|
- $post['sourceType'] = $sourceType;
|
|
|
- $post['goodsNum'] = 1;
|
|
|
- $post['fromType'] = $fromType;
|
|
|
- $post['product'] = [];
|
|
|
- $order = OrderClass::addOrder($post);
|
|
|
- $id = $order['id'];
|
|
|
- $orderSn = $order['orderSn'];
|
|
|
- $merchantId = $this->sjId;
|
|
|
- if ($payWay == 0) {
|
|
|
- $id = $order['id'];
|
|
|
- $name = '购买商品';
|
|
|
- $totalFee = $actPrice;
|
|
|
- $admin = AdminClass::getAdminById($this->adminId);
|
|
|
- //小程序使用miniOpenId
|
|
|
- $openId = $admin['miniOpenId'];
|
|
|
- $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
|
|
|
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
|
|
|
- $wxPayType = 0;
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- $wxPayType = 1;
|
|
|
- }
|
|
|
- $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
|
|
|
- $wx = Yii::getAlias("@vendor/weixin");
|
|
|
- require_once($wx . '/lib/WxPay.Api.php');
|
|
|
- require_once($wx . '/example/WxPay.JsApiPay.php');
|
|
|
- $input = new \WxPayUnifiedOrder();
|
|
|
- $input->SetBody($name);
|
|
|
- $input->SetOut_trade_no($orderSn);
|
|
|
- $input->SetTotal_fee($totalFee * 100);
|
|
|
- $input->SetTime_start(date("YmdHis", $now));
|
|
|
- $input->SetAttach($attach);
|
|
|
- //设置订单有效期5分钟
|
|
|
- $input->SetTime_expire(date("YmdHis", $expireTime));
|
|
|
- $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
|
|
|
- $input->SetTrade_type("JSAPI");
|
|
|
-
|
|
|
- //花卉宝代为申请的微信支付
|
|
|
- //$merchantExtend = $this->sjExtend;
|
|
|
- $merchantExtend = WxOpenClass::getGhsWxInfo();
|
|
|
- if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
|
|
|
- $input->SetSub_openid($openId);
|
|
|
- } else {
|
|
|
- $input->SetOpenid($openId);
|
|
|
- }
|
|
|
- //小程序使用miniAppId
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
- }
|
|
|
- //强制使用小程序的appId
|
|
|
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
- Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
|
|
|
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
- $tools = new \JsApiPay();
|
|
|
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
- $newParams = json_decode($jsApiParameters, true);
|
|
|
- $newParams['orderId'] = $id;
|
|
|
- util::success($newParams);
|
|
|
- } elseif ($payWay == 1) {
|
|
|
- $extend = MerchantExtendService::getByMerchantId($merchantId);
|
|
|
- if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
|
|
|
- util::fail('支付宝付款即将开通...');
|
|
|
- }
|
|
|
- $config = [
|
|
|
- //应用ID,您的APPID。
|
|
|
- 'app_id' => $extend['alipayPId'],
|
|
|
- //商户私钥,您的原始格式RSA私钥
|
|
|
- 'merchant_private_key' => $extend['alipayKey'],
|
|
|
- //异步通知地址
|
|
|
- 'notify_url' => Yii::$app->params['ghsHost'] . "/notice/ali-callback",
|
|
|
- //同步跳转
|
|
|
- 'return_url' => "",
|
|
|
- //编码格式
|
|
|
- 'charset' => "UTF-8",
|
|
|
- //签名方式
|
|
|
- 'sign_type' => "RSA2",
|
|
|
- //支付宝网关
|
|
|
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
|
|
|
- //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
|
|
|
- 'alipay_public_key' => $extend['alipayPublicKey'],
|
|
|
- ];
|
|
|
-
|
|
|
- Yii::info(json_encode($config) . ' aplipay config');
|
|
|
-
|
|
|
- $alipayWap = Yii::getAlias("@vendor/alipayWap");
|
|
|
- require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
|
|
|
- require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
|
|
|
-
|
|
|
- $totalFee = $order['actPrice'];
|
|
|
- $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
|
|
|
- $subject = '购买商品';//订单名称,必填
|
|
|
- $total_amount = $totalFee;//付款金额,必填
|
|
|
- $body = '';//商品描述,可空
|
|
|
- $timeout_express = "1m";//超时时间
|
|
|
-
|
|
|
- $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
|
|
|
- $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
|
|
|
- $passBackParams = urlencode($passBackParams);
|
|
|
-
|
|
|
- $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
|
|
|
- $payRequestBuilder->setBody($body);
|
|
|
- $payRequestBuilder->setSubject($subject);
|
|
|
- $payRequestBuilder->setOutTradeNo($out_trade_no);
|
|
|
- $payRequestBuilder->setTotalAmount($total_amount);
|
|
|
- $payRequestBuilder->setTimeExpress($timeout_express);
|
|
|
- //在异步通知时将该参数原样返回
|
|
|
- $payRequestBuilder->setPassbackParams($passBackParams);
|
|
|
- //同步通知
|
|
|
- $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
|
|
|
- //异步通知
|
|
|
- $notifyUrl = Yii::$app->params['ghsHost'] . "/notice/ali-callback";
|
|
|
- $payResponse = new \AlipayTradeService($config);
|
|
|
- $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
|
|
|
- //直接将支付宝的html返回给前端
|
|
|
- echo $result;
|
|
|
- } elseif ($payWay == 2) {
|
|
|
- $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
|
|
|
- $callbackParams = [];
|
|
|
- $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
|
|
|
- $balance = isset($respond['balance']) ? $respond['balance'] : 0;
|
|
|
- util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $id, 'balance' => $balance]);
|
|
|
- } else {
|
|
|
- util::fail('无效的支付方式');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
//下单要用到的相关信息 ssh 2019.12.6
|
|
|
public function actionOrderRelate()
|
|
|
{
|