shish пре 1 година
родитељ
комит
67a6cc26f7

+ 5 - 0
app-hd/controllers/RechargeController.php

@@ -9,6 +9,7 @@ use biz\shop\classes\ShopClass;
 use biz\sj\classes\SjClass;
 use bizGhs\custom\classes\CustomClass;
 use bizHd\custom\classes\HdClass;
+use bizHd\order\classes\SettleClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\imgUtil;
@@ -105,6 +106,10 @@ class RechargeController extends BaseController
                 'side' => 0,
             ];
             \bizHd\recharge\classes\RechargeClass::complete($recharge, $payWay, $params);
+
+            //这边要有销账单的动作
+            SettleClass::clearSettle();
+
             $transaction->commit();
             util::success($post);
         } catch (\Exception $e) {

+ 39 - 38
app-hd/controllers/SettleController.php

@@ -24,12 +24,11 @@ class SettleController extends BaseController
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-
             $staff = $this->shopAdmin;
             $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
             $idData = $post['id'] ?? '';
             if (is_numeric($idData)) {
-                util::fail('请求参数错误');
+                util::fail('请求参数错误');
             }
             $customId = $post['customId'] ?? 0;
             $custom = CustomClass::getLockById($customId);
@@ -41,34 +40,49 @@ class SettleController extends BaseController
             if (empty($hd)) {
                 util::fail('客户信息缺失');
             }
-
-            //1、先充值
-            $rechargeAmount = 0;
-            if (is_numeric($id)) {
-                $order = OrderClass::getById($id, true);
-                $rechargeAmount = $order->remainDebtPrice ?? 0;
-            } else {
-                $idArr = json_decode($id, true);
-                $ids = array_column($idArr, 'id');
-                $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
-                if (!empty($orderList)) {
-                    foreach ($orderList as $order) {
-                        $remainDebtPrice = $order->remainDebtPrice ?? 0;
-                        $rechargeAmount = bcadd($rechargeAmount, $remainDebtPrice, 2);
-                    }
+            //先充值
+            $mayClearAmount = 0;
+            $idList = json_decode($idData, true);
+            $ids = array_column($idList, 'id');
+            if (empty($ids)) {
+                util::fail('请选择订单');
+            }
+            $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+            if (empty($orderList)) {
+                util::fail('请选择订单呢');
+            }
+            foreach ($orderList as $order) {
+                if ($order->mainId != $this->mainId) {
+                    util::fail('不是你的订单哦');
                 }
+                $remainDebtPrice = $order->remainDebtPrice ?? 0;
+                $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
             }
-            if (empty($rechargeAmount)) {
+            if (empty($mayClearAmount)) {
                 util::fail('不需要销账');
             }
             $staffId = $this->shopAdminId;
             $staffName = $this->shopAdminName;
             $customName = $custom->name ?? '';
+            $userId = $custom->userId;
             $hdName = $hd->name;
             $shopId = $this->shopId;
             $mainId = $this->mainId;
             $orderSn = orderSn::getRechargeSn();
-            $rechargeData = [
+            $shop = $this->shop;
+            $settleParams = [];
+
+            $hasSettle = SettleClass::getByCondition(['customId' => $customId, 'status' => 1], true);
+            if (!empty($hasSettle)) {
+                util::fail('这个客户名下有待结账单,请先取消');
+            }
+
+            //创建待账单
+            $settle = SettleClass::addSettle(0, $orderList, $shop, $custom, $hd, $staff, $settleParams);
+            $settleId = $settle->id;
+            $settleAmount = $settle->actPrice;
+
+            $addData = [
                 'orderSn' => $orderSn,
                 'modPrice' => 1,
                 'payWay' => $payWay,
@@ -78,38 +92,25 @@ class SettleController extends BaseController
                 'hdId' => $hdId,
                 'hdName' => $hdName,
                 'onlinePay' => 1,
-                'amount' => $rechargeAmount,
+                'amount' => $mayClearAmount,
                 'staffId' => $staffId,
                 'staffName' => $staffName,
                 'payStatus' => 0,
                 'payTime' => '0000-00-00 00:00:00',
                 'status' => 0,
+                'clearId' => $settleId,
+                'clearAmount' => $settleAmount,
                 'remark' => '',
                 'customId' => $customId,
                 'customName' => $customName,
+                'userId' => $userId,
             ];
-            $respond = RechargeClass::addRecharge($rechargeData);
+            $respond = RechargeClass::addRecharge($addData);
             $retId = $respond->id;
+            //充值成功并且销账成功
             $recharge = RechargeClass::getLockById($retId);
             $params = ['onlinePay' => 1, 'side' => 0];
             RechargeClass::complete($recharge, $payWay, $params);
-
-            //2、再销账
-            $idArr = json_decode($idData, true);
-            $ids = array_column($idArr, 'id');
-            $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
-            if (!empty($orderList)) {
-                foreach ($orderList as $order) {
-                    if (empty($order)) {
-                        util::fail('没有找到订单呢');
-                    }
-                    if ($order->mainId != $this->mainId) {
-                        util::fail('不是你的订单');
-                    }
-                    SettleClass::confirmSettle($order, $payWay, $staff);
-                }
-            }
-
             $transaction->commit();
             util::complete();
         } catch (\Exception $exception) {

+ 2 - 2
app-mall/controllers/OrderController.php

@@ -491,7 +491,7 @@ class OrderController extends BaseController
                 'orderSn' => $oldOrderSn,
             ];
             $response = $laResource->close($closeParams);
-            if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+            if (!isset($response['code']) || $response['code'] != 'BBS00000') {
                 $msg = $response['msg'] ?? '';
                 noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg, '15280215347');
                 util::fail('出错了哦,请重新下一单');
@@ -538,7 +538,7 @@ class OrderController extends BaseController
             'couponId' => $couponId,
         ];
         $response = $laResource->driveWxPay($wxParams);
-        if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+        if (!isset($response['code']) || $response['code'] != 'BBS00000') {
             $errMsg = $response['msg'] ?? '';
             noticeUtil::push($errMsg, '15280215347');
             util::fail('支付失败');

+ 112 - 2
app-mall/controllers/RechargeController.php

@@ -19,6 +19,112 @@ class RechargeController extends BaseController
 
     public $guestAccess = ['recharge'];
 
+    //用微信支付进行充值 ssh 20250709
+    public function actionWxPayRecharge()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'] ?? '';
+        //避免重复提交
+        util::checkRepeatCommit($id, 8);
+        $recharge = RechargeClass::getById($id, true);
+        if (empty($recharge)) {
+            util::fail('没有充值单');
+        }
+        $userId = $this->userId;
+        $shopId = $this->shopId;
+        if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
+            util::fail('不是你的充值单');
+        }
+        $shop = $this->shop;
+        $user = $this->user;
+        if (empty($shop)) {
+            util::fail('没有门店信息');
+        }
+        $shop = $this->shop;
+        $orderSn = $recharge->orderSn;
+
+        $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
+        if (empty($openId)) {
+            $openId = !empty($user['miniOpenId']) ? $user['miniOpenId'] : '';
+        }
+        if (empty($openId)) {
+            util::fail('没有找到openId');
+        }
+        $name = '充值销账,单号' . $orderSn;
+        $totalFee = $recharge->amount ?? 0;
+        $orderId = $recharge->id;
+        $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
+
+        $sjExtend = WxOpenClass::getMallWxInfo();
+        $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
+        $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
+        $params = [
+            'appid' => 'OP00002119',
+            'serial_no' => '018b08cfddbd',
+            'merchant_no' => $shop->lklSjNo,
+            'term_no' => $shop->lklScanTermNo,
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $laResource = new Lakala($params);
+        $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
+        $wxParams = [
+            'orderSn' => $orderSn,
+            'amount' => $totalFee,
+            'capitalType' => $capitalType,
+            'notifyUrl' => $notifyUrl,
+            'wxAppId' => $sjExtend['miniAppId'],
+            'openId' => $openId,
+            'subject' => $name,
+            'couponId' => 0,
+        ];
+        $response = $laResource->driveWxPay($wxParams);
+        if (!isset($response['code']) || $response['code'] != 'BBS00000') {
+            $errMsg = $response['msg'] ?? '';
+            noticeUtil::push($errMsg, '15280215347');
+            util::fail('充值失败');
+        }
+        $respData = $response['resp_data'] ?? [];
+        $accRespFields = $respData['acc_resp_fields'] ?? [];
+        if (empty($accRespFields)) {
+            util::fail('充值失败,没有找到支付数据');
+        }
+        $appId = $accRespFields['app_id'] ?? '';
+        $nonceStr = $accRespFields['nonce_str'] ?? '';
+        $paySign = $accRespFields['pay_sign'] ?? '';
+        $package = $accRespFields['package'] ?? '';
+        $signType = $accRespFields['sign_type'] ?? '';
+        $timeStamp = $accRespFields['time_stamp'] ?? '';
+        $new = [
+            'id' => $orderId,
+            'appId' => $appId,
+            'nonceStr' => $nonceStr,
+            'paySign' => $paySign,
+            'package' => $package,
+            'signType' => $signType,
+            'timeStamp' => $timeStamp,
+            'orderSn' => $orderSn,
+        ];
+        util::success($new);
+    }
+
+    //获取充值订单的详情 ssh 20250709
+    public function actionGetDetail()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $recharge = RechargeClass::getById($id, true);
+        if (empty($recharge)) {
+            util::fail('没有找到充值订单');
+        }
+        $userId = $this->userId;
+        $shopId = $this->shopId;
+        if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
+            util::fail('不是你的充值单');
+        }
+        util::success($recharge);
+    }
+
     //充值 ssh 20240507
     public function actionRecharge()
     {
@@ -44,8 +150,12 @@ class RechargeController extends BaseController
         if (empty($hd)) {
             util::fail('没有找到花店哦!');
         }
-        if (empty($salt) || $hd->salt != $salt) {
-            util::fail('不是你的花店哦');
+        if (empty($salt)) {
+
+        }else{
+            if($hd->salt != $salt){
+                util::fail('不是你的花店哦');
+            }
         }
         $customId = $hd->customId ?? 0;
         $custom = CustomClass::getById($customId, true);

+ 99 - 2
app-mall/controllers/SettleController.php

@@ -2,6 +2,14 @@
 
 namespace mall\controllers;
 
+use bizHd\order\classes\SettleClass;
+use bizHd\recharge\classes\RechargeClass;
+use bizHd\wx\classes\WxOpenClass;
+use bizMall\order\classes\OrderClass;
+use common\components\dict;
+use common\components\lakala\Lakala;
+use common\components\noticeUtil;
+use common\components\orderSn;
 use common\components\util;
 use Yii;
 
@@ -10,11 +18,100 @@ class SettleController extends BaseController
 
     public $guestAccess = [];
 
-    //创建新的结账单 ssh 202
+    //创建结账和充值单 ssh 20250709
     public function actionCreateOrder()
     {
         $post = Yii::$app->request->post();
-        util::complete('操作成功');
+
+        $shop = $this->shop;
+        if (empty($shop)) {
+            util::fail('没有门店信息');
+        }
+        $hd = $this->hd;
+        if (empty($hd)) {
+            util::fail('没有花店信息呢');
+        }
+        $custom = $this->custom;
+        if (empty($custom)) {
+            util::fail('花店信息缺失');
+        }
+
+        $idList = $post['ids'] ?? '';
+        $idList = trim($idList);
+        if (empty($idList)) {
+            util::fail('请选择订单');
+        }
+        $ids = explode(',', $idList);
+        if (empty($ids)) {
+            util::fail('请选择订单哦');
+        }
+        $mayClearAmount = 0;
+        $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+        if (empty($orderList)) {
+            util::fail('没有选订单');
+        }
+        foreach ($orderList as $order) {
+            if ($order->mainId != $this->mainId) {
+                util::fail('不是你的订单呢');
+            }
+            $remainDebtPrice = $order->remainDebtPrice ?? 0;
+            $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
+        }
+        if (empty($mayClearAmount)) {
+            util::fail('不需要销账');
+        }
+        $orderSn = orderSn::getRechargeSn();
+        $payWay = 0;
+        $shopId = $this->shopId;
+        $mainId = $this->mainId;
+        $hdId = $hd->id;
+        $hdName = $hd->name;
+        $staffId = 0;
+        $staffName = '';
+        $customId = $custom->id;
+        $customName = $custom->name;
+        $userId = $this->userId;
+        $settleParams = [];
+        $staff = [];
+
+        //避免重复提交
+        util::checkRepeatCommit($userId, 8);
+
+        $hasSettle = SettleClass::getByCondition(['customId' => $customId, 'status' => 1], true);
+        if (!empty($hasSettle)) {
+            util::fail('这个客户名下有待结账单,请先取消');
+        }
+
+        //创建待账单
+        $settle = SettleClass::addSettle(1, $orderList, $shop, $custom, $hd, $staff, $settleParams);
+        $settleId = $settle->id;
+        $settleAmount = $settle->actPrice;
+
+        $createData = [
+            'customId' => $customId,
+            'customName' => $customName,
+            'userId' => $userId,
+            'orderSn' => $orderSn,
+            'modPrice' => 1,
+            'payWay' => $payWay,
+            'style' => 1,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'hdId' => $hdId,
+            'hdName' => $hdName,
+            'onlinePay' => 1,
+            'amount' => $mayClearAmount,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'payStatus' => 0,
+            'payTime' => '0000-00-00 00:00:00',
+            'status' => 0,
+            'clearId' => $settleId,
+            'clearAmount' => $settleAmount,
+            'remark' => '',
+        ];
+        $respond = RechargeClass::addRecharge($createData);
+        util::success($respond);
     }
 
 }

+ 75 - 2
biz-hd/order/classes/SettleClass.php

@@ -17,6 +17,79 @@ class SettleClass extends BaseClass
 
     public static $baseFile = '\bizHd\order\models\Settle';
 
+    //$side 0 表示花店创建结账单,1客户创建结账单,二者区别有花店有带$staff信息,客户没有
+    //$params 预留参数
+    public static function addSettle($side, $orderList, $shop, $custom, $hd, $staff = [], $params = [])
+    {
+        $totalRemain = 0;
+        $string = '';
+        $shopId = $shop->id;
+        $mainId = $shop->mainId;
+        $sjId = $shop->sjId;
+
+        $customId = $custom->id ?? 0;
+        $customName = $custom->name ?? '';
+        $customAvatar = $custom->avatar;
+        $customMobile = $custom->mobile;
+        $customAddress = $custom->address;
+        $customUserId = $custom->userId;
+
+        $hdId = $hd->id;
+        $hdName = $hd->name;
+        $hdAvatar = $hd->avatar;
+        $hdMobile = $hd->mobile;
+        $hdAddress = $hd->address;
+        $staffId = 0;
+        $staffName = '';
+        if ($side == 1) {
+            $staffId = $staff->id;
+            $staffName = $staff->name ?? '';
+        }
+
+        $settleOrderSn = orderSn::getSettleSn();
+        foreach ($orderList as $order) {
+            $remainDebtPrice = $order->remainDebtPrice ?? 0;
+            $totalRemain = bcadd($totalRemain, $remainDebtPrice, 2);
+            $string = $string . ',' . $order->id;
+        }
+        $num = count($orderList);
+        $settleData = [
+            'prePrice' => $totalRemain,
+            'actPrice' => $totalRemain,
+            'realPrice' => $totalRemain,
+            'payWay' => 0,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'sjId' => $sjId,
+            'purchaseIds' => '',
+            'saleIds' => $string,
+            'num' => $num,
+            'status' => 1,
+            'customId' => $customId,
+            'customName' => $customName,
+            'customAvatar' => $customAvatar,
+            'customMobile' => $customMobile,
+            'customAddress' => $customAddress,
+            'customUserId' => $customUserId,
+            'hdId' => $hdId,
+            'hdShopId' => $shopId,
+            'hdName' => $hdName,
+            'hdAvatar' => $hdAvatar,
+            'hdMobile' => $hdMobile,
+            'hdAddress' => $hdAddress,
+            'hdStaffId' => $staffId,
+            'hdStaffName' => $staffName,
+            'orderSn' => $settleOrderSn,
+            'payTime' => '0000-00-00 00:00:00',
+        ];
+        return self::addData($settleData);
+    }
+
+    public static function clearSettle()
+    {
+
+    }
+
     //结清尾款 ssh 20220708
     public static function confirmSettle($order, $payWay, $staff)
     {
@@ -92,8 +165,8 @@ class SettleClass extends BaseClass
         }
 
         //客户欠款金额减少
-        $custom = CustomClass::getLockById($customId);
-        CustomClass::clearDebtAmountReduce($custom, $remainDebtPrice, $settleReturn);
+        //$custom = CustomClass::getLockById($customId);
+        //CustomClass::clearDebtAmountReduce($custom, $remainDebtPrice, $settleReturn);
 
         //制作单上的尾款也去掉
         WorkClass::updateByCondition(['orderId' => $orderId], ['orderDebtPrice' => 0]);

+ 4 - 3
biz-hd/recharge/classes/RechargeClass.php

@@ -92,6 +92,7 @@ class RechargeClass extends BaseClass
         $shop = ShopClass::getById($shopId, true);
         $rechargeWeal = $shop->rechargeWeal ?? 0;
         $addGiveAmount = 0;
+
         //如果客户有本身有欠款,充值不享受任何福利
         if ($custom->balance > 0) {
             if ($rechargeWeal == 1 || $rechargeWeal == 2) {
@@ -99,7 +100,7 @@ class RechargeClass extends BaseClass
                 if (!empty($weal)) {
                     $weal = arrayUtil::arraySort($weal, 'level', SORT_ASC);
                     if ($rechargeWeal == 1) {
-                        //充值升级会员
+                        //优惠方式1:充值升级会员
                         $newLevel = 0;
                         foreach ($weal as $k => $v) {
                             $thisRecharge = $v['recharge'] ?? 0;
@@ -117,7 +118,7 @@ class RechargeClass extends BaseClass
                             CustomClass::levelChange($oldLevel, $newLevel, $shop, $custom, $hd, $params);
                         }
                     } else {
-                        //充多少送多少
+                        //优惠方式2:充多少送多少
                         foreach ($weal as $k => $v) {
                             $thisRecharge = $v['recharge'] ?? 0;
                             $thisGive = $v['give'] ?? 0;
@@ -145,7 +146,7 @@ class RechargeClass extends BaseClass
         $hd->balance = bcadd($hd->balance, $totalAmount, 2);
         $hd->save();
         if ($hd->balance != $custom->balance) {
-            $msg = '充值回调失败,金额不一致。编号:' . floatval($hd->balance) . ' / ' . floatval($custom->balance);
+            $msg = '充值金额不一致。编号:' . floatval($hd->balance) . ' / ' . floatval($custom->balance);
             Yii::info($msg);
             util::fail($msg);
         }