|
|
@@ -3,38 +3,88 @@
|
|
|
namespace hd\controllers;
|
|
|
|
|
|
use bizHd\purchase\classes\PurchaseClearClass;
|
|
|
+use bizHd\wx\classes\WxOpenClass;
|
|
|
+use common\components\dict;
|
|
|
+use common\components\httpUtil;
|
|
|
use Yii;
|
|
|
use common\components\util;
|
|
|
|
|
|
class PurchaseClearController extends BaseController
|
|
|
{
|
|
|
|
|
|
- //生成结算订单 ssh 2021.1.26
|
|
|
- public function actionCreateOrder()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $ids = $post['id'];
|
|
|
- $data['merchantId'] = $this->sjId;
|
|
|
- $data['id'] = $ids;
|
|
|
- $respond = PurchaseClearClass::addClear($data);
|
|
|
- util::success($respond);
|
|
|
- }
|
|
|
-
|
|
|
- public function actionWxPay()
|
|
|
- {
|
|
|
- $string = '{
|
|
|
- "code": 1,
|
|
|
- "msg": "操作成功",
|
|
|
- "data": {
|
|
|
- "appId": "wx21b7c3ef12082099",
|
|
|
- "nonceStr": "i7f1e9z6ls42f3342m4j2bngxj6rq08e",
|
|
|
- "package": "prepay_id=wx042304351179687ee46ee32d8ecf420000",
|
|
|
- "signType": "MD5",
|
|
|
- "timeStamp": "1612451097",
|
|
|
- "paySign": "39FD249CD03B24FDA1755493F09D7C2E"
|
|
|
+ //生成结算订单 ssh 2021.1.26
|
|
|
+ public function actionCreateOrder()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $ids = $post['id'];
|
|
|
+ $data['merchantId'] = $this->sjId;
|
|
|
+ $data['id'] = $ids;
|
|
|
+ $respond = PurchaseClearClass::addClear($data);
|
|
|
+ util::success($respond);
|
|
|
}
|
|
|
-}';
|
|
|
- echo $string;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ 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 = PurchaseClearClass::getByCondition(['orderSn' => $orderSn]);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('订单号无效');
|
|
|
+ }
|
|
|
+ $id = $order['id'];
|
|
|
+
|
|
|
+ $name = $order['orderName'] ?? '购买商品';
|
|
|
+ $totalFee = $order['actPrice'];
|
|
|
+
|
|
|
+ //强制使用小程序的miniOpenId
|
|
|
+ $openId = $this->admin['miniOpenId'];
|
|
|
+
|
|
|
+ $typeList = dict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhGhsOrder']['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['hdHost'] . '/notice/wx-callback/');
|
|
|
+ $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $merchantExtend = WxOpenClass::getWxInfo();
|
|
|
+ if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
|
|
|
+ $input->SetSub_openid($openId);
|
|
|
+ } else {
|
|
|
+ $input->SetOpenid($openId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //强制使用小程序的miniAppId
|
|
|
+ $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
+
|
|
|
+ $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
+ $tools = new \JsApiPay();
|
|
|
+ $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
+ $newParams = json_decode($jsApiParameters, true);
|
|
|
+ $current = date("Y-m-d H:i:s");
|
|
|
+ $updateData = ['deadline' => $current, 'changePrice' => 2];
|
|
|
+ PurchaseClearClass::updateById($id, $updateData);
|
|
|
+ util::success($newParams);
|
|
|
+ }
|
|
|
+
|
|
|
}
|