zhangchangchun 6 年之前
父节点
当前提交
197345fa3f
共有 3 个文件被更改,包括 47 次插入8 次删除
  1. 40 0
      app/Http/Controllers/V1/ShopController.php
  2. 4 0
      app/Repositories/ShopRepository.php
  3. 3 8
      routes/api.php

+ 40 - 0
app/Http/Controllers/V1/ShopController.php

@@ -149,6 +149,24 @@ class ShopController extends Controller {
         $data['extra']['columns'] = ['shop_id','shop_name','mobile','province_name','city_name','product_count','proportion','status'];
         return $data;
     }
+    //删除商家
+    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);
+        }
+        $res = Shop::where(['shop_id'=>$data['shop_id']])->update(['status'=>$data['status']]);
+        if($res){
+            //下架商家所有商品,放入队列
+            return  ['message'  => '成功','status_code'   => 200];
+        }else{
+            return $this->response->error("失败", 500);
+        }
+    }
     /**
      * @param Request $request
      * @return mixed
@@ -167,5 +185,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);
+        }
+    }
 
 }

+ 4 - 0
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;
 
@@ -69,6 +70,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 +80,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;
         }
     }

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