|
@@ -80,16 +80,25 @@ class Index extends Controller
|
|
|
$token = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . $_SERVER['HTTP_REFERER'] . get_client_ip(0) . $userInfoRes['data']['uid']);
|
|
$token = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . $_SERVER['HTTP_REFERER'] . get_client_ip(0) . $userInfoRes['data']['uid']);
|
|
|
$user = $userInfoRes['data'];
|
|
$user = $userInfoRes['data'];
|
|
|
|
|
|
|
|
|
|
+ $first = 0;
|
|
|
$userInfo = Db::table('awards_user_info')->where('uid', $user['uid'])->find();
|
|
$userInfo = Db::table('awards_user_info')->where('uid', $user['uid'])->find();
|
|
|
if (empty($userInfo)) {
|
|
if (empty($userInfo)) {
|
|
|
$userAttr = [
|
|
$userAttr = [
|
|
|
'uid' => $user['uid'],
|
|
'uid' => $user['uid'],
|
|
|
'portrait' => $user['profile_image_url'],
|
|
'portrait' => $user['profile_image_url'],
|
|
|
- 'nickname' => $user['name']
|
|
|
|
|
|
|
+ 'nickname' => $user['name'],
|
|
|
|
|
+ 'is_share' => 0,
|
|
|
|
|
+ 'count' => 1,
|
|
|
|
|
+ 'create_at' => time()
|
|
|
];
|
|
];
|
|
|
if (0 == Db::table('awards_user_info')->insert($userAttr)) {
|
|
if (0 == Db::table('awards_user_info')->insert($userAttr)) {
|
|
|
return $this->response(5001, '系统错误,请稍后再试~');
|
|
return $this->response(5001, '系统错误,请稍后再试~');
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $count = Db::table('awards_user_task_log')->where('uid', $user['uid'])->count('id');
|
|
|
|
|
+ if ($count < $userInfo['count']) {
|
|
|
|
|
+ $first = 1;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 生成加密用的密钥和向量
|
|
// 生成加密用的密钥和向量
|
|
@@ -107,41 +116,6 @@ class Index extends Controller
|
|
|
'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', $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', $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([
|
|
@@ -160,20 +134,11 @@ class Index extends Controller
|
|
|
public function checkRole()
|
|
public function checkRole()
|
|
|
{
|
|
{
|
|
|
$first = 0;
|
|
$first = 0;
|
|
|
- $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, 'not login.');
|
|
|
|
|
- } 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;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
|
|
|
|
|
+ $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
|
|
|
|
|
+ if ($count < $userInfo['count']) {
|
|
|
|
|
+ $first = 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $this->successResponse([
|
|
return $this->successResponse([
|
|
@@ -209,46 +174,23 @@ class Index extends Controller
|
|
|
|
|
|
|
|
$date = date('Y-m-d');
|
|
$date = date('Y-m-d');
|
|
|
|
|
|
|
|
- $userTask = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->find();
|
|
|
|
|
-
|
|
|
|
|
- if (empty($userTask)) {
|
|
|
|
|
|
|
+ $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
|
|
|
|
|
+ if (empty($userInfo)) {
|
|
|
return $this->response(403, '没有登录');
|
|
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(5002, '没有参与次数');
|
|
|
|
|
- }
|
|
|
|
|
- $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(5002, '没有参与次数');
|
|
|
|
|
- }
|
|
|
|
|
- $log = [
|
|
|
|
|
- 'uid' => Safe::$user['uid'],
|
|
|
|
|
- 'date' => $date,
|
|
|
|
|
- 'duration' => $duration,
|
|
|
|
|
- 'number' => $number,
|
|
|
|
|
- 'create_at' => time()
|
|
|
|
|
- ];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (empty($log)) {
|
|
|
|
|
|
|
+ $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
|
|
|
|
|
+ if ($count >= $userInfo['count']) {
|
|
|
return $this->response(5002, '没有参与次数');
|
|
return $this->response(5002, '没有参与次数');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $log = [
|
|
|
|
|
+ 'uid' => Safe::$user['uid'],
|
|
|
|
|
+ 'date' => $date,
|
|
|
|
|
+ 'duration' => $duration,
|
|
|
|
|
+ 'number' => $number,
|
|
|
|
|
+ 'create_at' => time()
|
|
|
|
|
+ ];
|
|
|
if (0 == Db::table('awards_user_task_log')->insert($log)) {
|
|
if (0 == Db::table('awards_user_task_log')->insert($log)) {
|
|
|
return $this->response(5001, '系统错误,请稍后再试~');
|
|
return $this->response(5001, '系统错误,请稍后再试~');
|
|
|
}
|
|
}
|
|
@@ -269,19 +211,20 @@ class Index extends Controller
|
|
|
{
|
|
{
|
|
|
$date = date('Y-m-d');
|
|
$date = date('Y-m-d');
|
|
|
|
|
|
|
|
- $userTask = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->find();
|
|
|
|
|
-
|
|
|
|
|
- if (empty($userTask)) {
|
|
|
|
|
|
|
+ $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
|
|
|
|
|
+ if (empty($userInfo)) {
|
|
|
return $this->response(403, '没有登录');
|
|
return $this->response(403, '没有登录');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ($userTask['share_add_votes'] > 0) {
|
|
|
|
|
- return $this->response(601, '今日已发布');
|
|
|
|
|
|
|
+ if ($userInfo['is_share'] > 0) {
|
|
|
|
|
+ return $this->response(601, '已发布');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 更新任务状态
|
|
// 更新任务状态
|
|
|
- $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
|
|
|
|
|
- 'share_add_votes' => 1,
|
|
|
|
|
|
|
+ $nums = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->update([
|
|
|
|
|
+ 'is_share' => 1,
|
|
|
|
|
+ 'count' => 2,
|
|
|
|
|
+ 'share_at' => time()
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
if ($nums) {
|
|
if ($nums) {
|
|
@@ -292,7 +235,7 @@ class Index extends Controller
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 排行接口
|
|
|
|
|
|
|
+ * 头号排行接口
|
|
|
* @throws FuncNotFoundException
|
|
* @throws FuncNotFoundException
|
|
|
* @throws ClassNotFoundException
|
|
* @throws ClassNotFoundException
|
|
|
* @throws DbException
|
|
* @throws DbException
|
|
@@ -302,16 +245,61 @@ class Index extends Controller
|
|
|
*/
|
|
*/
|
|
|
public function ranking()
|
|
public function ranking()
|
|
|
{
|
|
{
|
|
|
- $date = date('Y-m-d');
|
|
|
|
|
- $res = Db::table('awards_user_task_log')->alias("l")
|
|
|
|
|
|
|
+ $ranking = Db::table('awards_user_task_log')->alias("l")
|
|
|
->leftJoin('awards_user_info u', 'l.uid = u.uid')
|
|
->leftJoin('awards_user_info u', 'l.uid = u.uid')
|
|
|
->field(['u.nickname', 'u.portrait', 'u.uid', 'l.duration', 'l.number'])
|
|
->field(['u.nickname', 'u.portrait', 'u.uid', 'l.duration', 'l.number'])
|
|
|
- ->where('l.date', $date)
|
|
|
|
|
|
|
+ ->order('l.number', 'desc')
|
|
|
|
|
+ ->order('l.duration', 'asc')
|
|
|
|
|
+ ->limit(50)
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ $userInfo = 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'])
|
|
|
|
|
+ ->order('l.number', 'desc')
|
|
|
|
|
+ ->order('l.duration', 'asc')
|
|
|
|
|
+ ->find();
|
|
|
|
|
+
|
|
|
|
|
+ $res = [
|
|
|
|
|
+ 'self' => $userInfo,
|
|
|
|
|
+ 'ranking' => $ranking
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ return $this->successResponse($res);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 最新排行接口
|
|
|
|
|
+ * @throws FuncNotFoundException
|
|
|
|
|
+ * @throws ClassNotFoundException
|
|
|
|
|
+ * @throws DbException
|
|
|
|
|
+ * @throws ModelNotFoundException
|
|
|
|
|
+ * @throws DataNotFoundException
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ public function newRanking()
|
|
|
|
|
+ {
|
|
|
|
|
+ $ranking = 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'])
|
|
|
|
|
+ ->order('l.create_at', 'desc')
|
|
|
->order('l.number', 'desc')
|
|
->order('l.number', 'desc')
|
|
|
->order('l.duration', 'asc')
|
|
->order('l.duration', 'asc')
|
|
|
->limit(15)
|
|
->limit(15)
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
|
|
+ $userInfo = 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'])
|
|
|
|
|
+ ->order('l.number', 'desc')
|
|
|
|
|
+ ->order('l.duration', 'asc')
|
|
|
|
|
+ ->find();
|
|
|
|
|
+
|
|
|
|
|
+ $res = [
|
|
|
|
|
+ 'self' => $userInfo,
|
|
|
|
|
+ 'ranking' => $ranking
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
return $this->successResponse($res);
|
|
return $this->successResponse($res);
|
|
|
}
|
|
}
|
|
|
|
|
|