wesmiler 1 year ago
parent
commit
09d6666375

+ 2 - 89
app/Http/Controllers/Api/v1/GoodsController.php

@@ -24,7 +24,7 @@ class GoodsController extends webApp
        try {
            $params = request()->post();
            $pageSize = request()->post('pageSize', 0);
-           $datas = GoodsService::make()->getDataList($params, $pageSize,'', $this->userId);
+           $datas = GoodsService::make()->getApiDataList($params, $pageSize,'', $this->userId);
            return showJson(1010, true, $datas);
        } catch (\Exception $exception){
            RedisService::set("caches:request:error_goods_index", ['trace'=>$exception->getTrace()], 7200);
@@ -33,23 +33,6 @@ class GoodsController extends webApp
     }
 
     /**
-     * 列表
-     * @return array
-     */
-    public function list()
-    {
-        try {
-            $params = request()->post();
-            $pageSize = request()->post('pageSize', 0);
-            $datas = GoodsService::make()->getDataList($params, $pageSize,'lev_a.*,lev_c.name as merch_name', $this->userId);
-            return showJson(1010, true, $datas);
-        } catch (\Exception $exception){
-            RedisService::set("caches:request:error_goods_index", ['trace'=>$exception->getTrace()], 7200);
-            return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getTrace() : '']);
-        }
-    }
-
-    /**
      * 分类
      * @return array
      */
@@ -68,78 +51,8 @@ class GoodsController extends webApp
     public function info()
     {
         $id = request()->post('id', 0);
-        $info = GoodsService::make()->getInfo($id, $this->userId);
+        $info = GoodsService::make()->getApiInfo($id);
         return showJson(1010, true, $info);
     }
 
-    /**
-     * 推荐
-     * @return array
-     */
-    public function recommend()
-    {
-        try {
-            $params = request()->post();
-            $pageSize = request()->post('pageSize', 0);
-            $lng = isset($params['lng'])? $params['lng'] : '';
-            $lat = isset($params['lat'])? $params['lat'] : '';
-            $params = [
-                'lat'=>  $lat? $lat : (isset($this->userInfo['lat'])? $this->userInfo['lat'] : ''),
-                'lng'=>  $lng? $lng : (isset($this->userInfo['lng'])? $this->userInfo['lng'] : ''),
-                'sort_type'=> 1,
-                'is_recommend'=> 1,
-                'type'=> isset($params['type'])? intval($params['type']) : 2,
-                'status'=> 2,
-            ];
-            $datas = GoodsService::make()->getDataList($params, $pageSize);
-            return showJson(1010, true, $datas);
-        } catch (\Exception $exception){
-            RedisService::set("caches:request:error_goods_recommend", ['trace'=>$exception->getTrace()], 7200);
-            return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
-        }
-
-    }
-
-    /**
-     * 发布
-     * @param GoodsValidator $validator
-     * @return array
-     */
-    public function submit(GoodsValidator $validator)
-    {
-        $params = request()->all();
-        $params = $validator->check($params, 'submit');
-        if (!is_array($params)) {
-            return showJson($params, false);
-        }
-
-        if(!$result = GoodsService::make()->submit($this->userId, $params)){
-            return showJson(GoodsService::make()->getError(), false);
-        }else{
-            return showJson(GoodsService::make()->getError(), true, $result);
-        }
-    }
-
-    /**
-     * 状态/上下架
-     * @return array|mixed
-     */
-    public function status()
-    {
-        if(!$result = GoodsService::make()->status()){
-            return showJson(GoodsService::make()->getError(), false);
-        }else{
-            return showJson(GoodsService::make()->getError(), true, $result);
-        }
-    }
-
-    /**
-     * 删除
-     * @return array|mixed
-     */
-    public function delete()
-    {
-       return GoodsService::make()->delete();
-    }
-
 }

File diff suppressed because it is too large
+ 54 - 575
app/Services/Api/GoodsService.php


+ 34 - 1
app/Services/SupplyService.php

@@ -131,8 +131,41 @@ class SupplyService extends BaseService
         return md5($str);
     }
 
-    public function goodsList()
+    /**
+     * 获取接口数据
+     * @param string $apiName 接口名称
+     * @param array $params 接口参数
+     * @param string $requestType 请求方式
+     * @param int $timeout 超时时间/秒
+     * @return array|false|mixed|string
+     */
+    public function getApiData($apiName, $params=[], $requestType='post', $timeout=5)
     {
+        $url = isset(self::$apiUrls[$apiName])?self::$apiUrls[$apiName] : '';
+        if(empty($url)){
+            $this->error = 1044;
+            return false;
+        }
 
+        if(!$this->getToken()){
+            $this->error = 1046;
+            return false;
+        }
+
+        $params['access_token'] = self::$accessToken;
+
+        $url = self::$apiUrl.$url;
+        RedisService::set("caches:supply:".self::$appId.'_'.self::$supplyMobile.":{$apiName}_request",['url'=>$url,'params'=> $params], 600);
+        $result = httpRequest($url,$params,$requestType,'',$timeout);
+        RedisService::set("caches:supply:".self::$appId.'_'.self::$supplyMobile.":{$apiName}_result",['url'=>$url,'params'=> $params,'result'=>$result], 600);
+        $errCode = isset($result['error_code'])? $result['error_code'] : '';
+        $errMsg = isset($result['error_msg'])? $result['error_msg'] : '';
+        $result = isset($result['result'])? $result['result'] : [];
+        if($errCode == 0){
+            return $result;
+        }else{
+            $this->error = $errMsg? $errMsg : 1045;
+            return false;
+        }
     }
 }

+ 15 - 0
config/goods.php

@@ -0,0 +1,15 @@
+<?php
+
+return [
+    'supplyList' => [
+        1 => '京东',
+        2 => '星链',
+        4 => '云商特卖',
+        5 => '厂商特卖',
+        7 => '微唯宝特卖',
+        9 => '三方仓储',
+        10 => '华南一仓',
+        12 => '华南二仓',
+        17 => '华东一仓',
+    ]
+];

+ 3 - 0
resources/lang/zh-cn/api.php

@@ -43,6 +43,9 @@ return [
     '1041' => '账户不存在',
     '1042' => '账户处理失败',
     '1043' => '账户明细处理失败',
+    '1044' => '供应链接口未配置',
+    '1045' => '供应链请求失败,请检查配置',
+    '1046' => '供应链授权失败,请检查配置',
 
     // 登录注册
     '2001'=> '账号非法或未注册',