Преглед на файлове

购买鲜花,扫码付款

shish преди 10 месеца
родител
ревизия
d677bfdea7

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

@@ -208,8 +208,8 @@ class NoticeController extends PublicController
         //接收流水类型、代金劵
         parse_str($attach);
         //流水类型
-        $capitalType = isset($capitalType) ? $capitalType : null;
-        if (isset($capitalType) == false) {
+        $capitalType = $capitalType ?? null;
+        if (!isset($capitalType)) {
             Yii::warning('capitalType empty,orderSn:' . $orderSn);
             util::end();
         }

+ 16 - 103
app-mall/controllers/OrderController.php

@@ -6,6 +6,7 @@ use biz\product\classes\ProductClass;
 use biz\shop\classes\ShopClass;
 use biz\wx\classes\WxMessageClass;
 use bizHd\custom\classes\HdClass;
+use bizHd\order\classes\ScanPayClass;
 use bizHd\wx\classes\WxOpenClass;
 use bizMall\custom\classes\CustomClass;
 use bizMall\goods\classes\GoodsClass;
@@ -803,26 +804,12 @@ class OrderController extends BaseController
         if (empty($shop)) {
             util::fail('没有门店信息');
         }
-        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
-        $gatheringItem = !empty($ext) ? $ext->gatheringItem : 0;
-        if (empty($gatheringItem)) {
-            util::fail('请设置付款用的商品');
-        }
-        $gatheringItemInfo = ItemClass::getById($gatheringItem, true);
-        if (empty($gatheringItemInfo)) {
-            util::fail('付款用的商品没有设置');
-        }
-        $ptItemId = $gatheringItemInfo->itemId ?? 0;
-        $classId = $gatheringItemInfo->classId ?? 0;
-        //收款码是否算收入由ext gatherRepeat决定
-        $post['repeat'] = $ext->gatherRepeat ?? 0;
         $customId = $this->customId;
         $custom = $this->custom;
         $hdId = $this->hdId;
         $hd = $this->hd;
         if (empty($customId) || empty($hdId)) {
             //考虑没有登录时的付款
-            $shop = $this->shop;
             $defaultCustomId = $shop->defaultCustomId ?? 0;
             if (empty($defaultCustomId)) {
                 util::fail('请设置快捷开单的客户');
@@ -830,7 +817,7 @@ class OrderController extends BaseController
             $customId = $defaultCustomId;
             $custom = CustomClass::getById($defaultCustomId, true);
             if (empty($custom)) {
-                util::fail('请设置快捷客户');
+                util::fail('无效的快捷客户');
             }
             $hdId = $custom->hdId;
             $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
@@ -844,89 +831,27 @@ class OrderController extends BaseController
         $customPy = $custom->py ?? '';
         $post['customName'] = $customName;
         $post['customNamePy'] = $customPy;
-        $post['gatheringItem'] = $gatheringItem;
         $post['shopId'] = $shopId;
         $post['mainId'] = $this->mainId;
-        $post['sjId'] = $this->sjId;
-        $post['store'] = 0;
         $post['customId'] = $customId;
-        $user = $this->user->attributes ?? [];
-        $post['bookName'] = $user['userName'] ?? '';
-        $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
-        $bookMobile = empty($bookMobile) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
-        $post['bookMobile'] = $bookMobile;
+
         $prePrice = round($post['prePrice'], 2);
-        $couponId = $post['couponId'] ?? 0;
-        $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => 0, 'couponId' => $couponId, 'userId' => $this->userId]);
-        $actPrice = $discountData['price'];
-        $post['discountType'] = $discountData['discountType'];
-        $post['discountAmount'] = $discountData['discountAmount'];
-        $post['orderPrice'] = $actPrice;
-        $post['actPrice'] = $actPrice;
-        $post['realPrice'] = $actPrice;
-        $post['mainPay'] = $actPrice;
-        $post['modifyPrice'] = $actPrice;
+        $actPrice = $prePrice;
+        if ($actPrice <= 0) {
+            util::fail('请填写付款金额');
+        }
         $post['userId'] = $this->userId;
-        $post['needPrint'] = dict::getDict('needPrint', 'noNeed');
         $now = time();
         $expireTime = $now + 300;//订单5分钟后过期
         $post['createTime'] = date("Y-m-d H:i:s", $now);
-        $post['deadline'] = $expireTime;
-        if ($actPrice <= 0) {
-            util::fail('请填写付款金额');
-        }
-
-        $post['goodsNum'] = 1;
-        $product = [[
-            'productId' => $gatheringItem,
-            'bigNum' => 1,
-            'smallNum' => '',
-            'num' => 1,
-            'unitType' => 0,
-            'property' => 1,
-            'unitPrice' => $actPrice,
-            'itemId' => $ptItemId,
-            'classId' => $classId
-        ]];
-        $post['product'] = $product;
-
-        $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : '00-00-00';
-        $post['onlinePay'] = dict::getDict('onlinePay', 'yes');
-
-        //前端未修改时这边做兼容
-        if (!empty($post['receiveAddress'])) {
-            $post['address'] = $post['receiveAddress'];
-            if (!empty($post['receiveProvince'])) {
-                $post['province'] = $post['receiveProvince'];
-            }
-            if (!empty($post['receiveCity'])) {
-                $post['city'] = $post['receiveCity'];
-            }
-            if (!empty($post['receiveFloor'])) {
-                $post['floor'] = $post['receiveFloor'];
-            }
-            if (!empty($post['latitude'])) {
-                $post['lat'] = $post['latitude'];
-            }
-            if (!empty($post['longitude'])) {
-                $post['long'] = $post['longitude'];
-            }
-            $city = $post['receiveCity'] ?? '';
-            $address = $post['receiveAddress'];
-            $floor = $post['receiveFloor'] ?? '';
-            $post['fullAddress'] = $city . $address . $floor;
-        }
-        $hasPay = 0;
-        $post['sendType'] = 1;
-        $post['orderType'] = 2;//花材订单
-        $post['dealPrice'] = 1;
-        $post['fromType'] = 1;
-        $order = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
+        $post['deadline'] = date("Y-m-d H:i:s", $expireTime);
+        $order = ScanPayClass::addOrder($post);
         $orderId = $order->id ?? 0;
         $orderSn = $order->orderSn ?? '';
+        $capitalType = dict::getDict('capitalType', 'scanPay', 'id');
         if ($payWay == 0) {
             //微信
-            $name = '购买商品';
+            $name = '购买鲜花,扫码付款';
             $totalFee = $actPrice;
             $user = UserService::getById($this->userId);
             //小程序使用miniOpenId
@@ -937,10 +862,8 @@ class OrderController extends BaseController
             if (empty($openId)) {
                 util::fail('没有微信信息');
             }
-            $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
 
             $sjExtend = WxOpenClass::getMallWxInfo();
-            $shop = $this->shop;
             $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
             $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
             $params = [
@@ -961,7 +884,7 @@ class OrderController extends BaseController
                 'wxAppId' => $sjExtend['miniAppId'],
                 'openId' => $openId,
                 'subject' => $name,
-                'couponId' => $couponId,
+                'couponId' => 0,
             ];
             $response = $laResource->driveWxPay($wxParams);
             if (!isset($response['code']) || $response['code'] != 'BBS00000') {
@@ -992,9 +915,7 @@ class OrderController extends BaseController
         } elseif ($payWay == 1) {
             //支付宝
             $totalFee = $actPrice;
-            $subject = '购买花材';
-            $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
-            $shop = $this->shop;
+            $subject = '购买鲜花,扫码付款';
             $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
             $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
             $params = [
@@ -1018,22 +939,14 @@ class OrderController extends BaseController
             if (!isset($response['code']) || $response['code'] != '000000') {
                 util::fail('支付失败了');
             }
-            $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
+            $url = $response['resp_data']['counter_url'] ?? '';
             if (empty($url)) {
                 util::fail('支付失败');
             }
             util::success(['url' => $url]);
         } elseif ($payWay == 2) {
-            util::fail('无效的支付方式');
-            //余额支付,验证支付密码是否正确
-            $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
-            $user = UserService::getUserInfo($this->userId);
-            UserService::validPayPassword($payPassword, $user);
-            $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
-            $callbackParams = [];
-            $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
-            $balance = isset($respond['balance']) ? $respond['balance'] : 0;
-            util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
+            //余额支付
+            util::fail('暂不支持');
         } else {
             util::fail('无效的支付方式');
         }

+ 82 - 0
biz-hd/order/classes/ScanPayClass.php

@@ -0,0 +1,82 @@
+<?php
+
+namespace bizHd\order\classes;
+
+use biz\goods\classes\GoodsClass;
+use biz\goods\models\Goods;
+use biz\shop\classes\ShopCapitalClass;
+use biz\shop\classes\ShopClass;
+use biz\shop\classes\ShopExtClass;
+use biz\stat\classes\StatOrderCountClass;
+use biz\stock\classes\GoodsStockRecordClass;
+use bizGhs\order\classes\CheckOrderClass;
+use bizGhs\product\classes\ProductClass;
+use bizGhs\stock\classes\StockRecordClass;
+use bizHd\custom\classes\CustomClass;
+use bizHd\item\classes\ItemClass;
+use bizHd\merchant\classes\SjClass;
+use bizHd\refund\classes\HdRefundClass;
+use bizHd\shop\classes\MainClass;
+use bizHd\shop\classes\ShopMoneyChangeClass;
+use bizHd\user\classes\UserClass;
+use bizHd\work\classes\WorkClass;
+use common\components\dict;
+use common\components\imgUtil;
+use common\components\miniUtil;
+use common\components\noticeUtil;
+use common\components\orderSn;
+use common\components\printUtil;
+use common\components\stringUtil;
+use common\components\util;
+use Yii;
+use bizHd\base\classes\BaseClass;
+use common\components\lakala\Lakala;
+
+class ScanPayClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\order\models\ScanPay';
+
+    public static function addOrder($data)
+    {
+        $mainId = $data['mainId'] ?? 0;
+        $shopId = $data['shopId'] ?? 0;
+        $hdId = $data['hdId'] ?? 0;
+        $customId = $data['customId'] ?? 0;
+        $snData = ['mainId' => $mainId, 'shopId' => $shopId, 'hdId' => $hdId, 'customId' => $customId];
+        $data['orderSn'] = orderSn::getScanPaySn($snData);
+        return self::add($data, true);
+    }
+
+    public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
+    {
+        $order = self::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($order)) {
+            noticeUtil::push('扫码付款成功,支付回调,单号:' . $orderSn . ' 金额:' . $totalFee . ' 回调id:' . $transactionId . ' 附件:' . $attach . ',没有找到单号', '15280215347');
+            $msg = "没有找到零售订单 orderSn:{$orderSn}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        if ($order->actPrice != $totalFee) {
+            noticeUtil::push("扫码付款成功,支付回调错误,订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->actPrice} {$totalFee} 附件:{$attach}", '15280215347');
+            $msg = "零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->actPrice} {$totalFee}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        $id = $order->id;
+        $order = self::getLockById($id);
+        $date = date("Y-m-d H:i:s");
+        $order->payStatus = 1;
+        $order->status = 2;
+        $order->payTime = $date;
+        $order->thirdNo = $transactionId;
+        $order->save();
+        self::payAfter($order, $payWay);
+    }
+
+    public static function payAfter($order, $payWay)
+    {
+
+    }
+
+}

+ 15 - 0
biz-hd/order/models/ScanPay.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizHd\order\models;
+
+use bizHd\base\models\Base;
+
+class ScanPay extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhScanPay';
+	}
+
+}

