gq 7 年 前
コミット
1ef477b890

+ 6 - 7
server/app/Console/Commands/DreamDJS.php

xqd xqd
@@ -44,16 +44,15 @@ class DreamDJS extends Command
     public function handle()
     {
         //执行逻辑
-        $user = Auth::guard('api')->user();
-        $dream = $user->UserCareDream;
+        $dream = DreamInfoModel::orderBy('end_time','desc')->get();
         foreach ($dream as $item) {
             if (date('Y-m-d',$item->end_time) == date('Y-m-d',time()+1*24*3600)) {
                 $message = $item->name.'过1天就要结束啦!';
-                $this->jPush($message,'',$user->id);
+                $this->jPush($message,'',$item->user_id);
             }
             if ( date('Y-m-d',time()+7*24*3600)== date('Y-m-d',$item->end_time)) {
                 $message = $item->name.'过1周就要结束啦!';
-                $this->jPush($message,'',$user->id);
+                $this->jPush($message,'',$item->user_id);
             }
             if ( $item->end_time < date('Y-n-d H:i:s')) {
                 $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
@@ -67,15 +66,15 @@ class DreamDJS extends Command
                 }
                 arsort($top);
                 $new_arr = array_values($top);
-                $key = array_search($top[$user->id],$new_arr);
+                $key = array_search($top[$item->user_id],$new_arr);
                 $message = $item->name."已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
-                $this->jPush($message,'',$user->id);
+                $this->jPush($message,'',$item->user_id);
             }
            if( isset($message)){
                $arr = [
                     'user_id'=>0,
                     'message'=>$message,
-                    'to_user_id'=>$user->id,
+                    'to_user_id'=>$item->user_id,
                     'dream_id'=>$item->id,
             ];
                SystemInfoModel::create($arr);

+ 8 - 0
server/app/Http/Controllers/Admin/Dream/InfoController.php

xqd
@@ -141,6 +141,14 @@ class InfoController extends Controller
      */
     private function _updateSave() {
         $data = (array) request('data');
+        if ($data['status']==2) { //审核不过
+            $info = [
+                'user_id' => $data['user_id'],
+                'message' => ' 你的梦想被暂停,客服会在短时间内联络你',
+                'type_id' => 1,
+            ];
+            SystemInfoModel::create($info);
+        }
         if (array_key_exists('sign',$data)) {
             $data['sign'] = join(',',$data['sign']);
         }

+ 5 - 6
server/app/Http/Controllers/Api/V1/DreamController.php

xqd xqd
@@ -462,10 +462,12 @@ class DreamController extends Controller
                 'op' =>  AccountLog::OP_SUPPORT,
             ];
             AccountLog::create($data);
-            $message = UserInfoModel::find($user->id)->nickname.'为你的梦想捐赠'.$coin.'梦想币';
+            $message = UserInfoModel::find($user->id)->nickname.'为你的梦想支持了'.$coin.'梦想币';
             $info = [
                 'user_id' => $user_id,
                 'message' => $message,
+                'is_reply' => 1,
+                'type_id' => 1,
             ];
             SystemInfoModel::create($info);
 
@@ -576,14 +578,11 @@ class DreamController extends Controller
 //                关注成功发送私信
             $message = BaseSettingsModel::where('category','message')->first();
             $message = empty($message) ? $user->nickname.'收藏了你的梦想' : $message->value;
-            /*$info2 = [
-                'user_id'=>$request->id,
-                'to_user_id' => $dream->user_id,
-                'message' =>$message
-            ];*/
             $info2 = [
                 'user_id' => $dream->user_id,
                 'message' => $message,
+                'is_reply' => 1,
+                'type_id' => 1,
             ];
             SystemInfoModel::create($info2);
             //            长连接

+ 78 - 0
server/app/Http/Controllers/Api/V1/IndexController.php

xqd xqd xqd
@@ -6,6 +6,8 @@ use App\Models\BaseSettingsModel;
 use App\Models\CommentInfoModel;
 use App\Models\DreamInfoModel;
 use App\Models\SearchInfoModel;
+use App\Models\SupportDreamModel;
+use App\Models\SystemInfoModel;
 use App\Models\UserCareDream;
 use App\Models\UserCareUser;
 use App\Models\UserInfoModel;
@@ -108,6 +110,9 @@ class IndexController extends Controller
     {
         $login_user = $this->getUser();
         $id = $login_user->id;
+//        访问首页时 当用户的梦想结束时通知用户
+        $this->systemInfo($id);
+
         $arr1 =DreamInfoModel::orderBy('score','desc')->limit(30)->select('id')->get()->toArray();
         $id_arr1 = array_column($arr1,'id');
         $arr2 =DreamInfoModel::orderBy('score','desc')->offset(15)->limit(120)->select('id')->get()->toArray();
@@ -143,6 +148,79 @@ class IndexController extends Controller
 
     }
 
+    public function systemInfo($id)
+    {
+        $end_dream_info = DreamInfoModel::where('user_id',$id)->where('end_time','>',date('Y-m-d H:i:s'))->get();
+        if (count($end_dream_info)>0) {
+            foreach ($end_dream_info as $item){
+                $message = "你的梦想《$item->title》已结束,点击了解接下来的步骤";
+                $arr[] = [
+                    'user_id'=>0,
+                    'message'=>$message,
+                    'to_user_id'=>$id,
+                    'dream_id'=>$item->id,
+                    'is_end'=>1,
+                    'type_id'=>1,
+                ];
+//                给支持者发送消息
+                $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
+                $top = [] ;
+                foreach ($support_dream as $item2) {
+                    if (!array_key_exists($item2->user_id,$top)) {
+                        $top[$item2->user_id] = $item2->score;
+                    }else{
+                        $top[$item2->user_id] += $item2->score;
+                    }
+                }
+                arsort($top);
+                $new_arr = array_values($top);
+                foreach ($top as $k => $v) {
+                    $key = array_search($v,$new_arr);
+                    $message = $item->name."已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
+                    if (empty($key)) { //最大支持者
+                        $arr[] = [
+                            'user_id'=>0,
+                            'message'=>$message,
+                            'to_user_id'=>$k,
+                            'dream_id'=>$item->id,
+                            'is_end'=>1,
+                            'type_id'=>2,
+                            'is_max'=>1,
+                        ];
+                    }else{
+                        $arr[] = [
+                            'user_id'=>0,
+                            'message'=>$message,
+                            'to_user_id'=>$k,
+                            'dream_id'=>$item->id,
+                            'is_end'=>1,
+                            'type_id'=>2,
+                        ];
+                    }
+
+                }
+                SystemInfoModel::insert($arr);
+            }
+//            2   我关注的梦想倒计时 通知消息
+            $dreams = UserCareDream::where('user_id',$id)->with('dreams')->get();
+            foreach ($dreams as $item) {
+                if (date('Y-m-d',$item->dreams->end_time) == date('Y-m-d',time()+1*24*3600)) {
+                    $message = $item->name.'过1天就要结束啦!';
+                    $arr = [
+                        'user_id'=>0,
+                        'message'=>$message,
+                        'to_user_id'=>$id,
+                        'dream_id'=>$item->dream_id,
+                        'is_url'=>1,
+                        'type_id'=>2,
+                    ];
+                    SystemInfoModel::create($arr);
+                }
+
+            }
+        }
+    }
+
     /**
      * @api {get}  /api/index/search 搜索
      * @apiDescription 搜索

+ 2 - 0
server/app/Http/Controllers/Api/V1/InteractionController.php

xqd
@@ -172,6 +172,8 @@ class InteractionController extends Controller
                 $info = [
                     'user_id' => $data['to_user_id'],
                     'message' => $message,
+                    'is_url' => 1,
+                    'type_id' => 1,
                 ];
                 SystemInfoModel::create($info);
 

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

xqd
@@ -39,6 +39,9 @@ class SystemInfoModel extends BaseModel
                            'dream_id',
                            'type_id',
                            'is_url',
+                           'is_reply',
+                           'is_max',
+                           'is_ok',
                           ];
 
     public function user()

+ 1 - 1
server/app/Models/UserCareDream.php

xqd
@@ -15,6 +15,6 @@ class UserCareDream extends Model
 
     public function dreams()
     {
-        return $this->hasMany('App\Models\DreamInfoModel','id','dream_id');
+        return $this->hasOne('App\Models\DreamInfoModel','id','dream_id');
     }
 }

+ 32 - 0
server/database/migrations/2017_10_30_165649_add_is_reply_to_system_info_table.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddIsReplyToSystemInfoTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            $table->smallInteger('is_reply')->default(0)->comment('0不可回复1可回复')->after('dream_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 34 - 0
server/database/migrations/2017_10_30_172609_add_is_end_to_system_info_table.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddIsEndToSystemInfoTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            $table->smallInteger('is_end')->default(0)->comment('1梦想结束消息')->after('dream_id');
+            $table->smallInteger('is_ok')->default(0)->comment('1支持者点击OK')->after('dream_id');
+            $table->smallInteger('is_max')->default(0)->comment('1最大支持者')->after('dream_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            //
+        });
+    }
+}