فهرست منبع

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

Mike 7 سال پیش
والد
کامیت
12e9fdd8f3

+ 15 - 7
server/app/Http/Controllers/Api/V1/AuthController.php

xqd xqd
@@ -15,7 +15,7 @@ class AuthController extends Controller
 {
     use SmsHelper,AuthenticatesUsers,AttachmentHelper,JpushHelper;
 
-    private $expireTime     = 1;
+    private $expireTime     = 5;
     private $keySmsCode     = 'auth:sms:';
     private $keySmsCodeExist     = 'auth:sms:exist';
     private $expireTimeExist     = 24*60;
@@ -298,14 +298,22 @@ class AuthController extends Controller
         \Log::info('verify_code:'.$verify_code);
         $key = $this->keySmsCode . $phone;
         Cache::store('file')->put($key, $verify_code, $this->expireTime);
-        $msg = '【喵喵】您的验证码是:' . $verify_code;
-        /*
+        $msg = '【喵喵】您的验证码是:' . $verify_code.')。5分钟内有效请及时验证';
+
          $result = $this->sendSms($msg, $phone);
-        if (!$result)
-             $this->logger->Error("Send sms failed.");
-        */
+        /*if (!$result)
+             $this->logger->Error("Send sms failed.");*/
+        if ($result!='success') {
+            \Log::error("Send sms failed.");
+        }
 
-        return $this->api(['verify_code' => $verify_code]);
+        if(env("APP_DEBUG")){
+            return $this->api(['verify_code' => $verify_code]);
+        }else{
+            //product
+            return $this->error(1);
+        }
+//        return $this->api(['verify_code' => $verify_code]);
     }
 
 

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

xqd
@@ -20,8 +20,8 @@ class Controller extends BaseController
 
     public function getUser()
     {
-//        $this->user = UserInfoModel::where('phone','13880642880')->first();
         $this->user = Auth::guard('api')->user();
+//        $this->user = UserInfoModel::where('phone','13880642880')->first();
         return $this->user;
     }
 

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

xqd xqd
@@ -28,6 +28,7 @@ class DreamController extends Controller
      * @apiVersion 0.1.0
      * @apiParam {int} [type=home] home interaction paihang  默认all
      * @apiParam {int} id 梦想ID
+     * @apiParam {int} [interaction_id] 动态id
      * @apiParam  [dream_user_id] id 梦想者id
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -264,11 +265,26 @@ class DreamController extends Controller
         $show_button = $dream->user_id == $user->id ? '0' : '1';
         $dream->show_button = $show_button;
 //        梦想互动
+        $interaction_id = $request->input('interaction_id');
+
         $interactions = InteractionInfo::where('dream_id',$id)->with(['comments' => function ($query) {
             $query->orderBy('created_at');
         }])->orderBy('created_at','desc')->get();
+        if (!empty($interaction_id)) {
+            $data = InteractionInfo::with(['comments' => function ($query) {
+                $query->orderBy('created_at');
+            }])->find($interaction_id);
+            if (count($data) > 0) {
+                $interactions = $interactions->toArray();
+                foreach ($interactions as $key => $value) {
+                    if ($value['id']==$interaction_id) {
+                        unset($interactions[$key]);
+                    }
+                }
+                array_unshift($interactions,$data);
+            }
+        }
         $dream->interactions = $interactions;
-//        dd($interactions);
         return $this->api($dream);
     }
 

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

xqd xqd xqd
@@ -133,16 +133,18 @@ class IndexController extends Controller
         }*/
         $type = $request->type;
         if ($type == 'trend') {
-            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
+            $banners = $this->getBanner();
+            $dreams = DreamInfoModel::where('end_time','>',date('Y-m-d H:i:s'))->orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
             $this->dreams($dreams);
-            return $this->api(compact('users','dreams'));
+            return $this->api(compact('banners','users','dreams'));
         } elseif ($type == 'news') {
-            $dreams = DreamInfoModel::orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
+            $banners = $this->getBanner();
+            $dreams = DreamInfoModel::where('end_time','>',date('Y-m-d H:i:s'))->orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
             $this->dreams($dreams);
-            return $this->api(compact('users','dreams'));
+            return $this->api(compact('banners','users','dreams'));
         } else{
             $banners = $this->getBanner();
-            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->limit(15)->paginate(15);
+            $dreams = DreamInfoModel::where('end_time','>',date('Y-m-d H:i:s'))->orderBy('score','desc')->with('user')->limit(15)->paginate(15);
             $this->dreams($dreams);
             return $this->api(compact('banners','users','dreams'));
         }
@@ -447,9 +449,9 @@ class IndexController extends Controller
             });
         }
         \Log::info($query->toSql());
