Browse Source

快捷支付

shish 5 years ago
parent
commit
49d658a426

+ 435 - 434
app/ghs/controllers/OrderController.php

@@ -3,6 +3,7 @@
 namespace ghs\controllers;
 
 use biz\merchant\services\MerchantExtendService;
+use biz\wx\classes\WxOpenClass;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\merchant\classes\ShopClass;
@@ -22,438 +23,438 @@ use common\components\stringUtil;
 
 class OrderController extends BaseController
 {
-
-    public $withoutLogin = ['order-relate', 'fast-pay'];
-
-    //订单列表 shish 2021.1.20
-    public function actionList()
-    {
-        $get = Yii::$app->request->get();
-        $status = $get['status'] ?? 0;
-        if (!empty($status)) {
-            $where['status'] = $status;
-        }
-        $where['merchantId'] = $this->merchantId;
-        if (isset($get['shopId'])) {
-            $shopId = $get['shopId'] ?? 0;
-            if (!empty($shopId)) {
-                $where['shopId'] = $this->shopId;
-            }
-        } else {
-            $where['shopId'] = $this->shopId;
-        }
-        $data = OrderClass::getOrderList($where);
-        util::success($data);
-    }
-
-    //商城下单操作 shish 2021.1.14
-    public function actionCreateOrder()
-    {
-        $post = Yii::$app->request->post();
-        $adminId = $this->adminId;
-        $shopId = $this->shopId;
-        if (!empty($shopId)) {
-            //供货商端 员工 开单
-            $post['customId'] = $post['customId'] ?? 0;
-            $post['adminId'] = $adminId;
-            $post['userId'] = 0;
-            $post['shopId'] = $shopId;
-        } else {
-            //供货商端 客户 开单
-            $post['userId'] = $adminId;
-            $post['adminId'] = 0;
-            $shopId = $post['shopId'] ?? 0;
-            if (empty($shopId)) {
-                util::fail('请选择供货商');
-            }
-            $post['shopId'] = $shopId;
-            $shop = ShopClass::getById($shopId);
-            if (empty($shop)) {
-                util::fail('没有找到供货商');
-            }
-        }
-
-        $post['payWay'] = $this->isWx == true ? 0 : 1;
-        $post['merchantId'] = $this->merchantId;
-        $post['fromType'] = 1;//商城
-        $post['prePrice'] = 0.01;
-        $post['actPrice'] = 0.01;
-        $post['sendSide'] = $post['sendSide'] ?? 0;
-
-        $productJson = $post['product'] ?? '';
-        if (empty($productJson)) {
-            util::fail('请选择花材');
-        }
-        $productList = json_decode($productJson, true);
-        if (empty($productList)) {
-            util::fail('请选择花材');
-        }
-        $orderSn = '';
-        $orderId = 0;
-        $connection = Yii::$app->db;//事务处理
-        $transaction = $connection->beginTransaction();
-        try {
-            //判断花材有效性
-            ProductClass::valid($productList, $this->shopId);
-            $post['product'] = $productList;
-            $order = OrderClass::addOrder($post);
-            $orderSn = $order['orderSn'] ?? '';
-            $orderId = $order['id'] ?? 0;
-            $transaction->commit();
-        } catch (Exception $e) {
-            $transaction->rollBack();
-            util::fail('下单失败');
-        }
-
-        util::success([
-            'orderId' => $orderId,
-            'orderSn' => $orderSn,
-            'totalPrice' => 0.01,
-            'sendType' => '快递送',
-            'sendTime' => '15:00',
-            'qrCode' => Yii::$app->params['imgHost'] . '/hhb_small.png',
-        ]);
-    }
-
-    //延期支付 shish 2021.1.19
-    public function actionDebt()
-    {
-        $get = Yii::$app->request->get();
-        util::complete();
-    }
-
-    //已经支付
-    public function actionHasPay()
-    {
-        $get = Yii::$app->request->get();
-        util::complete();
-    }
-
-    //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
-    public function actionWxPay()
-    {
-        ini_set('date.timezone', 'Asia/Shanghai');
-        $post = Yii::$app->request->post();
-        $couponId = $post['couponId'] ?? 0;
-        $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
-        $order = OrderClass::getByOrderSn($orderSn);
-        if (empty($order)) {
-            util::fail('订单号无效');
-        }
-        $orderId = $order['id'];
-
-        //支付前验证订单有效性
-        OrderClass::valid($order, $this->adminId);
-
-        $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
-        $totalFee = $order['actPrice'];
-
-        //小程序使用miniOpenId
-        if (httpUtil::isMiniProgram()) {
-            $openId = $this->admin['miniOpenId'];
-        } else {
-            $openId = $this->admin['openId'];
-        }
-        $typeList = configDict::getConfig('capitalType');
-        $capitalType = $typeList['xhOrder']['id'];
-        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
-        $wxPayType = 0;
-        if (httpUtil::isMiniProgram()) {
-            $wxPayType = 1;
-        }
-        $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
-        //订单30分钟后过期
-        $now = time();
-        $expireTime = $now + 1800;
-
-        $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);//将流水类型、代金劵等传给微信再回传
-        $input->SetTime_expire(date("YmdHis", $expireTime));
-        $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
-        $input->SetTrade_type("JSAPI");
-
-        //花卉宝代为申请的微信支付
-        $merchantExtend = $this->merchantExtend;
-        if ($merchantExtend['wxPayApply'] == 1) {
-            $input->SetSub_openid($openId);
-        } else {
-            $input->SetOpenid($openId);
-        }
-        //小程序使用miniAppId
-        if (httpUtil::isMiniProgram()) {
-            $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-        }
-
-        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-        $tools = new \JsApiPay();
-        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-        $newParams = json_decode($jsApiParameters, true);
-        //已请求微信不能修改价格
-        $updateData = [];
-        $updateData['modPrice'] = 0;
-        if (empty($order['deadline'])) {
-            $updateData['deadline'] = $expireTime;
-        }
-        OrderService::updateById($orderId, $updateData);
-        util::success($newParams);
-    }
-
-    //获取订单详情 shish 2021.1.21
-    public function actionDetail()
-    {
-        $get = Yii::$app->request->get();
-        $id = $get['id'] ?? 0;
-        $info = OrderClass::getOrderInfo($id, true, true, true);
-        OrderClass::valid($info, $this->shopId);
-        util::success($info);
-    }
-
-    //重选花材 shish 2021.1.22
-    public function actionChooseProduct()
-    {
-        $post = Yii::$app->request->post();
-        $id = $post['id'] ?? 0;
-        $product = $post['product'] ?? '[]';
-        $product = json_decode($product, true);
-        //检查花材是否都是同家门店的
-        ProductClass::valid($product, $this->shopId);
-
-        $info = OrderClass::getOrderInfo($id);
-        OrderClass::valid($info, $this->shopId);
-
-        //添加修改花材
-        OrderItemService::replace($info, $product);
-        util::complete();
-    }
-
-    //自取和免发货流程处理 shish 2021.1.22
-    public function actionWithoutSend()
-    {
-        $get = Yii::$app->request->get();
-        $id = $get['id'] ?? 0;
-        $info = OrderClass::getOrderInfo($id);
-        OrderClass::valid($info, $this->shopId);
-        OrderClass::withoutSend($info);
-        util::complete();
-    }
-
-    //本店送 shish 2021.1.24
-    public function actionSelfSend()
-    {
-        $get = Yii::$app->request->get();
-        $id = isset($get['id']) ? $get['id'] : 0;
-        $info = OrderClass::getOrderInfo($id);
-        OrderClass::valid($info, $this->shopId);
-        OrderClass::selfSend($info);
-        util::complete();
-    }
-
-    //运费计算 shish 2021.1.24
-    public function actionFreight()
-    {
-        util::success(['sndCost' => 20]);
-    }
-
-    //发快递和第三方配送 shish 2021.1.24
-    public function actionThirdSend()
-    {
-        $respond = [
-            'sendSide' => '达达',
-            'distance' => 5.5,
-            'sendCost' => 20,
-            'status' => 1,
-            'tip' => 5,
-        ];
-        util::success($respond);
-    }
-
-    //确认送达 shish 2021.1.24
-    public function actionReach()
-    {
-        $get = Yii::$app->request->get();
-        $id = isset($get['id']) ? $get['id'] : 0;
-        $info = OrderClass::getOrderInfo($id);
-        OrderClass::valid($info, $this->shopId);
-        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;
-        $user = $this->admin;
-        $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
-        $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
-        $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
-        $post['bookMobile'] = $bookMobile;
-        $prePrice = round($post['prePrice'], 2);
-        $couponId = isset($post['couponId']) ? $post['couponId'] : 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->merchantId;
-        $now = time();
-        $expireTime = $now + 300;//订单5分钟后过期
-        $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;
-        $order = OrderService::addOrder($post);
-        $orderId = $order['id'];
-        $orderSn = $order['orderSn'];
-        $merchantId = $this->merchantId;
-        if ($payWay == 0) {
-            $orderId = $order['id'];
-            $name = '购买商品';
-            $totalFee = $actPrice;
-            $user = UserService::getById($this->adminId);
-            $openId = isset($user['openId']) ? $user['openId'] : 0;
-            if (httpUtil::isMiniProgram()) {
-                //小程序使用miniOpenId
-                $openId = $user['miniOpenId'];
-            }
-            if (empty($openId)) {
-                util::fail('没有找到客户的openId');
-            }
-            $typeList = configDict::getConfig('capitalType');
-            $capitalType = $typeList['xhOrder']['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['mallHost'] . '/notice/wx-callback/');
-            $input->SetTrade_type("JSAPI");
-
-            //花卉宝代为申请的微信支付
-            $merchantExtend = $this->merchantExtend;
-            if ($merchantExtend['wxPayApply'] == 1) {
-                $input->SetSub_openid($openId);
-            } else {
-                $input->SetOpenid($openId);
-            }
-            //小程序使用miniAppId
-            if (httpUtil::isMiniProgram()) {
-                $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'] = $orderId;
-            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['mallHost'] . "/notice/alipay-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";//超时时间
-
-            $typeList = configDict::getConfig('capitalType');
-            $capitalType = $typeList['xhOrder']['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['mallHost'] . "/notice/alipay-callback";
-            $payResponse = new \AlipayTradeService($config);
-            $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
-            //直接将支付宝的html返回给前端
-            echo $result;
-        } elseif ($payWay == 2) {
-            //余额支付,验证支付密码是否正确
-            $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
-            $user = UserService::getUserInfo($this->adminId, false);
-            UserService::validPayPassword($payPassword, $user);
-            $typeList = configDict::getConfig('capitalType');
-            $capitalType = $typeList['xhOrder']['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' => $orderId, 'balance' => $balance]);
-        } else {
-            util::fail('无效的支付方式');
-        }
-    }
-
+	
+	public $withoutLogin = ['order-relate', 'fast-pay'];
+	
+	//订单列表 shish 2021.1.20
+	public function actionList()
+	{
+		$get = Yii::$app->request->get();
+		$status = $get['status'] ?? 0;
+		if (!empty($status)) {
+			$where['status'] = $status;
+		}
+		$where['merchantId'] = $this->merchantId;
+		if (isset($get['shopId'])) {
+			$shopId = $get['shopId'] ?? 0;
+			if (!empty($shopId)) {
+				$where['shopId'] = $this->shopId;
+			}
+		} else {
+			$where['shopId'] = $this->shopId;
+		}
+		$data = OrderClass::getOrderList($where);
+		util::success($data);
+	}
+	
+	//商城下单操作 shish 2021.1.14
+	public function actionCreateOrder()
+	{
+		$post = Yii::$app->request->post();
+		$adminId = $this->adminId;
+		$shopId = $this->shopId;
+		if (!empty($shopId)) {
+			//供货商端 员工 开单
+			$post['customId'] = $post['customId'] ?? 0;
+			$post['adminId'] = $adminId;
+			$post['userId'] = 0;
+			$post['shopId'] = $shopId;
+		} else {
+			//供货商端 客户 开单
+			$post['userId'] = $adminId;
+			$post['adminId'] = 0;
+			$shopId = $post['shopId'] ?? 0;
+			if (empty($shopId)) {
+				util::fail('请选择供货商');
+			}
+			$post['shopId'] = $shopId;
+			$shop = ShopClass::getById($shopId);
+			if (empty($shop)) {
+				util::fail('没有找到供货商');
+			}
+		}
+		
+		$post['payWay'] = $this->isWx == true ? 0 : 1;
+		$post['merchantId'] = $this->merchantId;
+		$post['fromType'] = 1;//商城
+		$post['prePrice'] = 0.01;
+		$post['actPrice'] = 0.01;
+		$post['sendSide'] = $post['sendSide'] ?? 0;
+		
+		$productJson = $post['product'] ?? '';
+		if (empty($productJson)) {
+			util::fail('请选择花材');
+		}
+		$productList = json_decode($productJson, true);
+		if (empty($productList)) {
+			util::fail('请选择花材');
+		}
+		$orderSn = '';
+		$orderId = 0;
+		$connection = Yii::$app->db;//事务处理
+		$transaction = $connection->beginTransaction();
+		try {
+			//判断花材有效性
+			ProductClass::valid($productList, $this->shopId);
+			$post['product'] = $productList;
+			$order = OrderClass::addOrder($post);
+			$orderSn = $order['orderSn'] ?? '';
+			$orderId = $order['id'] ?? 0;
+			$transaction->commit();
+		} catch (Exception $e) {
+			$transaction->rollBack();
+			util::fail('下单失败');
+		}
+		
+		util::success([
+			'orderId' => $orderId,
+			'orderSn' => $orderSn,
+			'totalPrice' => 0.01,
+			'sendType' => '快递送',
+			'sendTime' => '15:00',
+			'qrCode' => Yii::$app->params['imgHost'] . '/hhb_small.png',
+		]);
+	}
+	
+	//延期支付 shish 2021.1.19
+	public function actionDebt()
+	{
+		$get = Yii::$app->request->get();
+		util::complete();
+	}
+	
+	//已经支付
+	public function actionHasPay()
+	{
+		$get = Yii::$app->request->get();
+		util::complete();
+	}
+	
+	//获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
+	public function actionWxPay()
+	{
+		ini_set('date.timezone', 'Asia/Shanghai');
+		$post = Yii::$app->request->post();
+		$couponId = $post['couponId'] ?? 0;
+		$orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
+		$order = OrderClass::getByOrderSn($orderSn);
+		if (empty($order)) {
+			util::fail('订单号无效');
+		}
+		$orderId = $order['id'];
+		
+		//支付前验证订单有效性
+		OrderClass::valid($order, $this->adminId);
+		
+		$name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
+		$totalFee = $order['actPrice'];
+		
+		//小程序使用miniOpenId
+		if (httpUtil::isMiniProgram()) {
+			$openId = $this->admin['miniOpenId'];
+		} else {
+			$openId = $this->admin['openId'];
+		}
+		$typeList = configDict::getConfig('capitalType');
+		$capitalType = $typeList['xhOrder']['id'];
+		//流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+		$wxPayType = 0;
+		if (httpUtil::isMiniProgram()) {
+			$wxPayType = 1;
+		}
+		$attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
+		//订单30分钟后过期
+		$now = time();
+		$expireTime = $now + 1800;
+		
+		$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);//将流水类型、代金劵等传给微信再回传
+		$input->SetTime_expire(date("YmdHis", $expireTime));
+		$input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
+		$input->SetTrade_type("JSAPI");
+		
+		//花卉宝代为申请的微信支付
+		$merchantExtend = $this->merchantExtend;
+		if ($merchantExtend['wxPayApply'] == 1) {
+			$input->SetSub_openid($openId);
+		} else {
+			$input->SetOpenid($openId);
+		}
+		//小程序使用miniAppId
+		if (httpUtil::isMiniProgram()) {
+			$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+		}
+		
+		$wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+		$tools = new \JsApiPay();
+		$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+		$newParams = json_decode($jsApiParameters, true);
+		//已请求微信不能修改价格
+		$updateData = [];
+		$updateData['modPrice'] = 0;
+		if (empty($order['deadline'])) {
+			$updateData['deadline'] = $expireTime;
+		}
+		OrderService::updateById($orderId, $updateData);
+		util::success($newParams);
+	}
+	
+	//获取订单详情 shish 2021.1.21
+	public function actionDetail()
+	{
+		$get = Yii::$app->request->get();
+		$id = $get['id'] ?? 0;
+		$info = OrderClass::getOrderInfo($id, true, true, true);
+		OrderClass::valid($info, $this->shopId);
+		util::success($info);
+	}
+	
+	//重选花材 shish 2021.1.22
+	public function actionChooseProduct()
+	{
+		$post = Yii::$app->request->post();
+		$id = $post['id'] ?? 0;
+		$product = $post['product'] ?? '[]';
+		$product = json_decode($product, true);
+		//检查花材是否都是同家门店的
+		ProductClass::valid($product, $this->shopId);
+		
+		$info = OrderClass::getOrderInfo($id);
+		OrderClass::valid($info, $this->shopId);
+		
+		//添加修改花材
+		OrderItemService::replace($info, $product);
+		util::complete();
+	}
+	
+	//自取和免发货流程处理 shish 2021.1.22
+	public function actionWithoutSend()
+	{
+		$get = Yii::$app->request->get();
+		$id = $get['id'] ?? 0;
+		$info = OrderClass::getOrderInfo($id);
+		OrderClass::valid($info, $this->shopId);
+		OrderClass::withoutSend($info);
+		util::complete();
+	}
+	
+	//本店送 shish 2021.1.24
+	public function actionSelfSend()
+	{
+		$get = Yii::$app->request->get();
+		$id = isset($get['id']) ? $get['id'] : 0;
+		$info = OrderClass::getOrderInfo($id);
+		OrderClass::valid($info, $this->shopId);
+		OrderClass::selfSend($info);
+		util::complete();
+	}
+	
+	//运费计算 shish 2021.1.24
+	public function actionFreight()
+	{
+		util::success(['sndCost' => 20]);
+	}
+	
+	//发快递和第三方配送 shish 2021.1.24
+	public function actionThirdSend()
+	{
+		$respond = [
+			'sendSide' => '达达',
+			'distance' => 5.5,
+			'sendCost' => 20,
+			'status' => 1,
+			'tip' => 5,
+		];
+		util::success($respond);
+	}
+	
+	//确认送达 shish 2021.1.24
+	public function actionReach()
+	{
+		$get = Yii::$app->request->get();
+		$id = isset($get['id']) ? $get['id'] : 0;
+		$info = OrderClass::getOrderInfo($id);
+		OrderClass::valid($info, $this->shopId);
+		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['adminName']) ? $admin['adminName'] : '';
+		$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;
+		$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->merchantId;
+		$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);
+		$orderId = $order['id'];
+		$orderSn = $order['orderSn'];
+		$merchantId = $this->merchantId;
+		if ($payWay == 0) {
+			$orderId = $order['id'];
+			$name = '购买商品';
+			$totalFee = $actPrice;
+			$admin = AdminClass::getAdminById($this->adminId);
+			$openId = isset($admin['openId']) ? $admin['openId'] : 0;
+			if (httpUtil::isMiniProgram()) {
+				//小程序使用miniOpenId
+				$openId = $admin['miniOpenId'];
+			} else {
+				//util::fail('仅支持小程序支付');
+				$openId = $admin['miniOpenId'];
+			}
+			$typeList = configDict::getConfig('capitalType');
+			$capitalType = $typeList['xhOrder']['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['mallHost'] . '/notice/wx-callback/');
+			$input->SetTrade_type("JSAPI");
+			
+			//花卉宝代为申请的微信支付
+			//$merchantExtend = $this->merchantExtend;
+			$merchantExtend = WxOpenClass::getGhsWxInfo();
+			if ($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'] = $orderId;
+			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['mallHost'] . "/notice/alipay-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";//超时时间
+			
+			$typeList = configDict::getConfig('capitalType');
+			$capitalType = $typeList['xhOrder']['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['mallHost'] . "/notice/alipay-callback";
+			$payResponse = new \AlipayTradeService($config);
+			$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
+			//直接将支付宝的html返回给前端
+			echo $result;
+		} elseif ($payWay == 2) {
+			//余额支付,验证支付密码是否正确
+			$payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
+			$typeList = configDict::getConfig('capitalType');
+			$capitalType = $typeList['xhOrder']['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' => $orderId, 'balance' => $balance]);
+		} else {
+			util::fail('无效的支付方式');
+		}
+	}
+	
 }

