|
@@ -91,13 +91,171 @@ class Index extends Controller
|
|
|
'ase_iv' => $iv,
|
|
'ase_iv' => $iv,
|
|
|
'uid' => $user['uid'],
|
|
'uid' => $user['uid'],
|
|
|
];
|
|
];
|
|
|
|
|
+
|
|
|
|
|
+ $first = 0;
|
|
|
|
|
+ $date = date('Y-m-d');
|
|
|
|
|
+ $userTask = Db::table('awards_user_task')->where('uid', $user['uid'])->where('date', $date)->find();
|
|
|
|
|
+ if (empty($userTask)) {
|
|
|
|
|
+ // 当天第一次,初始化数据
|
|
|
|
|
+ $state = [
|
|
|
|
|
+ // 品牌任务完成状态
|
|
|
|
|
+ 'finish_state' => 0,
|
|
|
|
|
+ // 关注子任务状态
|
|
|
|
|
+ 'follow_state' => 0,
|
|
|
|
|
+ // 转发子任务状态
|
|
|
|
|
+ 'forward_state' => 0,
|
|
|
|
|
+ // 查看浏览主页任务状态
|
|
|
|
|
+ 'view_state' => 0,
|
|
|
|
|
+ // 品牌任务完成后是否加票
|
|
|
|
|
+ 'finish_add_votes' => 0,
|
|
|
|
|
+ // 分享完成后是否加票
|
|
|
|
|
+ 'share_add_votes' => 0,
|
|
|
|
|
+ 'uid' => $user['uid'],
|
|
|
|
|
+ 'date' => $date,
|
|
|
|
|
+ ];
|
|
|
|
|
+ if (0 == Db::table('awards_user_task')->insert($state)) {
|
|
|
|
|
+ return $this->response(5001, '系统错误,请稍后再试~');
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ($userTask['finish_state'] == 0 && $userTask['share_add_votes'] == 0) {
|
|
|
|
|
+ $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->where('date', $date)->count('id');
|
|
|
|
|
+ if ($count < 1) {
|
|
|
|
|
+ $first = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ($userTask['finish_state'] > 0 && $userTask['share_add_votes'] > 0) {
|
|
|
|
|
+ $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->where('date', $date)->count('id');
|
|
|
|
|
+ if ($count < 2) {
|
|
|
|
|
+ $first = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
// 缓存用户信息1天
|
|
// 缓存用户信息1天
|
|
|
Cache::set('u:' . $token, json_encode($cacheUser), 86400);
|
|
Cache::set('u:' . $token, json_encode($cacheUser), 86400);
|
|
|
return $this->successResponse([
|
|
return $this->successResponse([
|
|
|
'user' => $user,
|
|
'user' => $user,
|
|
|
'token' => $token,
|
|
'token' => $token,
|
|
|
- 'first' => Cache::get('u:f:' . $user['uid']) != 1,
|
|
|
|
|
|
|
+ 'first' => $first,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 提交任务接口
|
|
|
|
|
+ * @throws FuncNotFoundException
|
|
|
|
|
+ * @throws ClassNotFoundException
|
|
|
|
|
+ * @throws DbException
|
|
|
|
|
+ * @throws ModelNotFoundException
|
|
|
|
|
+ * @throws DataNotFoundException
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ public function submitTask()
|
|
|
|
|
+ {
|
|
|
|
|
+ $duration = Request::post("duration");
|
|
|
|
|
+ $number = Request::post("number");
|
|
|
|
|
+
|
|
|
|
|
+ $date = date('Y-m-d');
|
|
|
|
|
+
|
|
|
|
|
+ $userTask = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->find();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($userTask)) {
|
|
|
|
|
+ return $this->response(403, '没有登录');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $log = [];
|
|
|
|
|
+ if ($userTask['finish_state'] == 0) {
|
|
|
|
|
+ $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->where('date', $date)->count('id');
|
|
|
|
|
+ if ($count > 0) {
|
|
|
|
|
+ return $this->response(403, '没有参与次数');
|
|
|
|
|
+ }
|
|
|
|
|
+ $log = [
|
|
|
|
|
+ 'uid' => Safe::$user['uid'],
|
|
|
|
|
+ 'date' => $date,
|
|
|
|
|
+ 'duration' => $duration,
|
|
|
|
|
+ 'number' => $number,
|
|
|
|
|
+ 'create_at' => time()
|
|
|
|
|
+ ];
|
|
|
|
|
+ Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
|
|
|
|
|
+ 'finish_state' => 1,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ } else if ($userTask['share_add_votes'] == 1) {
|
|
|
|
|
+ $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->where('date', $date)->count('id');
|
|
|
|
|
+ if ($count > 1) {
|
|
|
|
|
+ return $this->response(403, '没有参与次数');
|
|
|
|
|
+ }
|
|
|
|
|
+ $log = [
|
|
|
|
|
+ 'uid' => Safe::$user['uid'],
|
|
|
|
|
+ 'date' => $date,
|
|
|
|
|
+ 'duration' => $duration,
|
|
|
|
|
+ 'number' => $number,
|
|
|
|
|
+ 'create_at' => time()
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($log)) {
|
|
|
|
|
+ return $this->response(403, '没有参与次数');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (0 == Db::table('awards_user_task_log')->insert($log)) {
|
|
|
|
|
+ return $this->response(5001, '系统错误,请稍后再试~');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this->successResponse(null, '提交成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 提交发布微博接口
|
|
|
|
|
+ * @throws FuncNotFoundException
|
|
|
|
|
+ * @throws ClassNotFoundException
|
|
|
|
|
+ * @throws DbException
|
|
|
|
|
+ * @throws ModelNotFoundException
|
|
|
|
|
+ * @throws DataNotFoundException
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ public function submitShare()
|
|
|
|
|
+ {
|
|
|
|
|
+ $date = date('Y-m-d');
|
|
|
|
|
+
|
|
|
|
|
+ $userTask = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->find();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($userTask)) {
|
|
|
|
|
+ return $this->response(403, '没有登录');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($userTask['share_add_votes'] > 0) {
|
|
|
|
|
+ return $this->response(601, '今日已发布');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新任务状态
|
|
|
|
|
+ $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
|
|
|
|
|
+ 'share_add_votes' => 1,
|
|
|
]);
|
|
]);
|
|
|
|
|
+
|
|
|
|
|
+ if ($nums) {
|
|
|
|
|
+ return $this->response(601, '发布成功');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return $this->response(601, '发布失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 排行接口
|
|
|
|
|
+ * @throws FuncNotFoundException
|
|
|
|
|
+ * @throws ClassNotFoundException
|
|
|
|
|
+ * @throws DbException
|
|
|
|
|
+ * @throws ModelNotFoundException
|
|
|
|
|
+ * @throws DataNotFoundException
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ public function ranking()
|
|
|
|
|
+ {
|
|
|
|
|
+ $date = date('Y-m-d');
|
|
|
|
|
+ $res = Db::table('awards_user_task_log')->alias("l")
|
|
|
|
|
+ ->leftJoin('awards_user_info u', 'l.uid = u.uid')
|
|
|
|
|
+ ->field(['u.nickname', 'u.portrait', 'u.uid', 'l.duration', 'l.number'])
|
|
|
|
|
+ ->where('l.date', $date)
|
|
|
|
|
+ ->order('l.number', 'desc')
|
|
|
|
|
+ ->order('l.duration', 'asc')
|
|
|
|
|
+ ->limit(15)
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ return $this->successResponse($res);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|