-        $arr1 =DreamInfoModel::limit(20)->select('id')->get()->toArray();
+        $arr1 =DreamInfoModel::orderBy('id')->limit(20)->select('id')->get()->toArray();
         $id_arr1 = array_column($arr1,'id');
-        $arr2 =DreamInfoModel::orderBy('score','desc')->limit(120)->select('id')->get()->toArray();
+        $arr2 =DreamInfoModel::orderBy('id','desc')->limit(120)->select('id')->get()->toArray();
         $id_arr2 = array_column($arr2,'id');
         $dtusers =UserCareUser::where('user_id',$id)->with('other_user')->
         where('dream_number','>',0)->orderBy('created_at')->get()->toArray();
@@ -465,16 +467,16 @@ class IndexController extends Controller
         }
         $type = $request->type;
         if ($type == 'trend') {
-            $dreams = $query->orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
+            $dreams = $query->where('end_time','<',date('Y-m-d H:i:s'))->orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
             $this->dreams($dreams);
             return $this->api(compact('users','dreams'));
         } elseif ($type == 'news') {
-            $dreams = $query->orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
+            $dreams = $query->where('end_time','<',date('Y-m-d H:i:s'))->orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
             $this->dreams($dreams);
             return $this->api(compact('users','dreams'));
         } else{
             $banners = $this->getBanner();
-            $dreams = $query->orderBy('score','desc')->with('user')->limit(20)->paginate(20);
+            $dreams = $query->where('end_time','<',date('Y-m-d H:i:s'))->orderBy('score','desc')->with('user')->limit(20)->paginate(20);
             $this->dreams($dreams);
             return $this->api(compact('banners','users','dreams'));
         }

+ 70 - 3
server/app/Http/Controllers/Api/V1/InteractionController.php

xqd xqd xqd xqd xqd xqd
@@ -6,6 +6,7 @@ use App\Models\CommentInfoModel;
 use App\Models\DreamInfoModel;
 use App\Models\InteractionInfo;
 use App\Models\ReplyCommentsInfo;
+use App\Models\SupportDreamModel;
 use App\Models\SystemInfoModel;
 use App\Models\UserCareDream;
 use App\Models\UserCareUser;
@@ -27,7 +28,7 @@ class InteractionController extends Controller
      * @apiParam {int} id                 梦想ID
      * @apiParam {string} title           互动标题
      * @apiParam {string} [video]           视频
