Quellcode durchsuchen

修改商家登录,新增修改商家状态

zhangchangchun vor 6 Jahren
Ursprung
Commit
24fecf235f

+ 30 - 0
app/Helper/helper.php

@@ -15,4 +15,34 @@ if ( ! function_exists('config_path'))
     {
     {
         return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
         return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
     }
     }
+}
+
+/**
+ * @param $url 地址
+ * @param $param 参数
+ * @param bool $isCheck 是否检查返回结果
+ * @param string $method 请求方式
+ * @return array|mixed
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+function http($url, $param, $isCheck = true, $method = 'post')
+{
+    try {
+        $client = new \GuzzleHttp\Client();
+        $response = $client->request($method, $url, $param);
+        $result = json_decode($response->getBody()->getContents(), true);
+        if ($isCheck == true) {
+            if ($result['code'] == 0) {
+                return $result['data'];
+            } else {
+                return [];
+            }
+        } else {
+            return $result;
+        }
+
+    } catch (\Exception $exception) {
+        return [];
+    }
+
 }
 }

+ 6 - 0
app/Http/Controllers/V1/AuthController.php

@@ -8,6 +8,7 @@
 
 
 namespace App\Http\Controllers\V1;
 namespace App\Http\Controllers\V1;
 
 
+use App\Shop;
 use App\ShopAccount;
 use App\ShopAccount;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Auth;
@@ -55,10 +56,15 @@ class AuthController extends Controller {
         if ($validator->fails()) {
         if ($validator->fails()) {
             return $this->response->error($validator->errors()->first(), 500);
             return $this->response->error($validator->errors()->first(), 500);
         }
         }
+
         $account = ShopAccount::where(['account'=>$data['account'],'status'=>1])->first();
         $account = ShopAccount::where(['account'=>$data['account'],'status'=>1])->first();
         if(!$account){
         if(!$account){
             return $this->response->error('登录失败,请重试', 500);
             return $this->response->error('登录失败,请重试', 500);
         }
         }
+        $shop = Shop::where(['shop_id'=>$account->shop_id,'status'=>1])->first();
+        if(!$shop){
+            return $this->response->error('登录失败,该商家不存在或已禁用', 500);
+        }
         $token = Auth::attempt(['account'=>$request->get('account'),'password'=>$request->get('password')]);
         $token = Auth::attempt(['account'=>$request->get('account'),'password'=>$request->get('password')]);
         if(!$token){
         if(!$token){
             return $this->response->error('登陆失败', 500);
             return $this->response->error('登陆失败', 500);

+ 15 - 3
app/Http/Controllers/V1/ShopController.php

@@ -9,6 +9,7 @@
 namespace App\Http\Controllers\V1;
 namespace App\Http\Controllers\V1;
 
 
 
 
+use App\Repositories\ProductRepository;
 use App\Repositories\ShopRepository;
 use App\Repositories\ShopRepository;
 use App\Shop;
 use App\Shop;
 use App\ShopAccount;
 use App\ShopAccount;
@@ -149,7 +150,11 @@ class ShopController extends Controller {
         $data['extra']['columns'] = ['shop_id','shop_name','mobile','province_name','city_name','product_count','proportion','status'];
         $data['extra']['columns'] = ['shop_id','shop_name','mobile','province_name','city_name','product_count','proportion','status'];
         return $data;
         return $data;
     }
     }
-    //删除商家
+
+    /**
+     * @param Request $request
+     * @return array
+     */
     public function isOpen(Request $request){
     public function isOpen(Request $request){
         $data = $request->only('shop_id','status');
         $data = $request->only('shop_id','status');
         $validator = Validator::make($data, [
         $validator = Validator::make($data, [
@@ -161,8 +166,15 @@ class ShopController extends Controller {
         }
         }
         $res = Shop::where(['shop_id'=>$data['shop_id']])->update(['status'=>$data['status']]);
         $res = Shop::where(['shop_id'=>$data['shop_id']])->update(['status'=>$data['status']]);
         if($res){
         if($res){
-            //下架商家所有商品,放入队列
-            return  ['message'  => '成功','status_code'   => 200];
+            //下架商家所有商品
+            if($data['status'] == 0){
+                $product = new ProductRepository();
+                $upStatus = $product->upProductStatus($data['shop_id']);
+                if($upStatus['status_code'] == 200){
+                    return  ['message'  => '成功','status_code'   => 200];
+                }
+            }
+
         }else{
         }else{
             return $this->response->error("失败", 500);
             return $this->response->error("失败", 500);
         }
         }

+ 26 - 0
app/Repositories/ProductRepository.php

@@ -0,0 +1,26 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-05-20
+ * Time: 17:05
+ */
+
+namespace App\Repositories;
+use Tymon\JWTAuth\Facades\JWTAuth;
+
+class ProductRepository {
+    public function upProductStatus($shop_id) {
+        try {
+            $sign = generateSign(['shop_id'=>$shop_id], config('customer.app_secret'));
+            $url = config("customer.app_service_url").'/operate/product/shop_status';
+            //$url = 'http://localhost:8080/userInfo';
+            $array = [
+                'json' => ['sign' => $sign,'shop_id'=>$shop_id], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array,false);
+        } catch (\Exception $e) {
+            return [];
+        }
+    }
+}

+ 0 - 2
app/Repositories/ShopRepository.php

@@ -58,8 +58,6 @@ class ShopRepository {
             return false;
             return false;
         }
         }
     }
     }
-
-
     //修改
     //修改
     public function editShopAccount($data = []){
     public function editShopAccount($data = []){
         $shop_id = $data['shop_id'];
         $shop_id = $data['shop_id'];