shish 5 anni fa
parent
commit
ceb2fa90c1

+ 1 - 1
app-hd/controllers/OrderController.php

@@ -32,7 +32,7 @@ class OrderController extends BaseController
 
     public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
 
-    //商城下单操作 ssh 2019.12.3
+    //单操作 ssh 2019.12.3
     public function actionCreateOrder()
     {
         $post = Yii::$app->request->post();

+ 3 - 2
app-hd/controllers/PxApplyController.php

@@ -5,6 +5,7 @@ namespace hd\controllers;
 use bizHd\custom\classes\CustomClass;
 use bizHd\px\classes\PxApplyClass;
 use bizHd\px\classes\PxClassClass;
+use bizHd\px\services\PxApplyService;
 use common\components\util;
 use Yii;
 
@@ -35,9 +36,9 @@ class PxApplyController extends BaseController
         $get['className'] = $info['name'] ?? '';
         $get['classCover'] = $info['cover'] ?? '';
         $get['applyTime'] = date("Y-m-d H:i:s");
-        $get['status'] = PxApplyClass::STATUS_CONFIRM;
+        $get['status'] = PxApplyClass::STATUS_UN_CONFIRM;
 
-        PxApplyClass::addApply($get, $this->shop);
+        PxApplyService::addBmPx($get);
         util::complete();
     }
 

+ 1 - 1
app-mall/controllers/PxApplyController.php

@@ -40,7 +40,7 @@ class PxApplyController extends BaseController
         $get['applyTime'] = date("Y-m-d H:i:s");
         $get['status'] = PxApplyClass::STATUS_UN_CONFIRM;
 
-        $respond = PxApplyClass::addApply($get, $this->shop);
+        $respond = \bizHd\px\classes\PxApplyClass::addApply($get, true);
         util::success($respond);
     }
 

+ 1 - 1
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -169,7 +169,7 @@ class PurchaseOrderClass extends BaseClass
 
             //支出流水
             $payWay = dict::getDict('payWay', 'unknown');
-            $capitalType = dict::getDict('capitalType', 'ghsPurchase');
+            $capitalType = dict::getDict('capitalType', 'ghsPurchase', 'id');
             $sjId = $order['merchantId'] ?? 0;
             $shopId = $order['shopId'] ?? 0;
             $event = '采购支出';

+ 34 - 4
biz-hd/order/classes/OrderClass.php

@@ -5,6 +5,7 @@ namespace bizHd\order\classes;
 use biz\goods\classes\GoodsClass;
 use biz\goods\models\Goods;
 use biz\shop\classes\ShopAdminClass;
+use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
 use biz\shop\models\Shop;
 use biz\stat\classes\StatOrderCountClass;
@@ -206,13 +207,43 @@ class OrderClass extends BaseClass
         $orderSn = $order->orderSn;
         OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $current, 'orderSn' => $orderSn]);
 
+        $actPrice = $order->actPrice ?? 0;
         $shopId = $order->shopId;
         $shop = ShopClass::getLockById($shopId);
+        if (empty($shop)) {
+            Yii::info("没有找到门店 OrderClass::complete() orderId:{$order->id}");
+            util::fail('没有找到门店');
+        }
         $shop->unSendOrder += 1;
         $shop->unPayOrder -= 1;
+        $currentTotalIncome = bcadd($shop->totalIncome, $actPrice, 2);
+        $shop->totalIncome = $currentTotalIncome;
         $shop->save();
 
-        //付款订单会存在没有商品的情况
+        $shopAdminId = $order->shopAdminId ?? 0;
+        $shopAdminName = $order->shopAdminName ?? '';
+        $sjId = $order->merchantId;
+        $event = '客户下单';
+        if (!empty($shopAdminId)) {
+            $event = '员工开单';
+        }
+        $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
+        $capital = [
+            'capitalType' => $capitalType,
+            'relateId' => $orderId,
+            'io' => 1,
+            'totalIncome' => $currentTotalIncome,
+            'payWay' => $payWay,
+            'event' => $event,
+            'sjId' => $sjId,
+            'shopId' => $shopId,
+            'shopAdminId' => $shopAdminId,
+            'shopAdminName' => $shopAdminName,
+        ];
+        ShopCapitalClass::addCapital($capital);
+
+
+        //二维码收款订单存在没有商品的情况
         if (!empty($orderGoods)) {
             // 扣库存
             self::decGoodsStock($orderGoods);
@@ -221,10 +252,10 @@ class OrderClass extends BaseClass
         }
 
         if (isset($order->shopAdminId) == false) {
-            util::fail('没有员工信息');
+            util::fail('没有员工字段');
         }
         if (isset($order->fromType) == false) {
-            util::fail('没有来源信息');
+            util::fail('没有来源字段');
         }
 
         if (!empty($order->shopAdminId)) {
@@ -240,7 +271,6 @@ class OrderClass extends BaseClass
                 $amount = $order->actPrice;
                 ShopClass::customKdAddBalance($shop, $amount, $order, $capitalType);
             }
