Browse Source

商品接口(列表和详情合并为一个)

wufeng 2 years ago
parent
commit
ff5ce2a50f

+ 0 - 32
app/mobile/controller/Exchange.php

@@ -1,32 +0,0 @@
-<?php
-
-namespace app\mobile\controller;
-
-use app\BaseController;
-use app\mobile\logic\ExchangeLogic;
-use think\exception\ValidateException;
-use think\facade\Config;
-use think\facade\Validate;
-
-//兑换
-class Exchange extends BaseController
-{
-    //商品列表
-    public function goodList()
-    {
-        $param = $this->request->only(['page' => 1, 'size' => 10], 'post');
-        return ExchangeLogic::goodList($param);
-    }
-
-    //商品详情
-    public function goodInfo()
-    {
-        $code = $this->request->post('code', '');
-
-        $val=Validate::rule(Config::get('validate_rules.goodInfo'));
-        if(!$val->check(['code'=>$code])) throw new ValidateException($val->getError());
-
-        return ExchangeLogic::goodInfo($code);
-    }
-
-}

+ 8 - 8
app/mobile/controller/Shopping.php → app/mobile/controller/Good.php

@@ -3,22 +3,22 @@
 namespace app\mobile\controller;
 
 use app\BaseController;
-use app\mobile\logic\ShoppingLogic;
+use app\mobile\logic\GoodLogic;
 use think\exception\ValidateException;
 use think\facade\Config;
 use think\facade\Validate;
 
-//商城商
-class Shopping extends BaseController
+//商品
+class Good extends BaseController
 {
-    //商城商品列表
+    //列表
     public function goodList()
     {
-        $param = $this->request->only(['page' => 1, 'size' => 10], 'post');
-        return ShoppingLogic::goodList($param);
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'type' => ''], 'post');
+        return GoodLogic::goodList($param);
     }
 
-    //商城商品详情
+    //详情
     public function goodInfo()
     {
         $code = $this->request->post('code', '');
@@ -26,7 +26,7 @@ class Shopping extends BaseController
         $val = Validate::rule(Config::get('validate_rules.goodInfo'));
         if (!$val->check(['code' => $code])) throw new ValidateException($val->getError());
 
-        return ShoppingLogic::goodInfo($code);
+        return GoodLogic::goodInfo($code);
     }
 
 

+ 11 - 9
app/mobile/logic/ExchangeLogic.php → app/mobile/logic/GoodLogic.php

@@ -8,12 +8,13 @@ use app\model\CompanyGoodModel;
 use app\model\GoodModel;
 use app\model\GroupModel;
 use app\model\InventoryExchangeModel;
+use app\model\InventoryShoppingModel;
 use app\model\OrderModel;
 use think\Exception;
 use think\facade\Db;
 use think\response\Json;
 
-class ExchangeLogic extends BaseLogic
+class GoodLogic extends BaseLogic
 {
 
     //商品列表
@@ -21,19 +22,18 @@ class ExchangeLogic extends BaseLogic
     {
         $db = CompanyGoodModel::alias('a')
             ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
-            ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id, 'b.type' => GoodModel::$type_exchange]);
+            ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id]);
 
         $count = $db->count('a.id');
 
         $list = $db
-            ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,c.inventory')
+            ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,b.price,b.type')
             ->page($data['page'], $data['size'])
             ->order(['a.is_top' => 'desc', 'a.weight' => 'desc', 'a.id' => 'desc'])
             ->select()
             ->toArray();
 
-        return json_show(CommonModel::$success, '获取兑换商品列表成功', ['count' => $count, 'list' => $list]);
+        return json_show(CommonModel::$success, '获取商品列表成功', ['count' => $count, 'list' => $list]);
 
     }
 