+ 15 - 0
biz-hd/order/models/ScanPaySn.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizHd\order\models;
+
+use bizHd\base\models\Base;
+
+class ScanPaySn extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhScanPaySn';
+	}
+
+}

+ 2 - 0
common/components/dict.php

@@ -419,6 +419,7 @@ class dict
             'deduct' => ['id' => 77, 'name' => 'deduct'],
             //如果涉及是系统处理和操作,都可以用这个流水类型
             'system' => ['id' => 78, 'name' => 'system'],
+            'scanPay' => ['id' => 79, 'name' => 'scanPay'],
         ],
         "capitalTypeList" => [//流水类型的对应链接,后台收支明细查看时跳转的链接
             0 => ['link' => '/capital/order-detail', 'name' => '网店', 'orderLink' => '/order/detail', 'id' => 0,],
@@ -469,6 +470,7 @@ class dict
             76 => ['link' => '', 'name' => '售后返充', 'id' => 76,],
             77 => ['link' => '', 'name' => '手动减少', 'id' => 77,],
             78 => ['link' => '', 'name' => '系统操作', 'id' => 78,],
+            79 => ['link' => '', 'name' => '扫码付款', 'id' => 79,],
         ],
 
         //用户来源

+ 16 - 0
common/components/orderSn.php

