Sfoglia il codice sorgente

采购微信支付

shish 5 anni fa
parent
commit
84561b11f8
3 ha cambiato i file con 81 aggiunte e 9 eliminazioni
  1. 69 0
      app-hd/controllers/PurchaseController.php
  2. 7 8
      biz/item/classes/PtItemClass.php
  3. 5 1
      sql.sql

+ 69 - 0
app-hd/controllers/PurchaseController.php

@@ -6,6 +6,9 @@ use biz\ghs\classes\GhsClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\services\PurchaseService;
 use bizGhs\product\classes\ProductClass;
+use bizHd\wx\classes\WxOpenClass;
+use common\components\dict;
+use common\components\httpUtil;
 use Yii;
 use common\components\util;
 
@@ -117,4 +120,70 @@ class PurchaseController extends BaseController
         util::success($respond);
     }
 
+    //微信支付 shish 2021.4.11
+    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 = PurchaseClass::getByCondition(['orderSn' => $orderSn]);
+        if (empty($order)) {
+            util::fail('订单号无效');
+        }
+        $id = $order['id'];
+
+        $name = $orderSn;
+        $totalFee = $order['actPrice'];
+
+        //强制使用小程序的miniOpenId
+        $openId = $this->admin['miniOpenId'];
+
+        $typeList = dict::getConfig('capitalType');
+        $capitalType = $typeList['xhPurchase']['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];
+        PurchaseClass::updateById($id, $updateData);
+        util::success($newParams);
+    }
+
 }

+ 7 - 8
biz/item/classes/PtItemClass.php

@@ -134,12 +134,12 @@ class PtItemClass extends BaseClass
             }
             $upData['cover'] = $data['cover'];
         }
-        if (isset($data['alias'])) {
-            if (empty($data['alias'])) {
-                util::fail("请输入花材别名");
-            }
-            $upData['alias'] = $data['alias'];
-        }
+//        if (isset($data['alias'])) {
+//            if (empty($data['alias'])) {
+//                util::fail("请输入花材别名");
+//            }
+//            $upData['alias'] = $data['alias'];
+//        }
         if (isset($data['cost'])) {
             if (empty($data['cost'])) {
                 util::fail("请输入花材成本价");
@@ -213,8 +213,7 @@ class PtItemClass extends BaseClass
             return $list;
         }
         foreach ($list as $key => $val) {
-            $list[$key]['shortCover'] = $val['cover'];
-            $list[$key]['cover'] = imgUtil::groupImg($val['cover']);
+            $list[$key]['coverUrl'] = imgUtil::groupImg($val['cover']);
         }
         return $list;
     }

+ 5 - 1
sql.sql

@@ -2045,7 +2045,7 @@ CREATE TABLE `xhGoodsItem` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='成品对应的花材';
 
 
-=====linqh 2021.4.11
+=====linqh 2021-4-11
 ==
 ALTER TABLE `xhPtItem`
 MODIFY COLUMN `bigUnit`  varchar(20) NOT NULL DEFAULT '' COMMENT '大单位名称' AFTER `unit`,
@@ -2064,3 +2064,7 @@ MODIFY COLUMN `bigUnit`  varchar(20) NOT NULL DEFAULT '' COMMENT '大单位名
 MODIFY COLUMN `smallUnit`  varchar(20) NOT NULL DEFAULT '' COMMENT '小单位' AFTER `bigUnit`,
 ADD COLUMN `bigUnitId`  smallint(6) NOT NULL DEFAULT 1 COMMENT '大单位ID' AFTER `smallUnit`,
 ADD COLUMN `smallUnitId`  smallint(6) NOT NULL DEFAULT 2 COMMENT '小单位ID' AFTER `bigUnitId`;
+
+====shish 2021-4-11
+ALTER TABLE `xhPurchase` ADD deadline DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '有效期' AFTER `debt`;
+ALTER TABLE xhPurchase ADD changePrice TINYINT NOT NULL DEFAULT 1 COMMENT '1可以修改价格 2不能修改' AFTER `orderSn`;