Explorar el Código

商城商品列表和详情

wufeng hace 2 años
padre
commit
ec55b9ef2e

+ 1 - 1
app/admin/logic/GoodLogic.php

@@ -25,7 +25,7 @@ class GoodLogic extends BaseLogic
         $count = $db->count('a.id');
 
         $list = $db
-            ->field('a.id,a.good_cover_img,a.good_code,a.good_name,a.moq,a.step,b.unit,a.good_remark,a.type,a.status,a.creater,a.addtime')
+            ->field('a.id,a.good_cover_img,a.good_code,a.good_name,a.moq,a.step,b.unit,a.good_remark,a.type,a.price,a.status,a.creater,a.addtime')
             ->page($data['page'], $data['size'])
             ->order('a.addtime desc')
             ->select()

+ 33 - 0
app/mobile/controller/Shopping.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace app\mobile\controller;
+
+use app\BaseController;
+use app\mobile\logic\ShoppingLogic;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
+
+//商城商品
+class Shopping extends BaseController
+{
+    //商城商品列表
+    public function goodList()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10], 'post');
+        return ShoppingLogic::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 ShoppingLogic::goodInfo($code);
+    }
+
+
+}

+ 2 - 2
app/mobile/logic/ExchangeLogic.php

@@ -20,9 +20,9 @@ class ExchangeLogic extends BaseLogic
     public static function goodList(array $data = []): Json
     {
         $db = CompanyGoodModel::alias('a')
-            ->leftJoin('good b', 'b.id=a.good_id AND b.type=' . GoodModel::$type_exchange . ' AND b.is_del=' . CommonModel::$del_normal)
+            ->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]);
+            ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id, 'b.type' => GoodModel::$type_exchange]);
 
         $count = $db->count('a.id');
 

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

@@ -0,0 +1,63 @@
+<?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\OrderExchangeModel;
+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')
+            ->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);
+            })
+            ->findOrEmpty()
+            ->toArray();
+
+        return json_show(CommonModel::$success, '获取商城商品详情成功', $rs);
+
+    }
+
+
+}

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

@@ -28,4 +28,7 @@ Route::rule('exchangeOrderAdd', 'Exchange/orderAdd');//兑换商品下单
 Route::rule('exchangeOrderList', 'Exchange/orderList');//兑换订单列表
 Route::rule('exchangeOrderInfo', 'Exchange/orderInfo');//兑换订单详情
 
+//【商城商品】
+Route::rule('shoppingGoodList', 'Shopping/goodList');//商城商品列表
+Route::rule('shoppingGoodInfo', 'Shopping/goodInfo');//商城商品详情