Browse Source

Merge branch 'gq' of http://git.9026.com/roobe/miao

Mike 8 năm trước cách đây
mục cha
commit
f9fb2495b1

+ 12 - 1
server/app/Http/Controllers/Api/V1/DreamController.php

xqd xqd
@@ -250,6 +250,12 @@ class DreamController extends Controller
      *       "message": "余额不足",
      *       "data": null
      *  }
+     *  {
+     *       "status": false,
+     *       "status_code": 1410,
+     *       "message": "支持已达上限",
+     *       "data": null
+     *  }
      *
      */
     public function support(Request $request)
@@ -270,7 +276,12 @@ class DreamController extends Controller
         $dream = DreamInfoModel::find($dream_id);
         $user_id = $dream->user_id;
         $coin = $request->coin;
-        $user_care_dream = UserCareDream::where('user_id',$user->id)->where('dream_id',$dream_id)->first();
+        if ($dream->get_coin == $dream->coin) {
+            return $this->error(ErrorCode::SUP_TOP);
+        } elseif($coin + $dream->get_coin > $dream->coin){
+            $coin = $coin + $dream->get_coin - $dream->coin ;
+        }
+        $user_care_dream = UserCareDream::where('user_id', $user->id)->where('dream_id', $dream_id)->first();
         $is_collection = empty($user_care_dream) ? 0 :1 ;
         $setting = BaseSettingsModel::where('category','score')->select('key','value')->first();
         $a = count($setting) > 0 ? $setting->key : '';

+ 10 - 5
server/app/Http/Controllers/Api/V1/IndexController.php

xqd xqd
@@ -90,16 +90,21 @@ class IndexController extends Controller
         $users = [];
         $type = $request->type;
         if ($type == 'trend') {
-            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->offset(20)->limit(100)->paginate(20);
+            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->offset(20)->limit(100)->paginate(15);
+//            dd($dreams);
+
             $this->dreams($dreams);
             return $this->api(compact('users','dreams'));
         } elseif ($type == 'news') {
-            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->offset(100)->limit(500)->paginate(20);
+            $dreams = DreamInfoModel::orderBy('score','desc')->orderBy('created_at','desc')->with('user')->limit(500)->offset(100)->paginate(15);
+//            dd($dreams);
+
             $this->dreams($dreams);
             return $this->api(compact('users','dreams'));
         } else{
             $banners = $this->getBanner();
-            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->limit(20)->paginate(20);
+            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->limit(20)->paginate(15);
+//            dd($dreams);
             $this->dreams($dreams);
             return $this->api(compact('banners','users','dreams'));
         }
@@ -147,11 +152,11 @@ class IndexController extends Controller
         $user_infos = UserInfoModel::where('nickname','like',$keyword)->get();
         $dream_infos =  DreamInfoModel::where(function ($query) use($keyword) {
             $query->where('name','like',$keyword)
-                ->where('end_time','<=',time());
+                ->where('end_time','>=',time());
         })
         ->orWhere(function ($query) use($keyword){
             $query->where('sign','like',$keyword)
-                ->where('end_time','<=',time());
+                ->where('end_time','>=',time());
         })->with(['user','img'])->get();
         $signs  = BaseSettingsModel::where('category','sign')->where('value','like',$keyword)->get();
         if (empty($request->keyword)) {

+ 56 - 68
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd xqd xqd
@@ -331,6 +331,7 @@ class MyController extends Controller
      * @apiDescription 我的收藏
      * @apiGroup My
      * @apiPermission Passport
+     * @apiParam {string}  keyword   关键字可选
      * @apiVersion 0.1.0
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -362,62 +363,7 @@ class MyController extends Controller
      *       }
      *   }
      *}
