wufeng hace 2 años
padre
commit
8a310a1b9d

+ 5 - 0
app/mobile/config/validate_rules.php

@@ -44,4 +44,9 @@ return [
         'new_password|新密码' => 'require|min:6|max:255',
     ],
 
+    //商品详情
+    'goodInfo'=>[
+        'code|编码'=>'require|length:18'
+    ],
+
 ];

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

@@ -0,0 +1,33 @@
+<?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);
+    }
+
+
+}

+ 61 - 0
app/mobile/logic/ExchangeLogic.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace app\mobile\logic;
+
+use app\model\CommonModel;
+use app\model\CompanyGoodModel;
+use app\model\GoodModel;
+use app\model\GroupModel;
+use think\response\Json;
+
+class ExchangeLogic extends BaseLogic
+{
+
+    //商品列表
+    public static function goodList(array $data = []): Json
+    {
+
+        $group_id = GroupModel::where(['is_del' => CommonModel::$del_normal, 'company_id' => self::$company_id, 'card_id' => self::$card_id])
+            ->value('id', 0);
+        if (!$group_id) return json_show(CommonModel::$error_param, '该账户所对应的分组不存在');
+
+
+        $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('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' => $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')
+            ->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')
+            ->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('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);
+            })
+            ->findOrEmpty()
+            ->toArray();
+
+        return json_show(CommonModel::$success, '获取兑换商品详情成功', $rs);
+
+    }
+
+
+}

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

@@ -21,5 +21,8 @@ Route::rule('addrDelete', 'Addr/delete');//删除
 Route::rule('serviceList', 'Service/list');//列表
 Route::rule('serviceRead', 'Service/read');//读取
 
+//【兑换商品】
+Route::rule('exchangeGoodList', 'Exchange/goodList');//商品列表
+Route::rule('exchangeGoodInfo', 'Exchange/goodInfo');//商品详情