@@ -41,9 +41,9 @@ class ExchangeLogic extends BaseLogic
     public static function goodInfo(string $code = ''): Json
     {
         $rs = CompanyGoodModel::alias('a')
-            ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_code,b.good_name,b.moq,b.step,b.good_banner_img,b.good_img,b.good_param,b.status,c.inventory,d.unit')
+            ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_code,b.good_name,b.moq,b.step,b.good_banner_img,b.good_img,b.good_param,b.status, 0 inventory,d.unit,b.price,b.type')
             ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
+//            ->leftJoin('inventory_shopping c', 'c.good_id=a.good_id')
             ->leftJoin('unit d', 'd.id=b.unit_id AND d.is_del=' . CommonModel::$del_normal)
             ->where(['a.is_del' => CommonModel::$del_normal, 'a.code' => $code])
             ->withAttr('good_param', function ($val) {
@@ -53,14 +53,16 @@ class ExchangeLogic extends BaseLogic
                 return explode(',', $val);
             })->withAttr('good_banner_img', function ($val) {
                 return explode(',', $val);
+            })->withAttr('inventory', function ($val, $da) {
+                if ($da['type'] == GoodModel::$type_shopping) return InventoryExchangeModel::where(['account_id' => self::$aid, 'good_id' => $da['good_id']])->value('inventory');
+                else return InventoryShoppingModel::where(['good_id' => $da['good_id']])->value('inventory');
             })
             ->findOrEmpty()
             ->toArray();
 
-        return json_show(CommonModel::$success, '获取兑换商品详情成功', $rs);
+        return json_show(CommonModel::$success, '获取商品详情成功', $rs);
 
     }
 
 
-
 }

+ 0 - 65
app/mobile/logic/ShoppingLogic.php

@@ -1,65 +0,0 @@
-<?php
-
-namespace app\mobile\logic;
-
-use app\model\AddrModel;
-use app\model\CommonModel;
-use app\model\CompanyGoodModel;
-use app\model\GoodModel;
-use app\model\GroupModel;
-use app\model\InventoryExchangeModel;
-use app\model\OrderModel;
-use think\Exception;
-use think\facade\Db;
-use think\response\Json;
-
-class ShoppingLogic extends BaseLogic
-{
-
-    //商品列表
-    public static function goodList(array $data = []): Json
-    {
-        $db = CompanyGoodModel::alias('a')
-            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('inventory_shopping c', ' c.good_id=a.good_id')
-            ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id, 'b.type' => GoodModel::$type_shopping]);
-
-        $count = $db->count('a.id');
-
-        $list = $db
-            ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,c.inventory,b.price')
-            ->page($data['page'], $data['size'])
-            ->order(['a.is_top' => 'desc', 'a.weight' => 'desc', 'a.id' => 'desc'])
-            ->select()
-            ->toArray();
-
-        return json_show(CommonModel::$success, '获取商城商品列表成功', ['count' => $count, 'list' => $list]);
-
-    }
-
-    //商品详情
-    public static function goodInfo(string $code = ''): Json
-    {
-        $rs = CompanyGoodModel::alias('a')
-            ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_code,b.good_name,b.moq,b.step,b.good_banner_img,b.good_img,b.good_param,b.status,c.inventory,d.unit,b.price')
-            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('inventory_shopping c', 'c.good_id=a.good_id')
-            ->leftJoin('unit d', 'd.id=b.unit_id AND d.is_del=' . CommonModel::$del_normal)
-            ->where(['a.is_del' => CommonModel::$del_normal, 'a.code' => $code])
-            ->withAttr('good_param', function ($val) {
-                return json_decode($val, true);
-            })
-            ->withAttr('good_img', function ($val) {
-                return explode(',', $val);
-            })->withAttr('good_banner_img', function ($val) {
-                return explode(',', $val);
-            })
-            ->findOrEmpty()
-            ->toArray();
-
-        return json_show(CommonModel::$success, '获取商城商品详情成功', $rs);
-
-    }
-
-
-}

+ 3 - 4
app/mobile/route/app.php

@@ -31,10 +31,9 @@ Route::rule('serviceList', 'Service/list');//服务列表
 Route::rule('serviceRead', 'Service/read');//服务详情
 Route::rule('serviceOrderList', 'Service/orderList');//服务订单列表
 Route::rule('serviceOrderInfo', 'Service/orderInfo');//服务订单详情
-Route::rule('exchangeGoodList', 'Exchange/goodList');//兑换商品列表
-Route::rule('exchangeGoodInfo', 'Exchange/goodInfo');//兑换商品详情
-Route::rule('shoppingGoodList', 'Shopping/goodList');//商城商品列表
-Route::rule('shoppingGoodInfo', 'Shopping/goodInfo');//商城商品详情
+
+Route::rule('goodList', 'Good/goodList');//商品列表
+Route::rule('goodInfo', 'Good/goodInfo');//商品详情
 
 //【订单】
 Route::rule('orderAdd', 'Order/add');//下单