From 3e161a7c1994b5761b40dcd157ef4bc888e0ffac Mon Sep 17 00:00:00 2001
From: lihan <3398341942@qq.com>
Date: Fri, 26 Oct 2018 09:38:10 +0800
Subject: [PATCH] 修改bug阶段

---
 app/pay/controller/PayController.php | 65 ++++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 27 deletions(-)

diff --git a/app/pay/controller/PayController.php b/app/pay/controller/PayController.php
index c606dcb..f3290a7 100644
--- a/app/pay/controller/PayController.php
+++ b/app/pay/controller/PayController.php
@@ -19,7 +19,7 @@ class PayController extends HomeBaseController
             if (empty($request->param('pay_type'))) {
                 $this->success('请选择支付方式', '', false);
             }
-            $consignee = Db::name('zj_user_place')->field('name,province,city,county,mobile,place')
+            $consignee = Db::name('zj_user_place')->field('name,province,city,county,mobile,place,province_id,city_id,county_id')
                 ->where(['id' => $request->param('address_id'), 'uid' => session('user.id')])
                 ->find();
             if (session('cart.id') != null && session('goods.id') == null) {
@@ -67,7 +67,13 @@ class PayController extends HomeBaseController
                 'pay_type' => $request->param('pay_type'),
                 'step' => 1,
                 //购买同时加入一级分类,用于判断是否赠送积分用
-                'cid' => $request->param('cid')
+                'cid' => $request->param('cid'),
+                //二级分类字符串-1-,-2-,-3-
+                'cids' => $this->getSonCategoryStr($data),
+                'province' => $consignee['province_id'],
+                'city' => $consignee['city_id'],
+                'county' => $consignee['county_id'],
+                'place' => $consignee['place']
             ];
             Db::startTrans();
             if (Db::name('zj_order')->insert($order)) {
@@ -80,7 +86,7 @@ class PayController extends HomeBaseController
                         'oid' => $oid,
                         'gid' => $v['id'],
                         'num' => $v['num'],
-                        'price' => Db::name('zj_goods')->where(['id'=>$v['id']])->value('price')
+                        'price' => Db::name('zj_goods')->where(['id' => $v['id']])->value('price')
                     ];
                 }
                 if (Db::name('zj_order_goods')->insertAll($orderGoods)) {
@@ -138,28 +144,23 @@ class PayController extends HomeBaseController
                         if ($pay_cash > $balance) {
                             $this->success('您的积分不足', '', false);
                         } else {
-                            if ($balance < $pay_num) {
-                                Db::rollback();
-                                $this->success('您的积分不足', '', false);
-                            } else {
-                                //先减余额
-                                $balance -= $pay_num;
-                                Db::name('user')->update(['id' => session('user.id'), 'balance' => (int)$balance]);
-                                //记录积分日志
-                                $model = new IntegralModel;
-                                $model->insertIntegralLog('', session('user.id'), time(), $pay_num, 2);
-                                Db::commit();
-                                session('goods.id', null);
-                                Db::name('zj_cart')->where(['id' => ['in', session('cart.id')]])->delete();
-                                session('cart.id', null);
-                                $info = [
-                                    'attach' => $oid,
-                                    'openid' => session('user.openid'),
-                                    'body' => '微信支付-天生红商城',
-                                    'total_fee' => $pay_cash
-                                ];
-                                $this->wxPay($info);
-                            }
+                            //先减余额
+                            $balance -= $pay_num;
+                            Db::name('user')->update(['id' => session('user.id'), 'balance' => (int)$balance]);
+                            //记录积分日志
+                            $model = new IntegralModel;
+                            $model->insertIntegralLog('', session('user.id'), time(), $pay_num, 2);
+                            Db::commit();
+                            session('goods.id', null);
+                            Db::name('zj_cart')->where(['id' => ['in', session('cart.id')]])->delete();
+                            session('cart.id', null);
+                            $info = [
+                                'attach' => $oid,
+                                'openid' => session('user.openid'),
+                                'body' => '微信支付-天生红商城',
+                                'total_fee' => $pay_cash
+                            ];
+                            $this->wxPay($info);
                         }
                     } else {
                         $this->success('请选择支付方式', '', false);
@@ -263,9 +264,9 @@ class PayController extends HomeBaseController
                 $integral_give_id = $model->insertIntegralGive($info['uid'], $ratio, $integral_half, $integral_half, time());
                 if ($integral_give_id) {
                     if ($model->insertIntegralLog($integral_give_id, $info['uid'], time(), $integral_half, 1)) {
-                        if(Db::name('user')->where(['id'=>$info['uid']])->setInc('balance', $integral_half)) {
+                        if (Db::name('user')->where(['id' => $info['uid']])->setInc('balance', $integral_half)) {
                             Db::commit();
-                        }else {
+                        } else {
                             Db::rollback();
                         }
                     } else {
@@ -278,4 +279,14 @@ class PayController extends HomeBaseController
         }
     }
 
+    //获取购买商品的二级分类字符串
+    private function getSonCategoryStr($data)
+    {
+        $str = '';
+        foreach ($data as $item) {
+            $str .= '-' . Db::name('zj_goods')->where(['id' => $item['id']])->value('cid') . '-,';
+        }
+        return substr($str, 0, strlen($str) - 1);
+    }
+
 }
\ No newline at end of file
--
libgit2 0.24.0