Browse Source

商城快速付款

shish 5 years ago
parent
commit
2a3c1584a1

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

@@ -114,7 +114,7 @@ class OrderController extends BaseController
             util::success($return);
         } catch (\Exception $e) {
             $transaction->rollBack();
-            Yii::info("下单报错:" . $e->getMessage());
+            Yii::info("下单失败原因:" . $e->getMessage());
             util::fail('下单失败');
         }
     }

+ 7 - 2
app-mall/controllers/BaseController.php

@@ -17,7 +17,7 @@ class BaseController extends PublicController
     public $validate = true;
     public $guestAccessAction = [];
     public $userId = 0, $user, $shopId;
-    public $sjId, $sj, $sjExtend, $customId = 0;
+    public $sjId, $sj, $sjExtend, $customId = 0, $custom = [];
     public $isWx;
 
     public function beforeAction($action)
@@ -56,7 +56,12 @@ class BaseController extends PublicController
                 util::fail('没有用户信息');
             }
             $this->user = $userInfo;
-            $customId = CustomClass::getCurrentCustomId($sjId, $userInfo);
+            $custom = CustomClass::getCurrentCustom($sjId, $userInfo);
+            if (empty($custom)) {
+                util::fail('没有找到客户');
+            }
+            $this->custom = $custom;
+            $customId = $custom['id'] ?? 0;
             $this->customId = $customId;
         }
         //游客可以访问的方法

+ 95 - 92
app-mall/controllers/OrderController.php

@@ -46,85 +46,98 @@ class OrderController extends BaseController
         //运费计算方式
         $freightType = isset($goodsInfo['freightType']) ? $goodsInfo['freightType'] : 0;
 
-        $post['userId'] = $this->userId;
-        $user = $this->user;
-        $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
-        $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
-        $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
-        $post['bookMobile'] = $bookMobile;
-
-        $post['payWay'] = $this->isWx == true ? 0 : 1;
-        $defaultShopId = MerchantService::getDefaultShopId($this->sj);
-        if (empty($defaultShopId)) {
-            util::fail('没有找到门店');
-        }
-        //计算运费
-        $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
-        $sendCost = 0;
-        //按距离计算运费并且客户要求送的
-        if ($freightType == 0 && $needSend == 1) {
-            $lat = $post['latitude'];//收货人纬度
-            $lng = $post['longitude'];//收货人经度
-            $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
-            $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
-        }
-        $post['sendCost'] = $sendCost;
-        $post['merchantId'] = $this->sjId;
-        $post['shopId'] = $defaultShopId;
-
-        //计算总金额
-        $unitPrice = $goodsInfo['price'];
-        $goodsStyleList = isset($goodsInfo['goodsStyleList']) ? $goodsInfo['goodsStyleList'] : [];
-        if (!empty($goodsStyleId)) {
-            if (empty($goodsStyleList)) {
-                util::fail('商品款式没有找到');
+        //事务处理
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $post['userId'] = $this->userId;
+            $user = $this->user;
+            $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
+            $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
+            $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
+            $post['bookMobile'] = $bookMobile;
+
+            $post['payWay'] = $this->isWx == true ? 0 : 1;
+            $defaultShopId = MerchantService::getDefaultShopId($this->sj);
+            if (empty($defaultShopId)) {
+                util::fail('没有找到门店');
             }
-            $styleIdList = array_keys($goodsStyleList);
-            if (in_array($goodsStyleId, $styleIdList) == false) {
-                util::fail('商品款式没有找到!');
+            //计算运费
+            $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
+            $sendCost = 0;
+            //按距离计算运费并且客户要求送的
+            if ($freightType == 0 && $needSend == 1) {
+                $lat = $post['latitude'];//收货人纬度
+                $lng = $post['longitude'];//收货人经度
+                $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
+                $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
             }
-            $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
-        }
-        $goodsPrice = $unitPrice * $goodsNum;
-        $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
-        //非门店订单
-        $store = 0;
-        $post['store'] = $store;
-        //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
-        $sourceType = $this->isWx ? 0 : 1;
-        if (httpUtil::isMiniProgram()) {
-            $sourceType = 2;
+            $post['sendCost'] = $sendCost;
+            $post['merchantId'] = $this->sjId;
+            $post['shopId'] = $defaultShopId;
+
+            //计算总金额
+            $unitPrice = $goodsInfo['price'];
+            $goodsStyleList = isset($goodsInfo['goodsStyleList']) ? $goodsInfo['goodsStyleList'] : [];
+            if (!empty($goodsStyleId)) {
+                if (empty($goodsStyleList)) {
+                    util::fail('商品款式没有找到');
+                }
+                $styleIdList = array_keys($goodsStyleList);
+                if (in_array($goodsStyleId, $styleIdList) == false) {
+                    util::fail('商品款式没有找到!');
+                }
+                $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
+            }
+            $goodsPrice = $unitPrice * $goodsNum;
+            $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
+            //非门店订单
+            $store = 0;
+            $post['store'] = $store;
+            //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
+            $sourceType = $this->isWx ? 0 : 1;
+            if (httpUtil::isMiniProgram()) {
+                $sourceType = 2;
+            }
+            $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
+            $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->userId]);
+            $actPrice = $discountData['price'];
+            $post['discountType'] = $discountData['discountType'];
+            $post['discountAmount'] = $discountData['discountAmount'];
+
+            $now = time();
+            $expireTime = $now + 1800;//订单30分钟后过期
+            $post['deadline'] = $expireTime;
+            $post['fromType'] = 1;//商城
+            $post['prePrice'] = $prePrice;
+            $post['actPrice'] = $actPrice;
+            $order = OrderClass::addOrder($post);
+            $orderId = $order['id'];
+            $orderSn = $order['orderSn'];
+            $data = [
+                'orderId' => $orderId,
+                'goodsId' => $goodsId,
+                'userId' => $this->userId,
+                'merchantId' => $this->sjId,
+                'title' => $goodsInfo['goodsName'],
+                'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
+                'unitPrice' => $unitPrice,
+                'num' => $goodsNum,
+                'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
+                'goodsStyleId' => $goodsStyleId,
+                'createTime' => date("Y-m-d H:i:s"),
+            ];
+            OrderGoodsService::add($data);//创建订单商品列表
+
+            $transaction->commit();
+            util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId]);
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            Yii::info("下单失败原因:" . $e->getMessage());
+            util::fail('下单失败');
         }
