Просмотр исходного кода

[智价云] 数据清洗-低价商品接口更新

tangyuanwang 2 недель назад
Родитель
Сommit
1602d8410d

+ 45 - 6
app/Exceptions/Handler.php

@@ -2,15 +2,17 @@
 
 namespace App\Exceptions;
 
+use App\Exceptions\Api\ApiException;
 use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
+use App\Facades\Servers\Logs\Log;
 use Throwable;
 
 class Handler extends ExceptionHandler
 {
     /**
-     * A list of the exception types that are not reported.
+     * 不报告的异常类型的列表
      *
-     * @var array<int, class-string<Throwable>>
+     * @var array
      */
     protected $dontReport = [
         //
@@ -19,7 +21,7 @@ class Handler extends ExceptionHandler
     /**
      * A list of the inputs that are never flashed for validation exceptions.
      *
-     * @var array<int, string>
+     * @var array
      */
     protected $dontFlash = [
         'current_password',
@@ -34,8 +36,45 @@ class Handler extends ExceptionHandler
      */
     public function register()
     {
-        $this->reportable(function (Throwable $e) {
-            //
-        });
+        $this->reportable(function (Throwable $e) {})->stop();
     }
+
+
+    /**
+     * 将异常呈现到HTTP响应中
+     * 
+     * 
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function render($request, Throwable $e){
+        // 如果是异常类型,获取异常的消息
+        $msg            = $e->getMessage();
+        // 错误信息
+        $msg            = $msg ? $msg : '404';
+        // 错误数据
+        $data           = '';
+        // 错误码
+        $code           = 'sys_error';
+        // http状态码
+        $status         = 200;
+        // 日志信息
+        $message        = request()->ip().' ' .request()->method().' '. request()->getPathInfo().' '.$msg .' of file '.$e->getFile().' on line '.$e->getLine();
+        // 如果是接口异常
+        if( $e instanceof ApiException ){
+            // 错误码
+            $code       = $e->getErrCode();
+            // 错误数据
+            $data       = $e->getErrData();
+        }else{
+            // 拼接报错文件位置
+            $message    .= ' of file '.$e->getFile().' on line '.$e->getLine();
+        }
+        // 要返回的数据
+        $data           = ['code'=>($code == 'sys_error' ? 'error' : $code),'msg'=>$msg,'data'=>$data];
+        // 记录日志
+        Log::info($code,$message,['param'=>request()->all(),'return'=>$data,'user_agent'=>request()->header('user-agent')],['filename'=>str_ireplace('/','_',trim(request()->getPathInfo(),'/'))]);
+        // 返回结果
+        return          response()->json($data,$status,[],JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
+    }
+
 }

+ 12 - 0
app/Http/Controllers/Manager/WashConfig/LowPriceGoods.php

@@ -79,6 +79,12 @@ class LowPriceGoods extends Controller
         $request->scene('add')->validate();
         // 接收数据
         $all_data = request()->all();
+        $store_scope = request('store_scope', '');
+        $all_data['store_scope'] = $store_scope;
+        //查询是否存在
+        $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
+        $data = $LowPriceGoodsModel->where($map)->first();
+        if ($data)     return json_send(['code' => 'error', 'msg' => '记录已存在']);
         // 写入数据表
         $result     =  $LowPriceGoodsModel->addLowProduct($all_data);
         // 如果操作失败
@@ -101,6 +107,12 @@ class LowPriceGoods extends Controller
         $id         = request('id', 0);
         // 接收数据
         $all_data = request()->all();
+        $store_scope = request('store_scope','');
+        $all_data['store_scope'] = $store_scope;
+                //查询是否存在
+        $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
+        $data = $LowPriceGoodsModel->where($map)->where('id', '!=', $id)->first();
+        if ($data)     return json_send(['code' => 'error', 'msg' => '记录已存在']);
         // 更新数据表
         $where = ['id' => $id];
         $result =  $LowPriceGoodsModel->updateLowProduct($where, $all_data);

+ 0 - 1
app/Http/Middleware/Manager/AccessAuth.php

@@ -48,7 +48,6 @@ class AccessAuth
         $path  = ltrim($request->getPathInfo(), '/');
         // 判断是否需要验证登录
         if (!in_array($path, $this->except)) {
-            echo 1;exit;
             // 用户ID
             $uid                                                    = request('access_token.uid', 0);
             // 如果未登录

+ 2 - 2
app/Http/Requests/Manager/WashConfig/LowPriceGoods.php

@@ -42,8 +42,8 @@ class LowPriceGoods extends BaseRequest
     protected   $scenes         = [
         'detail'             => ['id'],
         'list'               => ['page', 'limit'],
-        'add'                      => ['product_name', 'product_specs', 'suggested_price', 'store_scope'],
-        'edit'                  => ['id', 'product_name', 'product_specs', 'suggested_price', 'store_scope'],
+        'add'                      => ['product_name', 'product_specs', 'suggested_price'],
+        'edit'                  => ['id', 'product_name', 'product_specs', 'suggested_price'],
         'set_status'              => ['id', 'status'],
         'delete'                  => ['id'],
     ];

+ 0 - 1
app/Models/Manager/WashConfig/LowPriceGoods.php

@@ -20,7 +20,6 @@ class LowPriceGoods extends Model
     protected $table = 'washconfig_lowprice_produce';
     // 是否主动维护时间戳
     public $timestamps = false;
-    protected   $connection = 'company';
     // 定义时间戳字段名
     // const CREATED_AT = 'insert_time';
     // const UPDATED_AT = 'update_time';