xielin 6 years ago
parent
commit
a60a1c7c93

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

@@ -53,18 +53,18 @@ class AuthController extends Controller {
             'password' => 'required|max:32',
         ]);
         if ($validator->fails()) {
-            return $this->jsonError($validator->errors()->first());
+            return $this->response->error($validator->errors()->first(), 500);
         }
-        $account = ShopAccount::where('account',$data['account'])->first();
+        $account = ShopAccount::where(['account'=>$data['account'],'status'=>1])->first();
         if(!$account){
-            return $this->jsonError('登录失败,请重试');
+            return $this->response->error('登录失败,请重试', 500);
         }
         $token = Auth::attempt(['mobile'=>$request->get('mobile'),'password'=>$request->get('password')]);
         if(!$token){
-            return $this->jsonError('登陆失败');
+            return $this->response->error('登陆失败', 500);
         }else{
             $shopAccount = Auth::user();
-            $factory = JWTFactory::customClaims(['shop'=>['uid'=>$shopAccount->id,'shop_id'=>$shopAccount->shop_id,'sign'=>md5($shopAccount->id).env('JWT_SECRET')]]);
+            $factory = JWTFactory::customClaims(['shop'=>['uid'=>$shopAccount->id,'username'=>$shopAccount->account,'shop_id'=>$shopAccount->shop_id,'sign'=>md5($shopAccount->id).env('JWT_SECRET')],'type'=>2]);
             $payload = $factory->make();
 
             $token = JWTAuth::encode($payload);
@@ -75,7 +75,7 @@ class AuthController extends Controller {
             $res = new Item($shopAccount,new LoginTransformer());
             $array = $fractal->createData($res)->toArray();
             //日志
-            return $this->jsonSuccess($array);
+            return $array;
         }
     }
 

+ 34 - 0
app/Http/Controllers/V1/ConfigController.php

@@ -0,0 +1,34 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-04-26
+ * Time: 10:30
+ */
+
+namespace App\Http\Controllers\V1;
+
+
+use App\MemberAttr;
+
+class ConfigController extends Controller {
+
+    public function __construct( )
+    {
+    }
+    //公共参数
+    public function index(){
+        return [
+            //订单状态 0-待付款 1-待发货 2-已发货 3-配送中 4-待自提 5-已自提 6-已完成  7-已关闭
+            'status'=>[
+                '1' =>'正常' ,
+                '0' =>'禁用',
+
+            ],
+            'verify_type'=>[
+                '1' => '不需审核',
+                '0' =>'需要审核',
+            ],
+        ];
+    }
+}

+ 68 - 20
app/Http/Controllers/V1/ShopController.php

@@ -39,9 +39,9 @@ class ShopController extends Controller {
             'mobile' => 'required|max:11',
             'address' => 'required|string',
             'province_name' => 'required|string|max:50',
-            'province_id' => 'required|integer|max:6',
+            'province_id' => 'required|integer|digits_between:1,7',
             'city_name' => 'required|string:max:50',
-            'city_id' => 'required|integer|max:6',
+            'city_id' => 'required|integer|digits_between:1,7',
             'contact_name' => 'string|max:50',
             'contact_mobile' => 'max:16',
             'shop_desc' => 'string|max:500',
@@ -53,44 +53,90 @@ class ShopController extends Controller {
             'proportion'=>'required|digits_between:1,100|integer',
             'verify_type'=>['required',Rule::in([0,1])],
             'account'=>'string|max:20',
-            'password'=>'string|min:6|max:18'
+            'password'=>'string|min:6|max:18',
+//            'shop_id'=>'integer',
+//            'shop_account_id'=>'integer',
         ]);
         if ($validator->fails()) {
-            return $this->jsonError($validator->errors()->first());
+            return $this->response->error($validator->errors()->first(), 500);
         }