-        $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
-        $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->userId]);
-        $actPrice = $discountData['price'];
-        $post['discountType'] = $discountData['discountType'];
-        $post['discountAmount'] = $discountData['discountAmount'];
 
-        $now = time();
-        $expireTime = $now + 1800;//订单30分钟后过期
-        $post['deadline'] = $expireTime;
-        $post['fromType'] = 1;//商城
-        $post['prePrice'] = $prePrice;
-        $post['actPrice'] = $actPrice;
-        $order = OrderClass::addOrder($post);
-        $orderId = $order['id'];
-        $orderSn = $order['orderSn'];
-        $data = [
-            'orderId' => $orderId,
-            'goodsId' => $goodsId,
-            'userId' => $this->userId,
-            'merchantId' => $this->sjId,
-            'title' => $goodsInfo['goodsName'],
-            'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
-            'unitPrice' => $unitPrice,
-            'num' => $goodsNum,
-            'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
-            'goodsStyleId' => $goodsStyleId,
-            'createTime' => date("Y-m-d H:i:s"),
-        ];
-        OrderGoodsService::add($data);//创建订单商品列表
-        util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId]);
     }
 
     //下单要用到的相关信息 shish 2019.12.6
@@ -263,11 +276,7 @@ class OrderController extends BaseController
         $store = isset($post['store']) ? $post['store'] : 1;
         $post['store'] = $store;
         //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
-        $sourceType = $this->isWx ? 0 : 1;
-        if (httpUtil::isMiniProgram()) {
-            $sourceType = 2;
-        }
-        $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
+        $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 2;
         //兼容旧系统sourceType=3表示朋友圈来源
         $fromType = $sourceType == 3 ? 2 : 0;
         $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
@@ -307,13 +316,10 @@ class OrderController extends BaseController
             $name = '购买商品';
             $totalFee = $actPrice;
             $user = UserService::getById($this->userId);
-            $openId = isset($user['openId']) ? $user['openId'] : 0;
-            if (httpUtil::isMiniProgram()) {
-                //小程序使用miniOpenId
-                $openId = $user['miniOpenId'];
-            }
+            //小程序使用miniOpenId
+            $openId = $user['miniOpenId'];
             if (empty($openId)) {
-                util::fail('没有找到客户的openId');
+                util::fail('没有找您的微信ID');
             }
             $typeList = dict::getConfig('capitalType');
             $capitalType = $typeList['xhOrder']['id'];
