lizhen hace 1 semana
padre
commit
edaf68206c

+ 11 - 69
addons/unishop/behavior/Order.php

@@ -36,60 +36,14 @@ class Order
         $productExtend = new \addons\unishop\extend\Product;
         $prefix = \think\Config::get('database.prefix');
 
-        if (Config::isPessimism()) {
+        if (1 == 1) {
             // 悲观锁
             foreach ($extra['specNumber'] as $spec => $number) {
                 $result = 0;
                 if (is_numeric($spec) && $params[$key]['use_spec'] == Product::SPEC_OFF) {
                     $result = Db::execute('UPDATE ' . $prefix . "unishop_product SET no_buy_yet = no_buy_yet+{$number}, real_sales = real_sales+{$number}, stock = stock-{$number} WHERE id = {$params[$key]['id']}");
                 } else if ($params[$key]['use_spec'] == Product::SPEC_ON) {
-                    $info = $productExtend->getBaseData($params[$key], $spec);
-
-                    // mysql<5.7.13时用
-                    //if (mysql < 5.7.13) {
-                    $spec = str_replace(',', '","', $spec);
-                    $search = '"stock":"' . $info['stock'] . '","value":["' . $spec . '"]';
-                    $stock = $info['stock'] - $number;
-                    $replace = '"stock":\"' . $stock . '\","value":["' . $spec . '"]';
-                    $sql = 'UPDATE ' . $prefix . "unishop_product SET no_buy_yet = no_buy_yet+{$number}, stock = stock-{$number}, real_sales = real_sales+{$number} ,`specTableList` = REPLACE(specTableList,'$search','$replace') WHERE id = {$params[$key]['id']}";
-                    $result = Db::execute($sql);
-                    //}
-
-                    //下面语句直接操作JSON
-                    //if (mysql >= 5.7.13) {
-                    //$info['stock'] -= $number;
-                    //$result = Db::execute("UPDATE fa_unishop_product SET no_buy_yet = no_buy_yet+{$number}, real_sales = real_sales+{$number}, stock = stock-{$number},specTableList = JSON_REPLACE(specTableList, '$[{$info['key']}].stock', {$info['stock']}) WHERE id = {$params[$key]['id']}");
-                    //}
-                }
-                if ($result == 0) { // 锁生效
-                    throw new Exception('下单失败,请重试');
-                }
-                $key++;
-            }
-        } else {
-            // 乐观锁
-            foreach ($extra['specNumber'] as $spec => $number) {
-                $result = 0;
-                if (is_numeric($spec) && $params[$key]['use_spec'] == Product::SPEC_OFF) {
-                    $result = Db::execute('UPDATE ' . $prefix . "unishop_product SET no_buy_yet = no_buy_yet+{$number}, real_sales = real_sales+{$number}, stock = stock-{$number} WHERE id = {$params[$key]['id']} AND stock = {$params[$key]['stock']}");
-                } else if ($params[$key]['use_spec'] == Product::SPEC_ON) {
-                    $info = $productExtend->getBaseData($params[$key], $spec);
-
-                    // mysql<5.7.13时用
-                    //if (mysql < 5.7.13) {
-                    $spec = str_replace(',', '","', $spec);
-                    $search = '"stock":"' . $info['stock'] . '","value":["' . $spec . '"]';
-                    $stock = $info['stock'] - $number;
-                    $replace = '"stock":\"' . $stock . '\","value":["' . $spec . '"]';
-                    $sql = 'UPDATE ' . $prefix . "unishop_product SET no_buy_yet = no_buy_yet+{$number}, real_sales = real_sales+{$number}, stock = stock-{$number},`specTableList` = REPLACE(specTableList,'$search','$replace') WHERE id = {$params[$key]['id']} AND stock = {$params[$key]['stock']}";
-                    $result = Db::execute($sql);
-                    //}
-
-                    //下面语句直接操作JSON
-                    //if (mysql >= 5.7.13) {
-                    //$info['stock'] -= $number;
-                    //$result = Db::execute("UPDATE fa_unishop_product SET no_buy_yet = no_buy_yet+{$number}, real_sales = real_sales+{$number}, stock = stock-{$number},specTableList = JSON_REPLACE(specTableList, '$[{$info['key']}].stock', {$info['stock']}) WHERE id = {$params[$key]['id']} AND stock = {$params[$key]['stock']}");
-                    //}
+                    $result = 1;
                 }
                 if ($result == 0) { // 锁生效
                     throw new Exception('下单失败,请重试');
@@ -98,17 +52,7 @@ class Order
             }
         }
 
-        // 行为二
-        if (!empty($extra['cart'])) {
-            $cart = $extra['cart'];
-            Db::execute('DELETE FROM ' . $prefix . "unishop_cart WHERE id IN ($cart) AND user_id = $extra[userId]");
-        }
 
-        // 行为三
-        $coupon = $extra['coupon'];
-        if (!empty($coupon)) {
-            Db::name('unishop_coupon_user')->where('id',$coupon['cu_id'])->update(['status'=>1]);
-        }
 
         // More ...
     }
@@ -128,12 +72,9 @@ class Order
     public function createOrderBefore(&$params, $extra)
     {
 
-        $specs = explode(',', $extra['spec']);
-        foreach ($specs as &$spec) {
-            $spec = str_replace('|', ',', $spec);
-        }
-        $numbers = explode(',', $extra['number']);
-        $productIds = explode(',', $extra['product_id']);
+        $specs = [''];
+        $numbers = [$extra['number']];
+        $productIds = [$extra['product_id']];
 
         if (count($specs) !== count($numbers) || count($specs) !== count($productIds)) {
             throw new Exception(__('Parameter error'));
@@ -145,7 +86,7 @@ class Order
         // 条件一
         $products = [];
         foreach ($productIds as $key => &$productId) {
-            $productId = Hashids::decodeHex($productId);
+
             $products[$key] = Db::name('unishop_product')
                 ->where(['id' => $productId, 'switch' => Product::SWITCH_ON])
                 ->lock(Config::isPessimism()) // Todo 是否使用悲观锁
@@ -158,7 +99,7 @@ class Order
             throw new Exception(__('There are offline product'));
         }
         // 从购物车下单多个商品时,有同一个商品的不同规格导致减库存问题
-        if (count($productIds) > 0) {
+        /*if (count($productIds) > 0) {
             $reduceStock = [];
             foreach ($products as $key => $value) {
                 if (!isset($reduceStock[$value['id']])) {
@@ -168,7 +109,7 @@ class Order
                     $reduceStock[$value['id']] += $numbers[$key];
                 }
             }
-        }
+        }*/
 
         // 条件二
         foreach ($products as $key => $product) {
@@ -198,7 +139,7 @@ class Order
         $address = [];
 
         // 条件四
-        if ($extra['coupon_id']) {
+        /*if ($extra['coupon_id']) {
 
 //            $coupon = Coupon::get($extra['coupon_id']);
 
@@ -230,7 +171,8 @@ class Order
 
         } else {
             $coupon = [];
-        }
+        }*/
+        $coupon = [];
 
         $params = [$products, $delivery, $coupon, $baseProductInfo, $address, $orderPrice, $specs, $numbers];
     }

+ 2 - 3
addons/unishop/controller/Order.php

@@ -101,7 +101,7 @@ class Order extends Base
             /*if ($productId) {*/
                 $number = input('number',1,'intval');
                 $number = intval($number);
-                $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
+//                $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
                 $product = (new Product)->where(['id' => $productId, 'switch' => Product::SWITCH_ON, 'deletetime' => null])->find();
                 /** 产品基础数据 **/
                 $spec = input('spec', '');
@@ -325,7 +325,7 @@ class Order extends Base
         // 0=全部,1=待付款,3=待核销,4=已完成,20=已取消
         $type = input('type', 0);
         $page = input('page', 1);
-        $pagesize = input('pagesize', 10);
+        $pagesize = input('listrow', 10);
         try {
 
             $orderModel = new \addons\unishop\model\Order();
@@ -847,7 +847,6 @@ class Order extends Base
     public function detail()
     {
         $order_id = input('order_id', 0);
-        $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
 
         try {
             $orderModel = new \addons\unishop\model\Order();

+ 4 - 4
addons/unishop/controller/Product.php

@@ -51,7 +51,7 @@ class Product extends Base
     public function detail()
     {
         $productId = input('id');
-        $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
+//        $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
 
         try {
 
@@ -152,8 +152,8 @@ class Product extends Base
     public function lists()
     {
         $page = input('page', 1);
-        $pagesize = input('pagesize', 20);
-        $by = input('by', 'weigh');
+        $pagesize = input('listrow', 20);
+        $by = input('by', 'activetime');
         $desc = input('desc', 'desc');
 
 //        $sid = input('sid'); // 二级分类Id
@@ -177,7 +177,7 @@ class Product extends Base
             ->where(['switch' => productModel::SWITCH_ON])
             ->page($page, $pagesize)
             ->order($by, $desc)
-            ->field('id,title,info,image,sales_price,use_spec')
+            ->field('id,title,info,image,sales_price,use_spec,activetime')
             ->select();
 
         if ($result) {

+ 6 - 7
addons/unishop/model/Order.php

@@ -249,11 +249,9 @@ class Order extends Model
         Hook::listen('create_order_before', $params, $data);
         list($products, $delivery, $coupon, $baseProductInfos, $address, $orderPrice, $specs, $numbers) = $params;
 
-        // 获取雪花算法分布式id,方便以后扩展
-        $snowflake = new Snowflake();
-        $id = $snowflake->id();
         // 优惠费用
-        $discountPrice = isset($coupon['value']) ? $coupon['value'] : 0;
+//        $discountPrice = isset($coupon['value']) ? $coupon['value'] : 0;
+        $discountPrice = 0;
         // 订单费用
         //$orderPrice;
         // 运费
@@ -265,13 +263,13 @@ class Order extends Model
         $out_trade_no = date('Ymd',time()).uniqid().$userId;
 
         $db_pay_type = [
+            'nopay'  => 0,
             'wallet' => 2,
             'wechat' => 3,
             'alipay' => 4,
         ];
 
-        (new self)->save([
-            'id' => $id,
+        $this->save([
             'user_id' => $userId,
             'out_trade_no' => $out_trade_no,
             'order_price' => $orderPrice,
@@ -290,6 +288,7 @@ class Order extends Model
             'intro_uid' => $intro_uid,
         ]);
 
+        $id = $this->id;
 
         (new OrderExtend)->save([
             'user_id' => $userId,
@@ -334,7 +333,7 @@ class Order extends Model
         Hook::listen('create_order_after', $products, $data);
 
         return [
-            'order_id' => Hashids::encodeHex($id),
+            'order_id' => $id,
             'out_trade_no' => $out_trade_no
         ];
     }

+ 4 - 2
addons/unishop/model/Product.php

@@ -77,7 +77,8 @@ class Product extends Model
      * @return string
      */
     public function getProductIdAttr($value, $data) {
-        return Hashids::encodeHex($data['id']);
+        return $data['id'];
+//        return Hashids::encodeHex($data['id']);
     }
 
     /**
@@ -154,7 +155,8 @@ class Product extends Model
         $data['info'] = $product['info'];
         $data['spec'] = $spec;
         $data['number'] = $number;
-        $data['id'] = Hashids::encodeHex($product['id']);
+//        $data['id'] = Hashids::encodeHex($product['id']);
+        $data['id'] = $product['id'];
 
         $data['total_price'] = bcmul($data['sales_price'],$number,2);
 

+ 4 - 4
application/api/controller/Unishop.php

@@ -31,7 +31,7 @@ class Unishop extends Api
         if(empty($orderid)){
             $this->error();
         }
-        $orderid = Hashids::decodeHex($orderid);
+//        $orderid = Hashids::decodeHex($orderid);
 
         if(!in_array($pay_type,['wechat','alipay','wallet'])){
             $this->error();
@@ -49,15 +49,15 @@ class Unishop extends Api
             $this->error('请刷新重试');
         }
 
-        /*if($orderinfo['total_price'] == 0){
+        if($orderinfo['total_price'] == 0){
             $update = [
                 'have_paid'=>time(),
-                //游艇项目自动发货
+                //自动发货
                 'have_delivered' => time()
             ];
             Db::name('unishop_order')->where($map)->update($update);
             $this->error('零元订单,已支付成功');
-        }*/
+        }
 
 
         //创建订单