Ver código fonte

Merge branch 'develop' of http://git.caihongxingqiu.net/rainbow/shop-manage into develop

xielin 6 anos atrás
pai
commit
85aa63dabb

+ 1 - 1
.env.example

@@ -24,5 +24,5 @@ PER_PAGE=20
 
 APP_ID=chxq-platform-manage
 CLUSTER=default
-APOLLO_NAMESPACES="application,shop-manage"
+APOLLO_NAMESPACES="application,shop-manage,admin-manage"
 APOLLO_CONFIG_SERVER=http://127.0.0.1:18080

+ 53 - 1
app/Helper/helper.php

@@ -15,4 +15,56 @@ if ( ! function_exists('config_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 [];
+    }
+
+}
+
+function generateSign(array $params, $secret_key)
+{
+    unset($params['sign']);
+    // 将删除参数组中所有等值为FALSE的参数(包括:NULL, 空字符串,0, false)
+    $params = array_filter($params);
+
+    // 按照键名对参数数组进行升序排序
+    ksort($params);
+
+    // 给参数数组追加密钥,键名为 key, 值为签名配置中配置的 secret_key 的值
+    $params['chxq_key'] = $secret_key;
+    \Illuminate\Support\Facades\Log::debug($params);
+    // 生成 URL-encode 之后的请求字符串
+    $str = http_build_query($params);
+    $str = urldecode($str);
+    \Illuminate\Support\Facades\Log::debug($str);
+    //$str = "address=计算机啊手机壳阿看见手机卡&address_type=1&area_id=2&area_name=西安市&city_id=2&city_name=西安市&contact_mobile
+    //=18458881890&contact_name=刘德华&province_id=1&province_name=陕西省&uid=0&zipcode=1000000";
+    // 将请求字符串使用MD5加密后,再转换成大写,并返回
+    return strtoupper(MD5($str));
+}

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

@@ -8,6 +8,7 @@
 
 namespace App\Http\Controllers\V1;
 
+use App\Shop;
 use App\ShopAccount;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
