shish 5 лет назад
Родитель
Сommit
376ab2800d

+ 8 - 7
app-hd/controllers/NoticeController.php

@@ -4,6 +4,7 @@ namespace hd\controllers;
 
 use biz\recharge\classes\RechargeClass;
 use bizHd\order\classes\OrderClass;
+use bizHd\purchase\classes\PurchaseClass;
 use common\components\dict;
 use Yii;
 use common\components\util;
@@ -40,7 +41,7 @@ class NoticeController extends PublicController
 
         $wxPay = dict::getDict('payWay', 'wxPay');
         //支付成功后续流程
-        $this->_thirdPayOk($wxPay, $capitalType, $orderSn, $totalFee, $attach);
+        $this->_thirdPay($wxPay, $capitalType, $orderSn, $totalFee, $attach);
 
         echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
     }
@@ -121,24 +122,24 @@ class NoticeController extends PublicController
 
             $aliPay = dict::getDict('payWay', 'alipay');
             //支付成功后续流程
-            $this->_thirdPayOk($aliPay, $capitalType, $orderSn, $totalFee, $attach);
+            $this->_thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach);
 
         }
         //请不要修改
         echo "success";
     }
 
-    public function _thirdPayOk($payWay, $capitalType, $orderSn, $totalFee, $attach)
+    public function _thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach)
     {
         //流水类型列表
         switch ($capitalType) {
             case dict::getDict('capitalType', 'xhRecharge', 'id'):
                 //充值
-                RechargeClass::thirdPayOk($payWay, $capitalType, $orderSn, $totalFee, $attach);
+                RechargeClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
                 break;
-            case dict::getDict('capitalType', 'xhOrder', 'id'):
-                //购买商品
-                OrderClass::thirdPayOk($payWay, $capitalType, $orderSn, $totalFee, $attach);
+            case dict::getDict('capitalType', 'xhPurchase', 'id'):
+                //采购订单
+                PurchaseClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
                 break;
             default:
         }

+ 3 - 3
app-hd/controllers/PurchaseController.php

@@ -55,7 +55,7 @@ class PurchaseController extends BaseController
     {
         $get = Yii::$app->request->get();
         $orderSn = $get['orderSn'] ?? 0;
-        $info = PurchaseClass::getByCondition(['orderSn' => $orderSn]);
+        $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
         PurchaseClass::valid($info, $this->shopId);
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
@@ -79,7 +79,7 @@ class PurchaseController extends BaseController
         if (password_verify($password, $admin['payPassword']) == false) {
             util::fail('密码错误');
         }
-        $info = PurchaseClass::getByCondition(['orderSn' => $orderSn]);
+        $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
         if (empty($info)) {
             util::fail('没有找到采购单');
         }
@@ -160,7 +160,7 @@ class PurchaseController extends BaseController
         //强制使用小程序的miniOpenId
         $openId = $this->admin['miniOpenId'];
 
-        $purchaseCapital = dict::getDict('capitalType','xhPurchase','id');
+        $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
         //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
         $wxPayType = 0;
         if (httpUtil::isMiniProgram()) {

+ 59 - 78
biz-hd/purchase/classes/PurchaseClass.php

@@ -7,6 +7,7 @@ use biz\ghs\models\Ghs;
 use biz\shop\models\Shop;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\order\classes\OrderClass;
+use common\components\dict;
 use common\components\orderSn;
 use common\components\util;
 use bizHd\base\classes\BaseClass;
@@ -131,95 +132,93 @@ class PurchaseClass extends BaseClass
     //订单延期支付 ssh 2021.1.24
     public static function debt($info)
     {
-        if (isset($info['status']) == false || $info['status'] != self::STATUS_UN_PAY) {
-            util::fail('订单不是待付款状态');
-        }
-        $id = $info['id'] ?? 0;
-        $data = [
-            'status' => self::STATUS_UN_SEND,
-            'debt' => 1,
-        ];
-        self::updateById($id, $data);
+        $payWay = dict::getDict('payWay', 'debtPay');
+        self::complete($info, $payWay);
+    }
 
-        $shopId = $info['shopId'] ?? 0;
-        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        $actPrice = $info['actPrice'];
-        $shop->totalPurchase = bcadd($shop->totalPurchase, $actPrice, 2);
-        $shop->totalPurchaseOrder += 1;
-        $shop->save();
-        $ghsId = $info['ghsId'] ?? 0;
-        $ghs = Ghs::findBySql('select * from ' . Ghs::tableName() . ' where id = :id for update', ['id' => $ghsId])->one();
-        if (empty($ghs)) {
-            util::fail('没有找到供货商');
-        }
-        $ghs->debt = 2;
-        $ghs->debtAmount = bcadd($ghs->debtAmount, $actPrice, 2);
-        $ghs->debtNum += 1;
-        $ghs->expendAmount = bcadd($ghs->expendAmount, $actPrice, 2);
-        $ghs->expendNum += 1;
-        $ghs->save();
+    //余额支付 ssh 2021.1.24
+    public static function balancePay($info)
+    {
+        $payWay = dict::getDict('payWay', 'balancePay');
+        self::complete($info, $payWay);
+    }
 
-        $ghsOrderId = $info['ghsOrderId'] ?? 0;
-        $cg = OrderClass::getById($ghsOrderId, true);
-        if (empty($cg)) {
-            util::fail('没有找到对应供货商订单');
+    //检查采购单
+    public static function valid($info, $shopId)
+    {
+        if (empty($info)) {
+            util::fail('没有找到采购单');
         }
-        $cg->status = OrderClass::ORDER_STATUS_UN_SEND;
-        $cg->save();
-        $shopId = $cg->shopId;
-        $actPrice = $cg->actPrice;
-        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
-        if (empty($shop)) {
-            util::fail('没有找到供货商门店');
+        if (isset($info->shopId) && $info->shopId == $shopId) {
+            return true;
         }
-        $shop->totalIncome = bcadd($shop->totalIncome, $actPrice, 2);
-        $shop->totalOrderNum += 1;
-        $shop->save();
+        util::fail('没有权限操作');
+    }
 
+    //采购订单支付成功后回调处理流程
+    public static function thirdPay($payWay, $orderSn, $totalFee, $attach)
+    {
+        $info = self::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($info)) {
+            util::fail('没有找到订单');
+        }
+        $info->actPirce
+        self::complete($info, $payWay);
     }
 
-    //余额支付 ssh 2021.1.24
-    public static function balancePay($info)
+    //第三方支付、余额支付和欠款支付后调用的流程 shish 2021.4.27
+    public static function complete($info, $payWay)
     {
-        if (isset($info['status']) == false || $info['status'] != self::STATUS_UN_PAY) {
+        if (empty($info)) {
+            util::fail('没有找到订单');
+        }
+        if (isset($info->status) == false || $info->status != self::STATUS_UN_PAY) {
             util::fail('订单不是待付款状态');
         }
-        $id = $info['id'] ?? 0;
-        $data = [
-            'status' => self::STATUS_UN_SEND,
-        ];
-        self::updateById($id, $data);
+        $info->payWay = $payWay;
+        $info->status = self::STATUS_UN_SEND;
+
+        //欠款支付
+        if ($payWay == dict::getDict('payWay', 'debtPay')) {
+            $info->debt = 1;
+        }
+        $info->save();
 
         $shopId = $info['shopId'] ?? 0;
         $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
-        $actPrice = $info['actPrice'];
+        $actPrice = $info->actPrice;
         $shop->totalPurchase = bcadd($shop->totalPurchase, $actPrice, 2);
         $shop->totalPurchaseOrder += 1;
         $shop->save();
-        $ghsId = $info['ghsId'] ?? 0;
+        $ghsId = $info->ghsId ?? 0;
         $ghs = Ghs::findBySql('select * from ' . Ghs::tableName() . ' where id = :id for update', ['id' => $ghsId])->one();
         if (empty($ghs)) {
             util::fail('没有找到供货商');
         }
+
+        //欠款支付
+        if ($payWay == dict::getDict('payWay', 'debtPay')) {
+            $ghs->debt = 2;
+            $ghs->debtAmount = bcadd($ghs->debtAmount, $actPrice, 2);
+            $ghs->debtNum += 1;
+        }
+
         $ghs->expendAmount = bcadd($ghs->expendAmount, $actPrice, 2);
         $ghs->expendNum += 1;
         $ghs->save();
 
-        $ghsOrderId = $info['ghsOrderId'] ?? 0;
-        $cg = OrderClass::getById($ghsOrderId, true);
-        if (empty($cg)) {
+        $ghsOrderId = $info->ghsOrderId ?? 0;
+        $ghsOrder = OrderClass::getById($ghsOrderId, true);
+        if (empty($ghsOrder)) {
             util::fail('没有找到对应供货商订单');
         }
-        $cg->status = OrderClass::ORDER_STATUS_UN_SEND;
-        $cg->save();
-        $shopId = $cg->shopId;
-        $actPrice = $cg->actPrice;
+        $ghsOrder->status = OrderClass::ORDER_STATUS_UN_SEND;
+        $ghsOrder->save();
+        $shopId = $ghsOrder->shopId;
+        $actPrice = $ghsOrder->actPrice;
         $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
         if (empty($shop)) {
             util::fail('没有找到供货商门店');
@@ -229,22 +228,4 @@ class PurchaseClass extends BaseClass
         $shop->save();
     }
 
-    //检查采购单
-    public static function valid($info, $shopId)
-    {
-        if (empty($info)) {
-            util::fail('没有找到采购单');
-        }
-        if (isset($info['shopId']) && $info['shopId'] == $shopId) {
-            return true;
-        }
-        util::fail('没有权限操作');
-    }
-
-    //采购订单支付成功后回调处理流程
-    public static function complete($purchase)
-    {
-
-    }
-
 }

+ 25 - 1
biz/recharge/classes/RechargeClass.php

@@ -31,8 +31,9 @@ class RechargeClass extends BaseClass
     }
 
     //处理充值流程 ssh 2021.2.21
-    public static function complete($recharge, $rechargeRenew = 0)
+    public static function complete($recharge, $payWay, $rechargeRenew = 0)
     {
+        $recharge->payWay = $payWay;
         $recharge->payStatus = self::PAY_STATUS_HAS_PAY;
         $recharge->save();
         $orderSn = $recharge->orderSn;
@@ -51,4 +52,27 @@ class RechargeClass extends BaseClass
         }
     }
 
+    //第三支付后流程 shish 2021.4.27
+    public static function thirdPay($payWay, $orderSn, $totalFee, $attach)
+    {
+        $recharge = RechargeClass::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($recharge)) {
+            noticeUtil::push('充值付款成功,收到回调,但没有找到充值记录,orderSn:' . $orderSn, '15280215347');
+            return false;
+        }
+        if ($totalFee != $recharge->amount) {
+            noticeUtil::push("充值付款成功,收到回调,但金额不一致 {$totalFee} {$recharge->amount},orderSn:" . $orderSn, '15280215347');
+            return false;
+        }
+        if ($recharge->payStatus == RechargeClass::PAY_STATUS_HAS_PAY) {
+            noticeUtil::push("充值付款成功,收到回调,但订单是已经支付过了,orderSn:" . $orderSn, '15280215347');
+            return false;
+        }
+        parse_str($attach);
+        //是否充值免费续期
+        $rechargeRenew = isset($rechargeRenew) ? $rechargeRenew : 0;
+        //处理充值成功的流程
+        self::complete($recharge, $payWay, $rechargeRenew);
+    }
+
 }

+ 3 - 4
common/components/dict.php

@@ -11,7 +11,6 @@ class dict
 
         'expressList' => [
             [
-
                 "id" => 1,
                 "deliveryId" => "dada",
                 "deliveryName" => "达达"
@@ -33,9 +32,9 @@ class dict
         'riseType' => ['noRise' => 0, 'percent' => 1, 'amount' => 2,],
         'riseTypeName' => [0 => '不涨价', 1 => '按百分比', 2 => '按金额'],
 
-        'payWay' => ['wxPay' => 0, 'alipay' => 1, 'balancePay' => 2],
-        'payWayName' => [0 => '微信', 1 => '支付宝', 2 => '余额'],
-        'payWayFullName' => [0 => '微信支付', 1 => '支付宝', 2 => '余额支付'],
+        'payWay' => ['wxPay' => 0, 'alipay' => 1, 'balancePay' => 2, 'debtPay' => 3],
+        'payWayName' => [0 => '微信', 1 => '支付宝', 2 => '余额', 3 => '欠款'],
+        'payWayFullName' => [0 => '微信支付', 1 => '支付宝', 2 => '余额支付', 3 => '欠款支付'],
 
         //后台支付方式选项
         'htPayWayOption' => [

+ 2 - 1
sql.sql

@@ -2260,4 +2260,5 @@ ALTER TABLE `xhPurchase` MODIFY `shopId` INT(11) UNSIGNED NOT NULL DEFAULT '0' C
 ALTER TABLE `xhGhsPurchaseOrder` MODIFY `shopId` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '门店ID' AFTER `merchantId`;
 ALTER TABLE xhGhsOrder ADD cgId INT NOT NULL DEFAULT 0 COMMENT '采购单id' AFTER `id`;
 ALTER TABLE `xhGhsOrder` CHANGE `cgId` `hdOrderId` INT NOT NULL DEFAULT 0 COMMENT '花店订单id';
-ALTER TABLE `xhPurchase` ADD ghsOrderId INT NOT NULL DEFAULT 0 COMMENT '供货商订单id' AFTER `orderSn`;
+ALTER TABLE `xhPurchase` ADD ghsOrderId INT NOT NULL DEFAULT 0 COMMENT '供货商订单id' AFTER `orderSn`;
+ALTER TABLE `xhPurchase` ADD payWay TINYINT NOT NULL DEFAULT 0 COMMENT '支付方式,选项查看dict文件' AFTER `orderSn`;