Преглед изворни кода

充值成功余额要增加

shish пре 5 година
родитељ
комит
957df823fe

+ 6 - 11
app/shop/controllers/OrderController.php

@@ -17,16 +17,12 @@ use common\services\xhPayToolService;
 use Yii;
 use common\components\util;
 use common\components\stringUtil;
-use biz\goods\services\CategoryService;
-use biz\goods\services\GoodsCategoryService;
 use biz\goods\services\GoodsService;
 use biz\merchant\services\ExpressService;
 use biz\order\services\OrderGoodsService;
 use biz\promote\services\CouponService;
-use biz\user\services\UserAssetService;
 use common\components\httpUtil;
-use common\components\miniUtil;
-use yii\web\Controller;
+
 
 class OrderController extends BaseController
 {
@@ -162,13 +158,13 @@ class OrderController extends BaseController
 			if (empty($product)) {
 				util::fail('请选择花材');
 			}
-			$totalPrice = 0;
+            $actPrice = 0;
 			$orderProduct = [];
 			foreach ($product as $key => $val) {
 				$productId = $val['productId'];
 				$bigNum = $val['bigNum'];
 				$smallNum = $val['smallNum'];
-				$totalPrice += 2;
+                $actPrice += 2;
 				$orderProduct[] = [
 					'productId' => $productId,
 					'bigNum' => $bigNum,
@@ -176,8 +172,8 @@ class OrderController extends BaseController
 				];
 			}
 
-			$post['prePrice'] = $totalPrice;
-			$post['actPrice'] = $totalPrice;
+			$post['prePrice'] = $actPrice;
+			$post['actPrice'] = $actPrice;
 			$order = OrderClass::addOrder($post);
 			$orderId = $order['id'];
 			$orderSn = $order['orderSn'];
@@ -186,9 +182,8 @@ class OrderController extends BaseController
 				$val['orderSn'] = $orderSn;
 				OrderItemClass::add($val);
 			}
-	
-		}
 
+		}
 		util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
 	}
 	

+ 103 - 0
app/shop/controllers/RechargeController.php

@@ -0,0 +1,103 @@
+<?php
+
+namespace shop\controllers;
+
+use biz\merchant\classes\MerchantClass;
+use biz\recharge\classes\RechargeClass;
+use biz\wx\classes\WxOpenClass;
+use common\components\configDict;
+use common\components\httpUtil;
+use common\components\util;
+use Yii;
+
+class RechargeController extends BaseController
+{
+
+    //免费续期活动 shish 2021.2.21
+    public function actionRenew()
+    {
+        $data = [
+            'renew' => 3980,
+            'recharge' => 5980,
+            'shopName' => '纯彩花艺',
+            'userNum' => 150,
+            'userAvatar' => [
+                Yii::$app->params['imgHost'] . '/hhb_small.png',
+                Yii::$app->params['imgHost'] . '/hhb_small.png',
+            ],
+        ];
+        util::success($data);
+    }
+
+    //续期充值付款 shish 2021.2.21
+    public function actionRenewPay()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $wxPay = configDict::getConfig('payWay', 'weixinPay');
+        $data = [
+            'amount' => 5980,
+            'payWay' => $wxPay,
+            'sjId' => $this->sjId,
+            'sjStyle' => MerchantClass::STYLE_RETAIL,
+            'shopId' => $this->shopId,
+            'modPrice' => 0,
+        ];
+        $order = RechargeClass::addOrder($data);
+        $orderSn = $order['orderSn'];
+        $name = $order['orderName'] ?? '充值';
+        $totalFee = $order['amount'];
+
+        //强制使用小程序的miniOpenId
+        $openId = $this->admin['miniOpenId'];
+
+        $capitalTypeData = configDict::getConfig('capitalType');
+        $capitalType = $capitalTypeData['xhRecharge']['id'];
+        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+        $wxPayType = 0;
+        if (httpUtil::isMiniProgram()) {
+            $wxPayType = 1;
+        }
+        $attach = "couponId=0&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['shopHost'] . '/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);
+        }
+
+        //强制使用小程序的AppId
+        $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+
+        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+        $tools = new \JsApiPay();
+        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+        $newParams = json_decode($jsApiParameters, true);
+        util::success($newParams);
+    }
+
+    //续期成功 shish 2021.2.21
+    public function actionRenewSuccess()
+    {
+        $sj = $this->sj;
+        $deadline = date("Y-m-d H:i", strtotime($sj['deadline']));
+        util::success(['deadline' => $deadline]);
+    }
+
+}

+ 1 - 1
biz-ghs/order/models/OrderItem.php

@@ -9,7 +9,7 @@ class OrderItem extends Base
 
     public static function tableName()
     {
-        return 'xhGhsOrderItem';
+        return 'xhOrderItem';
     }
 
 }