-
             //门店和朋友圈订单并且没有填写收花人的直接将订单置为自取并且是完成状态
             if (in_array($order->fromType, [dict::getDict("fromType", "shop"), dict::getDict("fromType", "friend")])) {
                 if (isset($order->receiveMobile) && isset($order->address)) {

+ 48 - 25
biz-hd/px/classes/PxApplyClass.php

@@ -4,14 +4,13 @@ namespace bizHd\px\classes;
 
 use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
-use biz\sj\classes\SjCapitalClass;
-use bizHd\custom\classes\CustomClass;
 use bizHd\stat\classes\StatStudentClass;
 use common\components\dict;
 use common\components\imgUtil;
+use bizHd\base\classes\BaseClass;
 use common\components\orderSn;
+use common\components\util;
 use Yii;
-use bizHd\base\classes\BaseClass;
 
 class PxApplyClass extends BaseClass
 {
@@ -23,30 +22,10 @@ class PxApplyClass extends BaseClass
     //已付款
     const  STATUS_CONFIRM = 2;
 
-    //培训报名 ssh 2021.3.17
-    public static function addApply($data, $shop)
+    public static function addApply($data, $returnObj = false)
     {
         $data['orderSn'] = orderSn::getPxApplySn();
-        StatStudentClass::addStudent($shop);
-        $shopId = $shop['id'];
-        $totalIncome = bcadd($shop['totalIncome'], $data['actPrice'], 2);
-        ShopClass::updateById($shopId, ['totalIncome' => $totalIncome]);
-        $capitalType = dict::getDict('capitalType', 'pxApply', 'id');
-        $payWay = $data['payWay'] ?? 0;
-        $sjId = $shop['merchantId'] ?? 0;
-        $shopId = $shop['id'] ?? 0;
-        $capitalData = [
-            'capitalType' => $capitalType,
-            'io' => 1,
-            'totalIncome' => $totalIncome,
-            'payWay' => $payWay,
-            'amount' => $data['actPrice'],
-            'sjId' => $sjId,
-            'shopId' => $shopId,
-        ];
-        ShopCapitalClass::addCapital($capitalData);
-
-        return self::add($data);
+        return PxApplyClass::add($data, $returnObj);
     }
 
     //学员管理 ssh 2021.3.17
@@ -78,4 +57,48 @@ class PxApplyClass extends BaseClass
         return $list;
     }
 
+    //订单完成 shish 20210523
+    public static function complete($order, $payWay)
+    {
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if (isset($order->status) == false || $order->status != self::STATUS_UN_CONFIRM) {
+            util::fail('订单不是待确认状态');
+        }
+        $order->status = self::STATUS_CONFIRM;
+        $order->payWay = $payWay;
+        $order->save();
+
+        $actPrice = $order->actPrice ?? 0;
+        $shopId = $order->shopId;
+        $shop = ShopClass::getLockById($shopId);
+        if (empty($shop)) {
+            Yii::info("没有找到门店 PxApplyClass::complete() orderId:{$order->id}");
+            util::fail('没有找到门店');
+        }
+        $currentTotalIncome = bcadd($shop->totalIncome, $actPrice, 2);
+        $shop->totalIncome = $currentTotalIncome;
+        $shop->studentNum += 1;
+        $shop->save();
+
+        $capitalType = dict::getDict('capitalType', 'pxApply', 'id');
+        $sjId = $order->sjId ?? 0;
+        $shopId = $order->shopId ?? 0;
+        $event = '学员报名';
+        $capitalData = [
+            'capitalType' => $capitalType,
+            'io' => 1,
+            'totalIncome' => $currentTotalIncome,
+            'payWay' => $payWay,
+            'amount' => $actPrice,
+            'sjId' => $sjId,
+            'shopId' => $shopId,
+            'event' => $event,
+        ];
+        ShopCapitalClass::addCapital($capitalData);
+        //增加新学员数量
+        StatStudentClass::addStudent($shop);
+    }
+
 }

+ 1 - 1
biz-hd/px/models/PxApply.php

@@ -9,7 +9,7 @@ class PxApply extends Base
 
 	public static function tableName()
 	{
-		return 'xhPxApply';
+		return 'xhPxBm';
 	}
 
 }

