dyjh vor 7 Jahren
Ursprung
Commit
827598f761

+ 22 - 19
app/Http/Controllers/Api/V1/IndexController.php

xqd xqd xqd xqd xqd
@@ -257,14 +257,10 @@ class IndexController extends Controller
      * @apiParam {int}  type  知识类型 1 悬赏 2 付费
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
-     * {
-     * "status": true,
-     * "status_code": 0,
-     * "message": "",
      * "data": {
-     *      "msg": "获取成功"
+     *      "code": 1
+     *      "msg": "添加成功"
      *    }
-     *}
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
      * {
@@ -293,14 +289,16 @@ class IndexController extends Controller
         $type = $request->input('type');
         $message = MessagesInfoModel::where([['id',$id],['type',$type],['state',0]])->first();
         if(!$message){
-            $msg = '该信息不存在或者已完成';
-            return $this->api(compact('msg'));
+            $data['msg'] = '该信息不存在或者已完成';
+            $data['code'] = 0;
+            return $this->api($data);
         }
 
         $check_is_buy = MessagesFollowerModel::where([['user_id',$this->getUserId()],['messages_id',$message->id]])->first();
         if($check_is_buy){
-            $msg = '您已获取该知识,请勿重复操作';
-            return $this->api(compact('msg'));
+            $data['msg'] = '您已获取该知识,请勿重复操作';
+            $data['code'] = 0;
+            return $this->api($data);
         }
         $user = UserInfoModel::find($this->getUserId());
         if($type == 2) {
@@ -308,13 +306,15 @@ class IndexController extends Controller
             $out_trade_no = 'We'.date('YmdHis').rand(1000,9999);
             $user->money -= $message->price;
             if($user->money<0){
-                $msg = '您的余额已不足,请先充值';
-                return $this->api(compact('msg'));
+                $data['msg'] = '您的余额已不足,请先充值';
+                $data['code'] = 0;
+                return $this->api($data);
             }
             if(!$user->save()){
-                $msg = '购买失败';
+                $data['msg'] = '购买失败';
                 DB::rollback();
-                return $this->api(compact('msg'));
+                $data['code'] = 0;
+                return $this->api($data);
             }
             //dd(111);
             $save['openid'] = $user->openid;
@@ -325,9 +325,10 @@ class IndexController extends Controller
             $save['type'] = 2;
             $res = PaymentInfoModel::create($save);
             if(!$res) {
-                $msg = '购买失败';
+                $data['msg'] = '购买失败';
                 DB::rollback();
-                return $this->api(compact('msg'));
+                $data['code'] = 0;
+                return $this->api($data);
             }
 
         }
@@ -337,12 +338,14 @@ class IndexController extends Controller
         $followers['mobile'] = $user->mobile;
         $followers['state'] = $type == 1?0:1;
         if(MessagesFollowerModel::create($followers)){
-            $msg = '获取成功';
+            $data['msg'] = '获取成功';
+            $data['code'] = 1;
             DB::commit();
         } else {
-            $msg = '购买失败';
+            $data['msg'] = '购买失败';
+            $data['code'] = 0;
             DB::rollback();
         }
-        return $this->api(compact('msg'));
+        return $this->api($data);
     }
 }

+ 12 - 12
app/Http/Controllers/Api/V1/UserController.php

