Explorar o código

新增编辑商家信息

zhangchangchun %!s(int64=6) %!d(string=hai) anos
pai
achega
6a5ed1276b

+ 56 - 6
app/Http/Controllers/V1/ShopController.php

@@ -54,16 +54,19 @@ class ShopController extends Controller {
             'verify_type'=>['required',Rule::in([0,1])],
             'account'=>'string|max:20',
             'password'=>'string|min:6|max:18',
-            'shop_id'=>'integer',
+//            'shop_id'=>'integer',
+//            'shop_account_id'=>'integer',
         ]);
         if ($validator->fails()) {
             return $this->response->error($validator->errors()->first(), 500);
         }
-        if($data['account'] && empty($data['shop_id'])){
-            $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);
@@ -73,6 +76,53 @@ class ShopController extends Controller {
             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|max:6',
+            'city_name' => 'required|string:max:50',
+            'city_id' => 'required|integer|max:6',
+            '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)
     {

+ 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);

+ 2 - 0
routes/api.php

@@ -38,6 +38,8 @@ $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');
         //用户列表