|
|
@@ -2,7 +2,100 @@
|
|
|
|
|
|
namespace shop\controllers;
|
|
|
|
|
|
+use biz\merchant\services\MerchantExtendService;
|
|
|
+use biz\merchant\services\MerchantService;
|
|
|
+use biz\saas\services\RenewService;
|
|
|
+use biz\saas\services\SetMealService;
|
|
|
+use biz\user\services\UserService;
|
|
|
+use common\components\configDict;
|
|
|
+use common\components\httpUtil;
|
|
|
+use common\components\util;
|
|
|
+use Yii;
|
|
|
+
|
|
|
class RenewController extends BaseController
|
|
|
{
|
|
|
|
|
|
+ public function actionList()
|
|
|
+ {
|
|
|
+ $where = [];
|
|
|
+ $list = RenewService::getRenewList($where);
|
|
|
+ util::success($list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //微信支付购买 shish 2020.1.11
|
|
|
+ public function actionWxPay()
|
|
|
+ {
|
|
|
+ ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
+ $merchantId = Yii::$app->request->get('merchantId', 0);
|
|
|
+ $merchant = MerchantService::getMerchantById($merchantId);
|
|
|
+ if (empty($merchant)) {
|
|
|
+ util::fail('没有找到商家');
|
|
|
+ }
|
|
|
+ $setId = isset($merchant['setId']) ? $merchant['setId'] : 0;
|
|
|
+ $set = SetMealService::getById($setId);
|
|
|
+ if (empty($set)) {
|
|
|
+ util::fail('没有找到套餐');
|
|
|
+ }
|
|
|
+ $userId = $this->userId;
|
|
|
+ $addData['userId'] = $userId;
|
|
|
+ $price = $set['price'];
|
|
|
+ $prePrice = $price;
|
|
|
+ $actPrice = $price;
|
|
|
+ $addData['actPrice'] = $actPrice;
|
|
|
+ $addData['prePrice'] = $prePrice;
|
|
|
+ $addData['merchantId'] = $merchantId;
|
|
|
+ $now = time();
|
|
|
+ $expireTime = $now + 300;//订单5分钟后过期
|
|
|
+ $addData['deadline'] = $expireTime;
|
|
|
+ $order = RenewService::addOrder($addData);
|
|
|
+ $orderId = $order['id'];
|
|
|
+ $orderSn = $order['orderSn'];
|
|
|
+ $couponId = 0;
|
|
|
+ $name = $set['name'] . '开通续费';
|
|
|
+ $totalFee = $actPrice;
|
|
|
+ $userId = $addData['userId'];
|
|
|
+ $user = UserService::getById($userId);
|
|
|
+ //小程序使用miniOpenId
|
|
|
+ if (httpUtil::isMiniProgram()) {
|
|
|
+ $openId = $user['miniOpenId'];
|
|
|
+ } else {
|
|
|
+ $openId = $user['openId'];
|
|
|
+ }
|
|
|
+ $typeList = configDict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhRenew']['id'];
|
|
|
+ $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
|
|
|
+ $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));//设置订单有效期5分钟
|
|
|
+ $input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
|
|
|
+ $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $merchantExtend = MerchantExtendService::getByMerchantId($this->merchantId);
|
|
|
+ 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);
|
|
|
+ $newParams['orderId'] = $orderId;
|
|
|
+ $newParams['merchantId'] = $merchantId;
|
|
|
+ util::success($newParams);
|
|
|
+ }
|
|
|
+
|
|
|
}
|