+ 4 - 0
biz-ghs/order/classes/OrderItemClass.php

@@ -14,6 +14,10 @@ class OrderItemClass extends BaseClass
     //添加和修改花材
     public static function replace($orderSn, $product)
     {
+    	//快速付款没有商品
+    	if(empty($product)){
+    		return false;
+	    }
         self::deleteByCondition(['orderSn' => $orderSn]);
         foreach ($product as $key => $val) {
             $product[$key]['orderSn'] = $orderSn;

+ 8 - 1
sql.sql

@@ -950,4 +950,11 @@ CREATE TABLE IF NOT EXISTS `xhPurchaseClearSn` (
   `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
   PRIMARY KEY (`id`)
 ) AUTO_INCREMENT=28356251 COMMENT='结算订单号';
-ALTER TABLE xhGhsOrder MODIFY `fromType` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '来源:1门店 2商城 3朋友圈';
+ALTER TABLE xhGhsOrder MODIFY `fromType` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '来源:1门店 2商城 3朋友圈';
+
+
+========
+==
+ALTER TABLE `xhWxBase` ADD `wxPayMerchantId` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '微信支付商户id' AFTER `wxRefreshToken`;
+ALTER TABLE `xhWxBase` ADD `wxPayKey` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '微信支付密钥' AFTER `wxPayMerchantId`;
+相应的值需要补进去

+ 1 - 1
vendor/weixin/example/WxPay.JsApiPay.php

@@ -70,7 +70,7 @@ class JsApiPay
 		|| !array_key_exists("prepay_id", $UnifiedOrderResult)
 		|| $UnifiedOrderResult['prepay_id'] == "")
 		{
-			//throw new WxPayException("参数错误");
+			\common\components\util::fail($UnifiedOrderResult);
             throw new WxPayException($UnifiedOrderResult['return_msg']);
 		}
 		$jsapi = new WxPayJsApiPay();