Esempio n. 1
0
File: Task.php Progetto: ptphp/ptphp
 function action_my_task($status)
 {
     $user_id = Auth::get_user_id();
     if (!$user_id) {
         _throw("您还没有登陆", 9001);
     }
     $table = self::_table("user_mission");
     $table_mission = self::_table("mission");
     $rows = self::_db()->rows("select\n                      user_mission.*,mission.title,mission.thumb,mission.desc from {$table} as user_mission\n                      left join {$table_mission} as mission on mission.id = user_mission.mission_id\n                      where user_mission.user_id = ? order by user_mission.id desc ", $user_id);
     return array("missions" => $rows);
 }
Esempio n. 2
0
 function action_detail($id)
 {
     $table_mission = self::_table("mission");
     $table_user_mission = self::_table("user_mission");
     $table_mission_verify = self::_table("user_mission_verify");
     $table_mission_task = self::_table("mission_task");
     $table_user_wx = self::_table("user_wx");
     $table_user_wx_rel = self::_table("user_wx_rel");
     //任务详情
     $mission = self::_db()->row("select * from {$table_mission} where id = ?", $id);
     $mission['tips1'] = null;
     if (!empty($mission['start_time']) && time() < strtotime($mission['start_time'])) {
         $mission['tips1'] = "任务未开始";
     }
     if (!empty($mission['end_time']) && time() > strtotime($mission['end_time'])) {
         $mission['tips1'] = "任务已结束";
     }
     //参与总人数
     $join_users_count = self::_db()->row("select count(id) as total from {$table_user_mission} where mission_id = ?", $id);
     $join_users_total = $join_users_count['total'];
     //取最新的14个参与人头像
     $limit = 14;
     $join_users = self::_db()->rows("select user_id from {$table_user_mission} where mission_id = ? order by id desc limit {$limit}", $id);
     $avatars = array();
     foreach ($join_users as $join_user) {
         $avatar = self::_db()->row("select rel.user_id,wx.avatar as pic from {$table_user_wx_rel} as rel\n                          left join {$table_user_wx} as wx on wx.openid = rel.openid\n                          where rel.user_id = ?", $join_user['user_id']);
         if ($avatar) {
             $avatars[] = $avatar;
         }
     }
     //取子任务
     $tasks = self::_db()->rows("select * from {$table_mission_task} where mission_id = ? order by id asc", $id);
     $i = 1;
     foreach ($tasks as &$task) {
         $task['key'] = $i++;
     }
     $user_id = Auth::get_user_id();
     $user_mission = array();
     $user_missions = array();
     if ($user_id > 0) {
         //当前用户 参与的任务
         $user_mission = self::_db()->row("select * from {$table_user_mission} where mission_id = ? and user_id = ?", $id, $user_id);
         //当前用户 最近提交审核的任务
         $user_missions = self::_db()->rows("select * from {$table_mission_verify} where mission_id = ? and user_id = ? order by `task_key` asc ", $id, $user_id);
     }
     return array("mission" => $mission, "avatars" => $avatars, "join_users_total" => $join_users_total, "tasks" => $tasks, "user_mission" => $user_mission, "user_missions" => $user_missions);
 }