@@ -55,10 +56,15 @@ class AuthController extends Controller {
         if ($validator->fails()) {
             return $this->response->error($validator->errors()->first(), 500);
         }
+
         $account = ShopAccount::where(['account'=>$data['account'],'status'=>1])->first();
         if(!$account){
             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')]);
         if(!$token){
             return $this->response->error('登陆失败', 500);

+ 11 - 2
app/Http/Controllers/V1/IndexController.php

@@ -6,6 +6,7 @@ use App\Repositories\StatisticsRepository;
 use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
+use Tymon\JWTAuth\Facades\JWTAuth;
 
 class IndexController extends Controller
 {
@@ -20,9 +21,14 @@ class IndexController extends Controller
      */
     public function index(Request $request)
     {
+       // $shopId = 1;
+        $token =  JWTAuth::decode(JWTAuth::getToken());
+        if($token['type'] == 2){
+            $shopId = $token['shop']->shop_id;
+        }
 //        $user = Auth::user();
 //        $shopId = $user->shop_id;
-        $shopId = 1;
+ //       $shopId = 1;
         $request = $request->all();
         $start = Carbon::parse(isset($request['start']) ? $request['start'] : Carbon::now())->startOfDay()->format('Y-m-d\TH:i:s\Z');
         $end = Carbon::parse(isset($request['end']) ? $request['end'] : Carbon::now())->endOfDay()->format('Y-m-d\TH:i:s\Z');
@@ -44,7 +50,10 @@ class IndexController extends Controller
     {
 //        $user = Auth::user();
 //        $shopId = $user->shop_id;
-        $shopId = 1;
+        $token =  JWTAuth::decode(JWTAuth::getToken());
+        if($token['type'] == 2){
+            $shopId = $token['shop']->shop_id;
+        }
         $request = $request->all();
         $start = Carbon::parse(isset($request['start']) ? $request['start'] : '-6 days')->startOfDay()->format('Y-m-d\TH:i:s\Z');
         $end = Carbon::parse(isset($request['end']) ? $request['end'] : Carbon::now())->endOfDay()->format('Y-m-d\TH:i:s\Z');

+ 67 - 1
app/Http/Controllers/V1/ShopController.php

@@ -9,12 +9,12 @@
 namespace App\Http\Controllers\V1;
 
 
+use App\Repositories\ProductRepository;
 use App\Repositories\ShopRepository;
 use App\Shop;
 use App\ShopAccount;
 use App\Transformers\ShopsTransformer;
 use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Validation\Rule;
 use League\Fractal\Manager;
@@ -22,6 +22,8 @@ use League\Fractal\Resource\Item;
 use League\Fractal\Resource\Collection;
 use League\Fractal\Pagination\IlluminatePaginatorAdapter;
 use Tymon\JWTAuth\Facades\JWTAuth;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
 
 class ShopController extends Controller {
 
@@ -149,6 +151,48 @@ class ShopController extends Controller {
         $data['extra']['columns'] = ['shop_id','shop_name','mobile','province_name','city_name','product_count','proportion','status'];
         return $data;
     }
+
+    /**
+     * @param Request $request
+     * @return array
+     */
+    public function isOpen(Request $request){
+        $data = $request->only('shop_id','status');
+        $validator = Validator::make($data, [
+            'shop_id' => 'required|integer',
+            'status' =>['required',Rule::in([0,1])],
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        DB::beginTransaction();
+        try {
+            $res = Shop::where(['shop_id'=>$data['shop_id']])->update(['status'=>$data['status']]);
+            if($res){
+                //下架商家所有商品
+                if($data['status'] == 0){
+                    $product = new ProductRepository();
+                    $upStatus = $product->upProductStatus($data['shop_id']);
+                    if(isset($upStatus['status_code']) && $upStatus['status_code'] == 200){
+                        DB::commit();
+                        Log::info('商家id'.$data['shop_id'].'商品禁售成功');
+                        return  ['message'  => '成功','status_code'   => 200];
+                    }else{
+                        Log::info('商家id'.$data['shop_id'].'商品禁售失败');
+                        return  ['message'  => '商品禁售失败','status_code'   => 500];
+                    }
+                }
+                DB::commit();
+                return  ['message'  => '成功','status_code'   => 200];
+            }else{
+                return $this->response->error("失败", 500);
+            }
+        } catch (\Exception $e) {
+            DB::rollBack();
+            return $this->response->error("失败", 500);
+        }
+
+    }
     /**
      * @param Request $request
      * @return mixed
@@ -167,5 +211,27 @@ class ShopController extends Controller {
         }
     }
 
+    /**
+     * @param Request $request
+     * @return array
+     * 删除账号
+     */
+    public function deleteShopAccount(Request $request){
+        $data = $request->only('shop_id');
+        $validator = Validator::make($data, [
+            'id' => 'required|integer',
+            'shop_id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $res = ShopAccount::where(['id'=>$data['id'],'shop_id'=>$data['shop_id']])->delete();
+        if($res){
+            //下架商家所有商品,放入队列
+            return  ['message'  => '成功','status_code'   => 200];
+        }else{
+            return $this->response->error("失败", 500);
+        }
+    }
 
 }

+ 30 - 0
app/Repositories/ProductRepository.php

@@ -0,0 +1,30 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-05-20
+ * Time: 17:05
+ */
+
+namespace App\Repositories;
+use Tymon\JWTAuth\Facades\JWTAuth;
+use Illuminate\Support\Facades\Log;
+
+class ProductRepository {
+
+    public function upProductStatus($shop_id) {
+        try {
+            //$sign = generateSign(['shop_id'=>$shop_id], config('customer.app_secret'));
+            $url = config("customer.manage_service_url").'/product/operate/product/shop_status';
+            Log::info('禁售商户商品请求参数url'.$url.'商品禁售成功');
+            //$url = 'http://localhost:8080/userInfo';
+            $array = [
+                'json' => ['shop_id'=>$shop_id], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            Log::info('禁售商户商品请求参数'.json_encode($array).'商品禁售成功');
+            return http($url,$array,false,'put');
+        } catch (\Exception $e) {
+            return [];
+        }
+    }
+}

+ 4 - 2
app/Repositories/ShopRepository.php

@@ -9,6 +9,7 @@ namespace App\Repositories;
 
 use App\Shop;
 use App\ShopAccount;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Hash;
 use League\Flysystem\Exception;
 
@@ -57,8 +58,6 @@ class ShopRepository {
             return false;
         }
     }
-
-
     //修改
     public function editShopAccount($data = []){
         $shop_id = $data['shop_id'];
@@ -69,6 +68,7 @@ class ShopRepository {
         unset($data['shop_id']);
         unset($data['shop_account_id']);
         unset($data['account']);
+        DB::beginTransaction();
         try{
             $shop = Shop::where(['shop_id'=>$shop_id])->update($data);
             $accountData = [];
@@ -78,8 +78,10 @@ class ShopRepository {
                 $accountData['password'] = Hash::make($password);
                 ShopAccount::where(['id'=>$shop_account_id])->update($accountData);
             }
+            DB::commit();
             return true;
         }catch (Exception $exception){
+            DB::rollBack();
             return false;
         }
     }

+ 2 - 0
bootstrap/app.php

@@ -29,6 +29,8 @@ $app->configure('apollo');
 $app->configure('auth');
 $app->configure('jwt');
 $app->configure('menu');
+$app->configure('database');
+$app->configure('customer');
 
 /*
 |--------------------------------------------------------------------------

+ 1 - 0
composer.json

@@ -7,6 +7,7 @@
     "require": {
         "php": ">=7.1.3",
         "dingo/api": "^2.2",
+        "guzzlehttp/guzzle": "^6.3",
         "cviebrock/laravel-elasticsearch": "^3.5",
         "hhxsv5/laravel-s": "~3.4.0",
         "laravel/lumen-framework": "5.8.*",

+ 131 - 0
config/database.php

@@ -0,0 +1,131 @@
+<?php
+
+return [
+
+    /*
+    |--------------------------------------------------------------------------
+    | Default Database Connection Name
+    |--------------------------------------------------------------------------
+    |
+    | Here you may specify which of the database connections below you wish
+    | to use as your default connection for all database work. Of course
+    | you may use many connections at once using the Database library.
+    |
+    */
+
+    'default' => env('DB_CONNECTION', 'mysql'),
+
+    /*
+    |--------------------------------------------------------------------------
+    | Database Connections
+    |--------------------------------------------------------------------------
+    |
+    | Here are each of the database connections setup for your application.
+    | Of course, examples of configuring each database platform that is
+    | supported by Laravel is shown below to make development simple.
+    |
+    |
+    | All database work in Laravel is done through the PHP PDO facilities
+    | so make sure you have the driver for your particular database of
+    | choice installed on your machine before you begin development.
+    |
+    */
+
+    'connections' => [
+
+        'sqlite' => [
+            'driver' => 'sqlite',
+            'database' => env('DB_DATABASE', database_path('database.sqlite')),
+            'prefix' => env('DB_PREFIX', ''),
+        ],
+
+        'mysql' => [
+            'driver' => 'mysql',
+            'host' => env('DB_HOST', '127.0.0.1'),
+            'port' => env('DB_PORT', 3306),
+            'database' => env('DB_DATABASE', 'forge'),
+            'username' => env('DB_USERNAME', 'forge'),
+            'password' => env('DB_PASSWORD', ''),
+            'unix_socket' => env('DB_SOCKET', ''),
+            'charset' => env('DB_CHARSET', 'utf8mb4'),
+            'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
+            'prefix' => env('DB_PREFIX', ''),
+            'strict' => env('DB_STRICT_MODE', true),
+            'engine' => env('DB_ENGINE', null),
+            'timezone' => env('DB_TIMEZONE', '+08:00'),
+        ],
+
+        'pgsql' => [
+            'driver' => 'pgsql',
+            'host' => env('DB_HOST', '127.0.0.1'),
+            'port' => env('DB_PORT', 5432),
+            'database' => env('DB_DATABASE', 'forge'),
+            'username' => env('DB_USERNAME', 'forge'),
+            'password' => env('DB_PASSWORD', ''),
+            'charset' => env('DB_CHARSET', 'utf8'),
+            'prefix' => env('DB_PREFIX', ''),
+            'schema' => env('DB_SCHEMA', 'public'),
+            'sslmode' => env('DB_SSL_MODE', 'prefer'),
+        ],
+
+        'sqlsrv' => [
+            'driver' => 'sqlsrv',
+            'host' => env('DB_HOST', 'localhost'),
+            'port' => env('DB_PORT', 1433),
+            'database' => env('DB_DATABASE', 'forge'),
+            'username' => env('DB_USERNAME', 'forge'),
+            'password' => env('DB_PASSWORD', ''),
+            'charset' => env('DB_CHARSET', 'utf8'),
+            'prefix' => env('DB_PREFIX', ''),
+        ],
+
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Migration Repository Table
+    |--------------------------------------------------------------------------
+    |
+    | This table keeps track of all the migrations that have already run for
+    | your application. Using this information, we can determine which of
+    | the migrations on disk haven't actually been run in the database.
+    |
+    */
+
+    'migrations' => 'migrations',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Redis Databases
+    |--------------------------------------------------------------------------
+    |
+    | Redis is an open source, fast, and advanced key-value store that also
+    | provides a richer set of commands than a typical key-value systems
+    | such as APC or Memcached. Laravel makes it easy to dig right in.
+    |
+    */
+
+    'redis' => [
+
+        'client' => 'predis',
+
+        'cluster' => env('REDIS_CLUSTER', false),
+
+        'default' => [
+            'host' => env('REDIS_HOST', '127.0.0.1'),
+            'password' => env('REDIS_PASSWORD', null),
+            'port' => env('REDIS_PORT', 6379),
+            'database' => env('REDIS_DB', 0),
+            'read_write_timeout' => 0,
+        ],
+
+        'cache' => [
+            'host' => env('REDIS_HOST', '127.0.0.1'),
+            'password' => env('REDIS_PASSWORD', null),
+            'port' => env('REDIS_PORT', 6379),
+            'database' => env('REDIS_CACHE_DB', 1),
+        ],
+
+    ],
+
+];

+ 10 - 0
config/menu.php

@@ -10,6 +10,16 @@ return [
         'name' => 'management',
         'title' => '商家',
         'children' => [
+            [
+                'name' => 'index',
+                'title' => '首页',
+                'children' => [
+                    [
+                        'name' => 'statistics-shop',
+                        'title' => '统计',
+                    ],
+                ],
+            ],
             [
                 'name' => 'product',
                 'title' => '商品',

+ 3 - 8
routes/api.php

@@ -45,16 +45,11 @@ $api->version('v1', [
         //用户列表
         //商户详情
         $api->get('shopView', 'ShopController@view');
+        //修改状态
+        $api->put('isOpen', 'ShopController@isOpen');
 
         $api->get('user', 'UserController@index');
-        //用户列表
-        $api->get('memberList', 'MemberController@memberList');
-        //用户详情
-        $api->post('memberView', 'MemberController@view');
-        //修改状态
-        $api->put('updateStatus', 'MemberController@updateStatus');
-        //设置属性
-        $api->post('setAttr', 'MemberController@setAttr');
+
         //公共配置
         $api->post('configIndex', 'ConfigController@index');
     });

+ 0 - 0
storage/.gitkeep