/**
  * 更新请求
  *
  * @param Request $request
  * @param int $id
  * @return void
  */
 public function update(Request $request, $id)
 {
     // 验证
     $this->validate($request, ['topic' => 'string', 'participants' => 'string', 'state' => 'required|in:1,-1', 'reply_message' => 'required|string']);
     $log = Comment::find($id);
     // 更新
     DB::transaction(function () use($request, $log) {
         if (Comment::STATUS['ENABLE'] == $request->state) {
             // 参与人
             $participantIds = [];
             $participantNames = Participant::filterParticipantNames($request->participants);
             if (!empty($participantNames)) {
                 foreach ($participantNames as $name) {
                     $participant = Participant::firstOrCreate(['name' => $name]);
                     $participant->increment('counts', 1);
                     $participantIds[] = $participant->id;
                 }
             }
             // 节目
             $program = Program::where('date', date('Y-m-d', strtotime($log->metas->thread_key)))->first();
             $topic = Program::filterTopic($request->topic);
             if (!empty($topic)) {
                 $program->update(['topic' => $topic]);
             }
             if (!empty($participantIds)) {
                 $program->participants()->sync($participantIds);
             }
         }
         // 刷新首页文件缓存
         Cache::forget(Program::INDEX_CACHE_KEY);
         // 刷新贡献记录页文件缓存
         Cache::forget(Comment::CONTRIBUTION_CACHE_KEY);
         // 记录日志
         Comment::where('id', $log->id)->update(['ext_is_agree' => $request->state]);
     });
     // 回复评论
     $state = Comment::replyPost($request->reply_message, $log->metas->thread_id, $log->metas->post_id, $log->metas->author_email);
     // 跳转
     $status = ['status' => $state ? 'success' : 'error', 'message' => $state ? '审核成功~' : '审核成功,回复失败'];
     return Redirect::to($request->_redirect_url)->with($status['status'], $status['message']);
 }
Exemple #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // 获取文本路径
     $path = $this->argument('path');
     if (!is_file($path)) {
         return $this->error("Invalid file path {$path}.");
     }
     // 解析数据
     $list = self::decodeText($path);
     // 插入数据
     foreach ($list as $group) {
         DB::transaction(function () use(&$group) {
             // 插入声音记录
             self::insertAudios($group);
             // 插入参与人记录
             $data = $group['all'] ?? end($group);
             $participantIds = [];
             $participantNames = Participant::filterParticipantNames($data['participant']);
             foreach ($participantNames as $name) {
                 $participant = Participant::firstOrCreate(['name' => $name]);
                 $participant->increment('counts', 1);
                 $participantIds[] = $participant->id;
             }
             // 插入节目记录
             $topic = Program::filterTopic($data['topic']);
             if (empty($group['all'])) {
                 if (in_array(mb_substr($topic, -1), ['a', 'b', 'c'])) {
                     $topic = mb_substr($topic, 0, -1);
                 }
             }
             $program = Program::firstOrCreate(['date' => $data['date'], 'topic' => $topic, 'state' => Program::STATE_ENABLE]);
             if (!empty($participantIds)) {
                 $program->participants()->sync($participantIds);
             }
             // 输出日期
             $this->info(sprintf("%s\t%s", $data['date'], $topic));
         });
     }
 }