-        if($data['account']){
-            $shop_account = ShopAccount::where(['account'=>$data['account']])->first();
-            if($shop_account){
-                return $this->jsonError('该账号已存在,请重新输入');
-            }
+        $shop = Shop::where(['shop_name'=>$data['account']])->first();
+        if($shop){
+            return $this->response->error('该商户已存在,请重新输入', 500);
+        }
+        $shop_account = ShopAccount::where(['account'=>$data['account']])->first();
+        if($shop_account){
+            return $this->response->error('该账号已存在,请重新输入', 500);
         }
         $shopRepository = new ShopRepository();
         $res = $shopRepository->saveShopAccount($data);
         if($res){
-            return $this->jsonSuccess();
+            return  ['message'  => '成功','status_code'   => 200];
         }else{
-            return $this->jsonError('添加失败');
+            return $this->response->error("失败", 500);
+        }
+    }
+
+    public function editShop(Request $request)
+    {
+        $data = $request->all();
+        $validator = Validator::make($data, [
+            'shop_name' => 'required|max:11',
+            'shop_short_name' => 'required|string|max:100',
+            'mobile' => 'required|max:11',
+            'address' => 'required|string',
+            'province_name' => 'required|string|max:50',
+            'province_id' => 'required|integer|digits_between:1,7',
+            'city_name' => 'required|string:max:50',
+            'city_id' => 'required|integer|digits_between:1,7',
+            'contact_name' => 'string|max:50',
+            'contact_mobile' => 'max:16',
+            'shop_desc' => 'string|max:500',
+            'status' =>['required',Rule::in([0,1])],
+            'logo_img' => 'string',
+            'license_img' => 'required|string',
+            'food_trans_license' => 'required|string',
+            'other_license' => 'string',
+            'proportion'=>'required|digits_between:1,100|integer',
+            'verify_type'=>['required',Rule::in([0,1])],
+            'account'=>'string|max:20',
+            'password'=>'string|min:6|max:18',
+            'shop_id'=>'integer|required',
+            'shop_account_id'=>'integer|required',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $shop = Shop::where('shop_name', '=', $data['shop_name'])->where('shop_id', '<>', $data['shop_id'])->first();
+        if($shop){
+            return $this->response->error('该商户已存在,请重新输入', 500);
+        }
+        $shop_account = ShopAccount::where('account',$data['account'])->where('id', '<>', $data['shop_account_id'])->first();
+        if($shop_account){
+            return $this->response->error('该账号已存在,请重新输入11', 500);
+        }
+        $shopRepository = new ShopRepository();
+        $res = $shopRepository->editShopAccount($data);
+        if($res){
+            return  ['message'  => '成功','status_code'   => 200];
+        }else{
+            return $this->response->error("失败", 500);
         }
     }
     //详情
     public function view(Request $request)
     {
-        $data = $request->all();
+        $data = $request->only('shop_id');
         $validator = Validator::make($data, [
             'shop_id' => 'required|integer',
         ]);
         if ($validator->fails()) {
-            return $this->jsonError($validator->errors()->first());
+            return $this->response->error($validator->errors()->first(), 500);
         }
         $shop = Shop::where(['shop_id'=>$data['shop_id']])->first();
         $fractal = new Manager();
         $res = new Item($shop,new ShopsTransformer());
-        $data = $fractal->createData($res)->toArray();
-        if($data){
-            return  $this->jsonSuccess($data);
-        }else{
-            return $this->jsonError("操作失败");
-        }
+        return $fractal->createData($res)->toArray();
     }
     //列表
     public function list(Request $request){
@@ -100,7 +146,7 @@ class ShopController extends Controller {
         $resource->setPaginator(new IlluminatePaginatorAdapter($shops));
         $data = $fractal->createData($resource)->toArray();
         $data['extra']['filters'] = ['shop_name','status'];
-        $data['extra']['columns'] = ['shop_id','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;
     }
     /**
@@ -120,4 +166,6 @@ class ShopController extends Controller {
             return $this->jsonError('操作失败');
         }
     }
+
+
 }

+ 29 - 6
app/Repositories/ShopRepository.php

@@ -42,7 +42,7 @@ class ShopRepository {
         unset($data['shop_account_id']);
         $shopData = $data;
         try{
-            $shop = Shop::updateOrCreate(['shop_id'=>$shop_id],$shopData);
+            $shop = Shop::create($shopData);
             $accountData = [];
             if($shop){
                 $accountData['shop_id'] = $shop->shop_id;
@@ -50,7 +50,7 @@ class ShopRepository {
             if(isset($data['account']) && isset($data['password'])){
                 $accountData['account'] = $data['account'];
                 $accountData['password'] = Hash::make($data['password']);
-                ShopAccount::updateOrCreate(['shop_id'=>$shop->shop_id],$accountData);
+                ShopAccount::create($accountData);
             }
             return true;
         }catch (Exception $exception){
@@ -58,19 +58,42 @@ class ShopRepository {
         }
     }
 
+
+    //修改
+    public function editShopAccount($data = []){
+        $shop_id = $data['shop_id'];
+        $shop_account_id = $data['shop_account_id'];
+        $account = $data['account'];
+        $password = $data['password'];
+        unset($data['password']);
+        unset($data['shop_id']);
+        unset($data['shop_account_id']);
+        unset($data['account']);
+        try{
+            $shop = Shop::where(['shop_id'=>$shop_id])->update($data);
+            $accountData = [];
+            if(isset($account) && isset($password)){
+                $accountData['shop_id'] = $shop_id;
+                $accountData['account'] = $account;
+                $accountData['password'] = Hash::make($password);
+                ShopAccount::where(['id'=>$shop_account_id])->update($accountData);
+            }
+            return true;
+        }catch (Exception $exception){
+            return false;
+        }
+    }
     public function shopList($request)
     {
 
         $where = [];
         if (isset($request['status'])) {
-            $where[] = ['status', '=', $request['uid']];
+            $where[] = ['status', '=', $request['status']];
         }
         if (isset($request['shop_name'])) {
-            $where[] = ['shop_name', 'like', '%'.$request['username'].'%'];
+            $where[] = ['shop_name', 'like', '%'.$request['shop_name'].'%'];
         }
-
        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
-//        $where = $this->memberWhereList($request);
         return Shop::where($where)
             ->orderBy('shop_id', 'desc')
             ->paginate($perPage);

+ 1 - 1
database/migrations/2019_04_28_172009_create_shops_table.php

@@ -26,7 +26,7 @@ class CreateShopsTable extends Migration
             $table->string('contact_mobile',16)->nullable()->default('')->comment('联系人电话');
             $table->string('contact_name')->nullable()->default('')->comment('联系人名称');
             $table->string('shop_desc')->nullable()->default('')->comment('商家介绍');
-            $table->tinyInteger('status')->default(1)->comment('状态 0启用 1禁用');
+            $table->tinyInteger('status')->default(1)->comment('状态 1启用 0禁用');
             $table->string('logo_img')->nullable()->default('')->comment('商家logo');
             $table->string('license_img')->comment('营业执照');
             $table->string('food_trans_license')->comment('食品流通许可证');

+ 1 - 1
database/migrations/2019_04_28_172025_create_shop_accounts_table.php

@@ -19,7 +19,7 @@ class CreateShopAccountsTable extends Migration
             $table->string('account')->nullable()->comment('账号');
             $table->string('mobile',16)->nullable()->comment('手机号码');
             $table->string('password')->nullable()->comment('密码');
-            $table->integer('status')->default(0)->comment('状态 0启用 1禁用');
+            $table->integer('status')->default(1)->comment('状态 1启用 0禁用');
             $table->string('ip')->default('')->comment('登陆ip');
             $table->softDeletes();
             $table->timestamps();

+ 8 - 0
routes/api.php

@@ -41,7 +41,15 @@ $api->version('v1', [
     });
 
     $api->group(['middleware' => 'jwt.chxq_auth'], function ($api) {
+        //新增编辑
+        $api->post('addShop', 'ShopController@addShop');
+        //编辑
+        $api->post('editShop', 'ShopController@editShop');
+        //商户列表
+        $api->get('shopList', 'ShopController@list');
         //用户列表
+        //商户详情
+        $api->post('shopView', 'ShopController@view');
 
         $api->get('user', 'UserController@index');
         //用户列表