-     * @apiErrorExample {json} Error-Response:
-     * HTTP/1.1 400 Bad Request
-     */
-    public function collection()
-    {
-        $user = $this->getUser();
-        $dreams = $user->collection;
-        $users = [];
-        foreach ($dreams as $item) {
-            if ($item->pivot->interaction_number > 0) {
-                $user_info = UserInfoModel::find($item->pivot->dream_user_id);
-                $avatar = $user_info ?  $user_info->avatar : '';
-                if (!array_key_exists($item->pivot->dream_user_id,$users)) {
-                    $users[$item->pivot->dream_user_id] = $avatar;
-                }
-            }
-           $item->img;
-        }
-        return $this->api(compact('dreams','users'));
-    }
-
-    /**
-     * @api {get} /api/my/setting 设置
-     * @apiDescription 设置
-     * @apiGroup My
-     * @apiPermission Passport
-     * @apiVersion 0.1.0
-     * @apiSuccessExample {json} Success-Response:
-     * HTTP/1.1 200 OK
-     *{
-     *   "status": true,
-     *   "status_code": 0,
-     *   "message": "",
-     *   "data": {
-     *       "key": "2511789",                    电话
-     *       "value": "关于喵喵介绍"              关于喵喵
-     *   }
-     *}
-     * @apiErrorExample {json} Error-Response:
-     * HTTP/1.1 400 Bad Request
-     */
-    public function setting()
-    {
-        $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
-        return $this->api($data);
-    }
-
-    /**
-     * @api {get}  /api/my/search_collection 梦想搜索
-     * @apiDescription 梦想搜索
-     * @apiGroup My
-     * @apiPermission none
-     * @apiVersion 0.1.0
-     * @apiParam {string}  keyword   关键字
-     * @apiSuccessExample {json} Success-Response:
-     * HTTP/1.1 200 OK
+     *          keyword存在
     {
         "status": true,
         "status_code": 0,
@@ -447,7 +393,7 @@ class MyController extends Controller
                         "sign": "梦想达人",
                         "created_at": "2017-06-25 13:10:56",
                         "updated_at": "2017-06-28 16:53:39"
-                        "img": {
+                        "img": {                                图片
                             "title": "",
                             "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
                         }
@@ -459,20 +405,62 @@ class MyController extends Controller
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
      */
-    public function searchCollection(Request $request)
+    public function collection(Request $request)
     {
         $user = $this->getUser();
-        $keyword ='%'.$request->keyword.'%';
-        $data = UserCareDream::where('user_id',$user->id)->
-        whereHas('dreams',function ($query) use($keyword){
-            $query->where('end_time','<=',time())->where('name','like',$keyword);
-        })->with('dreams')->get();
-       foreach ($data as $item) {
-           foreach ($item->dreams as $dream) {
-               $dream->img;
-           }
+        if ($request->keyword) {
+            $keyword ='%'.$request->keyword.'%';
+            $data = UserCareDream::where('user_id',$user->id)->
+            whereHas('dreams',function ($query) use($keyword){
+                $query->where('end_time','>=',time())->where('name','like',$keyword);
+            })->with('dreams')->get();
+            foreach ($data as $item) {
+                foreach ($item->dreams as $dream) {
+                    $dream->img;
+                }
+            }
+            $this->insertSearchTable($user->id,$request->keyword);
+            return $this->api($data);
+        }else{
+            $dreams = $user->collection;
+            $users = [];
+            foreach ($dreams as $item) {
+                if ($item->pivot->interaction_number > 0) {
+                    $user_info = UserInfoModel::find($item->pivot->dream_user_id);
+                    $avatar = $user_info ?  $user_info->avatar : '';
+                    if (!array_key_exists($item->pivot->dream_user_id,$users)) {
+                        $users[$item->pivot->dream_user_id] = $avatar;
+                    }
+                }
+                $item->img;
+            }
+            return $this->api(compact('dreams','users'));
         }
-        $this->insertSearchTable($user->id,$request->keyword);
+    }
+
+    /**
+     * @api {get} /api/my/setting 设置
+     * @apiDescription 设置
+     * @apiGroup My
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *   "status": true,
+     *   "status_code": 0,
+     *   "message": "",
+     *   "data": {
+     *       "key": "2511789",                    电话
+     *       "value": "关于喵喵介绍"              关于喵喵
+     *   }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function setting()
+    {
+        $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
         return $this->api($data);
     }
 

+ 2 - 0
server/app/Services/Base/ErrorCode.php

xqd
@@ -68,10 +68,12 @@ final class ErrorCode {
     const LOCK_USER = 1309;
 //    const MERCHANT_BALANCE_NOT_ENOUGH = 1311;
     const KEY_ERROR = 1310;
+    const SUP_TOP = 1410;
 
     //错误常量枚举
     private static $_msg = [
         self::DREAM_NOT_EXIST => '梦想不存在',
+        self::SUP_TOP => '支持已达上限',
         self::ATTACHMENT_DELETE_FAILED => '删除附件文件失败',
         self::ATTACHMENT_MOVE_FAILED => '移动附件失败',
         self::ATTACHMENT_RECORD_DELETE_FAILED => '删除附件记录失败',

+ 0 - 4
server/routes/api.php

xqd
@@ -141,10 +141,6 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'my.collection',
         'uses' => 'MyController@collection',
     ]);
-    $api->get('my/search_collection', [
-        'as' => 'my.search_collection',
-        'uses' => 'MyController@searchCollection',
-    ]);
     $api->get('my/setting', [
         'as' => 'my.setting',
         'uses' => 'MyController@setting',