@@ -337,13 +343,10 @@ class OrderController extends BaseController
             $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
             $input->SetTrade_type("JSAPI");
 
-            //花卉宝代为申请的微信支付
             $sjExtend = $this->sjExtend;
-            if ($sjExtend['wxPayApply'] == 1) {
-                $input->SetSub_openid($openId);
-            } else {
-                $input->SetOpenid($openId);
-            }
+            //花卉宝代为申请的微信支付
+            //$input->SetSub_openid($openId);
+            $input->SetOpenid($openId);
             //小程序使用miniAppId
             if (httpUtil::isMiniProgram()) {
                 $sjExtend['wxAppId'] = $sjExtend['miniAppId'];

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

@@ -164,8 +164,8 @@ class UserController extends BaseController
     //用户基本信息和资产 shish 2019.12.19
     public function actionMyProfile()
     {
-        $user = UserService::getUserInfo($this->userId);
-        $growth = $user['userAsset']['growth'];
+        $user = $this->custom;
+        $growth = $user['growth'] ?? 0;
         $extend = $this->sjExtend;
         $grade = MerchantExtendService::getGradeList($extend, 'asc');
         //下个等级的积分

+ 9 - 6
biz-hd/custom/classes/CustomClass.php

@@ -19,19 +19,22 @@ class CustomClass extends BaseClass
         return 'hd_custom_key_' . $sjId . '_' . $userId;
     }
 
-    public static function getCurrentCustomId($sjId, $user)
+    public static function getCurrentCustom($sjId, $user)
     {
         $userId = $user['id'];
         $key = self::getCustomCacheKey($sjId, $userId);
         $currentId = Yii::$app->redis->executeCommand('GET', [$key]);
+        $info = [];
         if (!empty($currentId)) {
-            return $currentId;
+            $info = self::getById($currentId);
         }
-        $info = self::getByCondition(['sjId' => $sjId, 'userId' => $userId]);
-        if (!empty($info)) {
-            return $info['id'];
+        if (empty($info)) {
+            $info = self::getByCondition(['sjId' => $sjId, 'userId' => $userId]);
+        } else {
+            $id = $info['id'];
+            Yii::$app->redis->executeCommand('SET', [$key, $id]);
         }
-        return 0;
+        return $info;
     }
 
     //创建获取客户信息 shish 2021.3.19

+ 0 - 13
biz-mall/order/classes/OrderClass.php

@@ -3,19 +3,11 @@
 namespace bizMall\order\classes;
 
 use bizMall\merchant\classes\MerchantAssetClass;
-use bizMall\merchant\classes\MerchantClass;
-use bizMall\message\classes\InformAdminClass;
-use bizMall\message\classes\InformUserClass;
 use bizMall\stat\classes\StatOrderClass;
 use bizMall\stat\classes\StatOrderCountClass;
-use bizMall\stat\classes\StatOrderMonthClass;
 use bizMall\user\classes\UserClass;
 use common\components\miniUtil;
 use common\components\orderSn;
-use common\components\stringUtil;
-use common\services\xhOrderDayNumService;
-use common\services\xhOrderMonthNumService;
-use Yii;
 use bizMall\base\classes\BaseClass;
 
 class OrderClass extends BaseClass
@@ -65,14 +57,9 @@ class OrderClass extends BaseClass
     //添加订单 shish 2019.12.5
     public static function addOrder($data)
     {
-        $date = date("Y-m-d H:i:s");
         $merchantId = $data['merchantId'];
-
         $data['orderSn'] = orderSn::getOrderSn();
         $data['payStatus'] = 0;
-        $data['createTime'] = $date;
-        $data['addTime'] = time();
-
         $month = date("Ym");
         $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
         //将花店每月的总订单数作为编号

+ 2 - 1
sql.sql

@@ -1719,4 +1719,5 @@ DROP TABLE IF EXISTS `xhRenewSn`;
 CREATE TABLE IF NOT EXISTS `xhRenewSn` (
   `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
   PRIMARY KEY (`id`)
-) AUTO_INCREMENT=18623508 COMMENT='续费订单号';
+) AUTO_INCREMENT=18623508 COMMENT='续费订单号';
+ALTER TABLE xhOrder DROP COLUMN `createTime`;