@@ -18,6 +18,7 @@ use bizHd\goods\classes\GoodsCgSnClass;
 use bizHd\goods\classes\GoodsSnClass;
 use bizHd\ljh\classes\LjhSnClass;
 use bizHd\order\classes\SettleSnClass;
+use bizHd\order\models\ScanPaySn;
 use bizHd\part\classes\PartSnClass;
 use bizHd\pd\classes\PdGoodsSnClass;
 use bizHd\purchase\classes\PurchaseClearSnClass;
@@ -125,6 +126,21 @@ class orderSn
         return $prefix . $id;
     }
 
+    public static function getScanPaySn($params)
+    {
+        $params['id'] = null;
+        $prefix = 'SC_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'SC';
+        }
+        $respond = ScanPaySn::add($params);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('订单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
     //供货商采购单号 ssh 2021.1.19
     public static function getGhsPurchaseSn()
     {

+ 4 - 0
common/components/payUtil.php

@@ -7,6 +7,7 @@ use biz\wx\classes\WxMessageClass;
 use bizGhs\custom\classes\CustomRechargeClass;
 use bizHd\ljh\classes\LjhApplyClass;
 use bizHd\order\classes\OrderClass;
+use bizHd\order\classes\ScanPayClass;
 use bizHd\purchase\classes\PurchaseClearClass;
 use bizHd\purchase\services\PurchaseService;
 use bizHd\px\services\PxApplyService;
@@ -45,6 +46,9 @@ class payUtil
                 //散客下单
                 OrderClass::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
                 break;
+            case dict::getDict('capitalType', 'scanPay', 'id'):
+                ScanPayClass::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
+                break;
             case dict::getDict('capitalType', 'xhRenew', 'id'):
                 //商家续期
                 RenewClass::thirdPay($payWay, $orderSn, $totalFee, $attach);