+ 20 - 0
biz/recharge/classes/RechargeClass.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace biz\recharge\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\orderSn;
+
+class RechargeClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\recharge\models\Recharge';
+
+    //创建订单 shish 2021.2.21
+    public static function addOrder($data)
+    {
+        $data['orderSn'] = orderSn::getRechargeSn();
+        return self::add($data);
+    }
+
+}

+ 12 - 0
biz/recharge/classes/RechargeSnClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\recharge\classes;
+
+use biz\base\classes\BaseClass;
+
+class RechargeSnClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\recharge\models\RechargeSn';
+
+}

+ 15 - 0
biz/recharge/models/Recharge.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\recharge\models;
+
+use biz\base\models\Base;
+
+class Recharge extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhRecharge';
+    }
+
+}

+ 15 - 0
biz/recharge/models/RechargeSn.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\recharge\models;
+
+use biz\base\models\Base;
+
+class RechargeSn extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhRechargeSn';
+    }
+
+}

+ 12 - 0
biz/recharge/services/RechargeService.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\recharge\services;
+
+use biz\base\services\BaseService;
+
+class RechargeService extends BaseService
+{
+
+    public static $baseFile = '\biz\recharge\classes\RechargeClass';
+
+}

+ 1 - 0
common/components/configDict.php

@@ -97,6 +97,7 @@ class configDict
         "capitalType" => [//流水类型,充值支付回调时的订单类型
             'xhOrder' => ['id' => 0, 'name' => 'xhOrder'],
             'xhActiveOrder' => ['id' => 2, 'name' => 'xhActiveOrder'],
+            //充值
             'xhRecharge' => ['id' => 4, 'name' => 'xhRecharge'],
             //支付宝关联微信帐号,积分累加订单
             'xhUserUnite' => ['id' => 5, 'name' => 'xhUserUnite'],

+ 136 - 119
common/components/orderSn.php

@@ -3,6 +3,7 @@
 namespace common\components;
 
 use biz\purchase\classes\PurchaseClearSnClass;
+use biz\recharge\classes\RechargeSnClass;
 use bizGhs\check\classes\CheckSnClass;
 use bizGhs\order\classes\OrderSnClass;
 use bizGhs\order\classes\PurchaseSnClass;
@@ -12,124 +13,140 @@ use yii\imagine\Image;
 //订单号生成 shish 2021.1.19
 class orderSn
 {
-	
-	//供货商订单号生成 shish 2021.1.19
-	public static function getGhsOrderSn()
-	{
-		$prefix = 'XSD_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'XSD';
-		}
-		$respond = OrderSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('订单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//零售商订单号生成 shish 2021.1.19
-	public static function getOrderSn()
-	{
-		$prefix = 'KD_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'KD';
-		}
-		$respond = \biz\order\classes\OrderSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('订单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//供货商采购单号 shish 2021.1.19
-	public static function getGhsPurchaseSn()
-	{
-		$prefix = 'PH_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'PH';
-		}
-		$respond = PurchaseSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('采购单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//供货商盘点单号 shish 2021.1.19
-	public static function getGhsCheckSn()
-	{
-		$prefix = 'PD_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'PD';
-		}
-		$respond = CheckSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('盘点单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//零售商采购单号 shish 2021.1.19
-	public static function getPurchaseSn()
-	{
-		$prefix = 'CG_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'CG';
-		}
-		$respond = \biz\purchase\classes\PurchaseSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('采购单号没有生成');
-		}
-		return $prefix . $id;
-	}
 
-	//零售商采购单号 shish 2021.1.19
-	public static function getPurchaseClearSn()
-	{
-		$prefix = 'PC_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'PC';
-		}
-		$respond = PurchaseClearSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('单号没有生成');
-		}
-		return $prefix . $id;
-	}
+    //供货商订单号生成 shish 2021.1.19
+    public static function getGhsOrderSn()
+    {
+        $prefix = 'XSD_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'XSD';
+        }
+        $respond = OrderSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('订单号没有生成');
+        }
+        return $prefix . $id;
+    }
 