-     * @apiParam {array} pics[]           图片数组
+     * @apiParam {array} [pics[]]           图片数组
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
      *{
@@ -48,6 +49,7 @@ class InteractionController extends Controller
      */
     public function store(Request $request)
     {
+        $user = $this->getUser();
         $validator = \Validator::make($request->all(),
             [
                 'id'  => 'required',
@@ -76,6 +78,21 @@ class InteractionController extends Controller
         $data['video'] = $request->video;
         $ok = InteractionInfo::create($data);
         if ($ok) {
+            //        新的互动应该有消息通知《支持者》
+            $support_user = SupportDreamModel::where('dream_id',$dream_id)->get();
+            if (!empty(count($support_user))) {
+                $user_ids = array_column($support_user->toArray(),'user_id');
+                foreach ($user_ids as $user_id) {
+                    $arr['user_id']=$user->id;
+                    $arr['to_user_id']=$user_id;
+                    $arr['message']='您支持的梦想又有新的动态啦';
+                    $arr['interaction_id']=$ok->id;
+                    $arr['dream_id']=$dream_id;
+                    SystemInfoModel::create($arr);
+//            长连接
+                    $this->jPush($arr['message'],'',$user_id);
+                }
+            }
 //            收藏梦想最新动态加一
             UserCareDream::where('dream_id',$dream_id)->increment('interaction_number',1);
             $dream_user_id = DreamInfoModel::find($dream_id)->user_id;
@@ -149,8 +166,8 @@ class InteractionController extends Controller
                 $data['to_user_id'] = $request->input('comment_user_id');
                 $data['to_user_avatar'] = $to_user->avatar;
                 $data['to_user_nickname'] = $to_user->nickname;
-
-                $message = $user->nickname.'在你的互动上留言啦!点击去看看!';
+//点击去看看
+                $message = $user->nickname.'在你的互动上留言啦!';
                 $info = [
                     'user_id' => $data['to_user_id'],
                     'message' => $message,
@@ -298,4 +315,54 @@ class InteractionController extends Controller
             return $this->error(ErrorCode::OPERATION_FAILED);
         }
     }
+
+    /**
+     * @api {get} /api/interaction/destroy 删除动态
+     * @apiDescription 删除动态
+     * @apiGroup Interaction
+     * @apiParam {int} id       动态ID
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * {
+     *  "status": true,
+     *   "status_code": 0,
+     *   "message": "",
+     *   "data": ""
+     *}
+     * HTTP/1.1 200 OK
+     * @apiErrorExample {json} Error-Response:
+     * {
+     *   "status": false,
+     *   "status_code": 700,
+     *   "message": "操作失败",
+     *  "data": null
+     *}
+     * HTTP/1.1 400 Bad Request
+     */
+    public function destroy(Request $request)
+    {
+        $validator = \Validator::make($request->all(),
+            [
+                'id'  => 'required',
+            ],
+            [
+                'id.required'  => '动态ID不存在',
+            ]
+        );
+
+        if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
+
+//        $user = $this->getUser();
+
+        $id = $request->input('id');
+        CommentInfoModel::where('interaction_id',$id)->delete();
+        $ok =  InteractionInfo::destroy($id);
+
+        if ($ok) {
+            return $this->api('');
+        }else{
+            return $this->error(ErrorCode::OPERATION_FAILED);
+        }
+    }
 }

+ 53 - 1
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd
@@ -255,12 +255,13 @@ class MyController extends Controller
     public function reply()
     {
         $user = $this->getUser();
+//        $user = UserInfoModel::find(4);
         $data = CommentInfoModel::where('to_user_id',$user->id)->orderBy('id','desc')->get(); //user_id
         foreach ($data as $item){   //访问接口  标记已读
             $item->update(['is_read'=>0]);
             $info = InteractionInfo::find($item->interaction_id);
             $dream_id =empty($info) ? 0 : $info->dream_id;
-            $item->dream_id = $dream_id;
+            $item->dreamid = $dream_id;
         }
         return $this->api($data);
     }
@@ -860,6 +861,57 @@ class MyController extends Controller
         $users =$user->UserCareUser;
         return $this->api($users);
 
+    }
+    /**
+     * @api {get} /api/my/careme 关注我的用户
+     * @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":[] or
+     *   "data": [
+     *      {
+     *           "id": 2,
+     *           "phone": "13880642881",
+     *          "nickname": "name2",
+     *          "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
+     *          "birthday": "2000-06-21",
+     *          "sign": 0,
+     *          "money": 0,
+     *          "coin": 800,
+     *          "sex": 1,
+     *          "signture": "我的个性签名2",
+     *          "height": 200,
+     *          "work": "兼职",
+     *          "emotion": 2,
+     *          "address": "370105",
+     *          "city": "成都",
+     *          "detail_address": "",
+     *          "status": 1,
+     *          "wechat": "",
+     *          "weibo": "",
+     *          "remember_token": "",
+     *          "created_at": "2017-06-25 10:42:06",
+     *          "updated_at": "2017-06-30 09:15:04",
+     *          "deleted_at": null,
+     *      }
+     *  ]
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function careMe()
+    {
+        $user = $this->getUser();
+        $users =$user->UserCareMe;
+        return $this->api($users);
+
     }
 
     public function insertSearchTable($id,$keyword)

+ 2 - 0
server/app/Models/SystemInfoModel.php

xqd
@@ -35,6 +35,8 @@ class SystemInfoModel extends BaseModel
                            'message',
                            'to_user_id',
                            'is_read',
+                           'interaction_id',
+                           'dream_id',
                           ];
 
     public function user()

+ 6 - 0
server/app/Models/UserInfoModel.php

xqd
@@ -63,6 +63,12 @@ class UserInfoModel extends Authenticatable
     {
         return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id');
     }
+
+    public function UserCareMe()
+    {
+        return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','other_user_id','user_id');
+    }
+
     public function UserCareDream()
     {
         return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->with(['user'])->withPivot('interaction_number','dream_user_id')->orderBy('updated_at');

+ 33 - 0
server/database/migrations/2017_10_25_102420_add_dream_id_and_interaction_id_to_system_info_table.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddDreamIdAndInteractionIdToSystemInfoTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            $table->integer('dream_id')->nullable()->after('is_read');
+            $table->integer('interaction_id')->nullable()->after('is_read');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 8 - 0
server/routes/api.php

xqd xqd
@@ -154,6 +154,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'my.care',
         'uses' => 'MyController@care',
     ]);
+    $api->get('my/careme', [
+        'as' => 'my.careme',
+        'uses' => 'MyController@careMe',
+    ]);
 //    我的收藏
     $api->get('my/collection', [
         'as' => 'my.collection',
@@ -268,6 +272,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'interaction.delete',
         'uses' => 'InteractionController@delete',
     ]);
+    $api->get('/interaction/destroy', [  //删除动态
+        'as' => 'interaction.destroy',
+        'uses' => 'InteractionController@destroy',
+    ]);
 
     //支付宝支付回调
     $api->post('pay/alipay/notify', [