xqd xqd xqd
@@ -453,14 +453,10 @@ class UserController extends Controller
      * @apiParam {int}  type  操作类型 1 添加 0 删除
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
-     * {
-     * "status": true,
-     * "status_code": 0,
-     * "message": "",
      * "data": {
+     *      "code": 1
      *      "msg": "添加成功"
      *    }
-     *}
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
      * {
@@ -491,16 +487,18 @@ class UserController extends Controller
         $messages_followers = MessagesFollowerModel::find($followers_id);
         $messages = MessagesInfoModel::where([['id'=>$messages_followers->messages_id],['type',1],['state',0]])->first();
         if(!$messages||$message_id!=$messages->id){
-            $msg = '该知识不存在,或者已完成';
-            return $this->api(compact('msg'));
+            $data['msg'] = '该知识不存在,或者已完成';
+            $data['code'] = 0;
+            return $this->api($data);
         }
         $user = UserInfoModel::find($messages_followers->user_id);
         $out_trade_no = 'We'.date('YmdHis').rand(1000,9999);
         $user->money += $messages->price;
 
         if(!$user->save()){
-            $msg = '确认失败';
-            return $this->api(compact('msg'));
+            $data['msg'] = '确认失败';
+            $data['code'] = 0;
+            return $this->api($data);
         }
         $save['openid'] = $user->openid;
         $save['out_trade_no'] = $out_trade_no;
@@ -511,14 +509,16 @@ class UserController extends Controller
         $save['type'] = 3;
         $res = PaymentInfoModel::create($save);
         if(!$res) {
-            $msg = '确认失败';
+            $data['msg'] = '确认失败';
+            $data['code'] = 1;
         } else {
-            $msg = '确认成功';
+            $data['msg'] = '确认成功';
+            $data['code'] = 0;
         }
         $messages->state = 1;
         $messages->save();
         $messages_followers->state = 1;
         $messages_followers->save();
-        return $this->api(compact('msg'));
+        return $this->api($data);
     }
 }

+ 2 - 2
public/apidoc/api_data.js

xqd xqd
@@ -244,7 +244,7 @@ define({ "api": [
       "examples": [
         {
           "title": "Success-Response:",
-          "content": "HTTP/1.1 200 OK\n{\n\"status\": true,\n\"status_code\": 0,\n\"message\": \"\",\n\"data\": {\n     \"msg\": \"获取成功\"\n   }\n}",
+          "content": "HTTP/1.1 200 OK\n\"data\": {\n     \"code\": 1\n     \"msg\": \"添加成功\"\n   }",
           "type": "json"
         }
       ]
@@ -446,7 +446,7 @@ define({ "api": [
       "examples": [
         {
           "title": "Success-Response:",
-          "content": "HTTP/1.1 200 OK\n{\n\"status\": true,\n\"status_code\": 0,\n\"message\": \"\",\n\"data\": {\n     \"msg\": \"添加成功\"\n   }\n}",
+          "content": "HTTP/1.1 200 OK\n\"data\": {\n     \"code\": 1\n     \"msg\": \"添加成功\"\n   }",
           "type": "json"
         }
       ]

+ 2 - 2
public/apidoc/api_data.json

xqd xqd
@@ -244,7 +244,7 @@
       "examples": [
         {
           "title": "Success-Response:",
-          "content": "HTTP/1.1 200 OK\n{\n\"status\": true,\n\"status_code\": 0,\n\"message\": \"\",\n\"data\": {\n     \"msg\": \"获取成功\"\n   }\n}",
+          "content": "HTTP/1.1 200 OK\n\"data\": {\n     \"code\": 1\n     \"msg\": \"添加成功\"\n   }",
           "type": "json"
         }
       ]
@@ -446,7 +446,7 @@
       "examples": [
         {
           "title": "Success-Response:",
-          "content": "HTTP/1.1 200 OK\n{\n\"status\": true,\n\"status_code\": 0,\n\"message\": \"\",\n\"data\": {\n     \"msg\": \"添加成功\"\n   }\n}",
+          "content": "HTTP/1.1 200 OK\n\"data\": {\n     \"code\": 1\n     \"msg\": \"添加成功\"\n   }",
           "type": "json"
         }
       ]

+ 1 - 1
public/apidoc/api_project.js

xqd
@@ -9,7 +9,7 @@ define({
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2018-07-20T02:14:23.626Z",
+    "time": "2018-07-20T02:31:16.691Z",
     "url": "http://apidocjs.com",
     "version": "0.17.6"
   }

+ 1 - 1
public/apidoc/api_project.json

xqd
@@ -9,7 +9,7 @@
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2018-07-20T02:14:23.626Z",
+    "time": "2018-07-20T02:31:16.691Z",
     "url": "http://apidocjs.com",
     "version": "0.17.6"
   }