-	//供货商入库订单号 linqh 2021.1.23
-	public static function getGhsStockInSn()
-	{
-		$prefix = 'RK_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'RK';
-		}
-		$respond = \bizGhs\order\classes\StockInSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('入库单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//供货商出库订单号 linqh 2021.1.23
-	public static function getGhsStockOutSn()
-	{
-		$prefix = 'CK_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'CK';
-		}
-		$respond = \bizGhs\order\classes\StockOutSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('出库单号没有生成');
-		}
-		return $prefix . $id;
-	}
-}
+    //零售商订单号生成 shish 2021.1.19
+    public static function getOrderSn()
+    {
+        $prefix = 'KD_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'KD';
+        }
+        $respond = \biz\order\classes\OrderSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('订单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商采购单号 shish 2021.1.19
+    public static function getGhsPurchaseSn()
+    {
+        $prefix = 'PH_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'PH';
+        }
+        $respond = PurchaseSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('采购单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商盘点单号 shish 2021.1.19
+    public static function getGhsCheckSn()
+    {
+        $prefix = 'PD_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'PD';
+        }
+        $respond = CheckSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('盘点单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //零售商采购单号 shish 2021.1.19
+    public static function getPurchaseSn()
+    {
+        $prefix = 'CG_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'CG';
+        }
+        $respond = \biz\purchase\classes\PurchaseSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('采购单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //零售商采购单号 shish 2021.1.19
+    public static function getPurchaseClearSn()
+    {
+        $prefix = 'PC_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'PC';
+        }
+        $respond = PurchaseClearSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商入库订单号 linqh 2021.1.23
+    public static function getGhsStockInSn()
+    {
+        $prefix = 'RK_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'RK';
+        }
+        $respond = \bizGhs\order\classes\StockInSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('入库单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商出库订单号 linqh 2021.1.23
+    public static function getGhsStockOutSn()
+    {
+        $prefix = 'CK_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'CK';
+        }
+        $respond = \bizGhs\order\classes\StockOutSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('出库单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //充值单号 shish 2021.2.20
+    public static function getRechargeSn()
+    {
+        $prefix = 'CZ_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'CZ';
+        }
+        $respond = RechargeSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('充值单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+}

+ 12 - 3
common/services/xhPayToolService.php

@@ -57,9 +57,15 @@ class xhPayToolService
         return self::basePay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay);
     }
 
-    public static function ghsOrderPay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams)
+    public static function ghsOrderPay($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams)
     {
+        $transaction->commit();
+    }
 
+    //充值回调处理 shish 2021.2.21
+    public static function recharge($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams)
+    {
+        $transaction->commit();
     }
 
     /**
@@ -75,6 +81,10 @@ class xhPayToolService
             $capitalTypeList = configDict::getConfig('capitalType');//流水类型列表
             $order = [];
             switch ($capitalType) {
+                case $capitalTypeList['xhRecharge']['id']:
+                    return self::recharge($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
+                    Yii::$app->end();
+                    break;
                 case $capitalTypeList['xhOrder']['id']:
                     //购买商品
                     $order = xhOrderService::getByOrderSn($orderSn);
@@ -88,10 +98,9 @@ class xhPayToolService
                     break;
                 case $capitalTypeList['xhGhsOrder']['id']:
                     //供货商订单
-                    return self::ghsOrderPay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
+                    return self::ghsOrderPay($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
                     Yii::$app->end();
                     break;
-
                 default:
                     Yii::warning('获取订单信息失败,回调传过来的 capitalType 不符合要求,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
                     util::fail('订单流水类型不明确');

+ 22 - 1
sql.sql

@@ -1156,4 +1156,25 @@ CREATE TABLE IF NOT EXISTS `xhOrderItem`(
   `bigNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '大单位数量,扎,包,箱',
   `smallNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '小单位数量,支,个,条',
   `ratio` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '大小单位转换比例,1扎多少支,1包多少支'
-)COMMENT='零售订单的花材';
+)COMMENT='零售订单的花材';
+DROP TABLE IF EXISTS `xhRecharge`;
+CREATE TABLE IF NOT EXISTS `xhRecharge`(
+id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+`payWay` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '支付方式 0微信 1支付宝 2余额',
+`payCode` VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '支付返回号',
+sjId INT NOT NULL DEFAULT 0 COMMENT '商家id',
+sjStyle TINYINT NOT NULL DEFAULT 1 COMMENT '商家类型 1零售 2供货',
+shopId INT NOT NULL DEFAULT 0 COMMENT '门店id',
+`amount` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '金额',
+`balance` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '余额',
+`totalRecharge` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '门店累计充值'
+)COMMENT='门店充值记录';
+DROP TABLE IF EXISTS `xhRechargeSn`;
+CREATE TABLE IF NOT EXISTS `xhRechargeSn` (
+  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`id`)
+) AUTO_INCREMENT=18213721 COMMENT='充值订单号';
+ALTER TABLE xhRecharge ADD orderSn CHAR(20) NOT NULL DEFAULT '' COMMENT '订单编号' AFTER `id`;
+ALTER TABLE `xhRecharge` ADD `modPrice` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '0不能修改价格 1可以修改' AFTER `orderSn`;
+ALTER TABLE `xhRecharge` ADD `deadline` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '订单有效时间' AFTER `modPrice`;
+ALTER TABLE xhRecharge ADD payStatus TINYINT NOT NULL DEFAULT 1 COMMENT '1待付款 2已付款' AFTER `totalRecharge`;