+ 1 - 1
biz-hd/px/models/PxApplySn.php

@@ -9,7 +9,7 @@ class PxApplySn extends Base
 
 	public static function tableName()
 	{
-		return 'xhPxApplySn';
+		return 'xhPxBmSn';
 	}
 
 }

+ 31 - 1
biz-hd/px/services/PxApplyService.php

@@ -3,11 +3,41 @@
 namespace bizHd\px\services;
 
 use bizHd\base\services\BaseService;
+use bizHd\px\classes\PxApplyClass;
+use common\components\dict;
+use common\components\orderSn;
+use common\components\util;
 use Yii;
 
 class PxApplyService extends BaseService
 {
 
-	public static $baseFile = '\bizHd\retail\classes\PxApplyClass';
+    public static $baseFile = '\bizHd\retail\classes\PxApplyClass';
+
+    //新增报名成功 ssh 2021.3.17
+    public static function addBmPx($data)
+    {
+        $order = PxApplyClass::addApply($data, true);
+        $payWay = dict::getDict('payWay', 'unknown');
+        PxApplyClass::complete($order, $payWay);
+        return $order;
+    }
+
+    //培训报名 shish 20210523
+    public static function thirdPay($payWay, $orderSn, $totalFee, $attach)
+    {
+        $order = self::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($order)) {
+            $msg = "没有找到报名订单 orderSn:{$orderSn}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        if ($order->actPrice != $totalFee) {
+            $msg = "报名订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->actPrice} {$totalFee}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        PxApplyClass::complete($order, $payWay);
+    }
 
 }

+ 0 - 29
biz-mall/px/classes/PxApplyClass.php

@@ -21,35 +21,6 @@ class PxApplyClass extends BaseClass
     const  STATUS_UN_CONFIRM = 1;
     const  STATUS_CONFIRM = 2;
 
-    //培训报名 ssh 2021.3.17
-    public static function addApply($data, $shop)
-    {
-        $data['orderSn'] = orderSn::getPxApplySn();
-
-        StatStudentClass::addStudent($shop);
-
-        $shopId = $shop['id'];
-        $totalIncome = bcadd($shop['totalIncome'], $data['actPrice'], 2);
-        ShopClass::updateById($shopId, ['totalIncome' => $totalIncome]);
-
-        $capitalType = dict::getDict('capitalType', 'pxApply', 'id');
-        $payWay = $data['payWay'] ?? 0;
-        $sjId = $shop['merchantId'] ?? 0;
-        $shopId = $shop['id'] ?? 0;
-        $capitalData = [
-            'capitalType' => $capitalType,
-            'io' => 1,
-            'totalIncome' => $totalIncome,
-            'payWay' => $payWay,
-            'amount' => $data['actPrice'],
-            'sjId' => $sjId,
-            'shopId' => $shopId,
-        ];
-        // ShopCapitalClass::addCapital($capitalData);
-
-        return self::add($data);
-    }
-
     //学员管理 ssh 2021.3.17
     public static function getApplyList($where)
     {

+ 1 - 1
biz-mall/px/models/PxApply.php

@@ -9,7 +9,7 @@ class PxApply extends Base
 
 	public static function tableName()
 	{
-		return 'xhPxApply';
+		return 'xhPxBm';
 	}
 
 }

+ 2 - 2
biz-mall/px/models/PxApplySn.php

@@ -9,7 +9,7 @@ class PxApplySn extends Base
 
 	public static function tableName()
 	{
-		return 'xhPxApplySn';
+		return 'xhPxBmSn';
 	}
 
-}
+}

+ 6 - 0
common/components/payUtil.php

@@ -7,6 +7,8 @@ use biz\renew\classes\RenewClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\purchase\classes\PurchaseClearClass;
 use bizHd\purchase\services\PurchaseService;
+use bizHd\px\classes\PxApplyClass;
+use bizHd\px\services\PxApplyService;
 use Yii;
 
 class payUtil
@@ -40,6 +42,10 @@ class payUtil
                     //零售和供货商续费订单
                     RenewClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
                     break;
+                case dict::getDict('capitalType', 'pxApply', 'id'):
+                    //培训报名
+                    PxApplyService::thirdPay($payWay, $orderSn, $totalFee, $attach);
+                    break;
                 default:
             }
             $transaction->commit();