|
@@ -22,6 +22,26 @@ class Info extends Base
|
|
|
$this->getOne($data[$k]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户任务列表
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function user()
|
|
|
+ {
|
|
|
+ $this->data['cate'] = Dever::db('task/cate')->state();
|
|
|
+
|
|
|
+ $data = Dever::db('task/user_task')->getAll();
|
|
|
+ if ($data) {
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $this->getOne($data[$k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
@@ -32,30 +52,91 @@ class Info extends Base
|
|
|
*/
|
|
|
public function one()
|
|
|
{
|
|
|
+ $this->checkUser();
|
|
|
+
|
|
|
$id = Dever::input('id');
|
|
|
$info = array();
|
|
|
if ($id > 0) {
|
|
|
$this->data['cate'] = Dever::db('task/cate')->state();
|
|
|
$info = Dever::db('task/info')->one($id);
|
|
|
- $this->getOne($info);
|
|
|
+ # 检测用户是否登录,是否认证,仅显示认证信息
|
|
|
+
|
|
|
+ $this->getOne($info, $button = true);
|
|
|
}
|
|
|
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
- private function getOne(& $data)
|
|
|
+ /**
|
|
|
+ * 领取任务
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function submit()
|
|
|
+ {
|
|
|
+ # 检测用户是否登录,是否认证
|
|
|
+ $this->checkUser(true);
|
|
|
+
|
|
|
+ $id = Dever::input('id');
|
|
|
+ $info = array();
|
|
|
+ if ($id > 0) {
|
|
|
+ $info = Dever::db('task/info')->one($id);
|
|
|
+ $this->getOne($info, $button = true);
|
|
|
+
|
|
|
+ if (isset($info['button']) && is_array($info['button']) && isset($info['button']['status']) && $info['button']['status'] > 0) {
|
|
|
+ if ($info['button']['status'] == 1) {
|
|
|
+ # 可以领取
|
|
|
+ return $this->submit_action($info);
|
|
|
+ } else {
|
|
|
+ Dever::alert($info['button']['desc']);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Dever::alert('领取失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Dever::alert('领取失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 立刻领取
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function submit_action($info)
|
|
|
+ {
|
|
|
+ $user = Dever::db('task/user_task')->one(array('task_id' => $info['id'], 'uid' => $this->data['uid'], 'rand' => Dever::id()));
|
|
|
+ if (!$user) {
|
|
|
+ $insert['uid'] = $this->data['uid'];
|
|
|
+ $insert['task_id'] = $info['id'];
|
|
|
+ $insert['company_id'] = $info['company_id'];
|
|
|
+ $insert['cate_id'] = $info['cate_id'];
|
|
|
+ $insert['level_id'] = $info['level_id'];
|
|
|
+ $insert['status'] = 1;
|
|
|
+ $info['user_task'] = Dever::db('task/user_task')->insert($insert);
|
|
|
+ return $info;
|
|
|
+ } else {
|
|
|
+ Dever::alert('领取失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 任务详情信息
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function getOne(& $data, $button = false)
|
|
|
{
|
|
|
# 多少人领取
|
|
|
$data['user_num'] = Dever::db('task/user_task')->total(array('task_id' => $data['id']));
|
|
|
|
|
|
# 3 金币/项
|
|
|
- $data['list_score'] = $data['task_cash'] . ' ' . $this->data['config']['score_name'] . '/' . $this->data['config']['score_name_ext'];
|
|
|
+ $data['list_score'] = $data['score'] . ' ' . $this->data['config']['score_name'] . '/项';
|
|
|
|
|
|
# 组员贡献 1 金币/项
|
|
|
- $data['list_group_score'] = '组员贡献 ' . $data['task_cash'] . ' ' . $this->data['config']['score_name'] . '/' . $this->data['config']['score_name_ext'];
|
|
|
+ $data['list_group_score'] = '组员贡献 ' . $data['score'] . ' ' . $this->data['config']['score_name'] . '/项';
|
|
|
|
|
|
#3 金币 + 1 金币
|
|
|
- $data['score'] = $data['task_cash'] . ' ' . $this->data['config']['score_name'] . ' + ' . $data['task_cash'] . ' ' . $this->data['config']['score_name'];
|
|
|
+ $data['score'] = $data['score'] . ' ' . $this->data['config']['score_name'] . ' + ' . $data['score'] . ' ' . $this->data['config']['score_name'];
|
|
|
|
|
|
# 任务类别
|
|
|
$data['cate'] = $this->data['cate'][$data['cate_id']];
|
|
@@ -64,37 +145,125 @@ class Info extends Base
|
|
|
$data['sdate_str'] = date('Y.m.d', $data['sdate']);
|
|
|
$data['edate_str'] = date('Y.m.d', $data['edate']);
|
|
|
|
|
|
- $data['button'] = $this->button($data);
|
|
|
-
|
|
|
+ if ($button) {
|
|
|
+ $data['button'] = $this->button($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['uid']) && $data['uid'] > 0 && $this->data['uid'] > 0 && $data['uid'] == $this->data['uid']) {
|
|
|
+ $data['score'] = $this->score($data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前用户获取的积分
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function score($data)
|
|
|
+ {
|
|
|
+ # 查看该用户完成的报告数
|
|
|
+ $where = array();
|
|
|
+ $where['uid'] = $data['uid'];
|
|
|
+ $where['status'] = 2;
|
|
|
+ $log = Dever::db('task/user_score_log')->getAll($where);
|
|
|
+
|
|
|
+ # 三项描述
|
|
|
+ $result = array();
|
|
|
+ $result['report'] = $result['group'] = $result['total'] = '';
|
|
|
+ $result['report_num'] = $result['report_score'] = $result['group_score'] = $result['total_score'] = 0;
|
|
|
+
|
|
|
+ if ($log) {
|
|
|
+ $result['report_num'] = count($report);
|
|
|
+ foreach ($log as $k => $v) {
|
|
|
+ if ($v['type'] == 4 && $v['report_id'] > 0) {
|
|
|
+ $result['report_score'] += $v['score'];
|
|
|
+ $result['report_num']++;
|
|
|
+ } elseif ($v['type'] == 5) {
|
|
|
+ $result['group_score'] += $v['score'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $result['total_score'] = $result['report_score'] + $result['group_score'];
|
|
|
+
|
|
|
+ if ($result['report_score'] > 0) {
|
|
|
+ $result['report'] = '已完成 '.$result['report_num'].' 份任务报告,获得 '.$result['report_score'].' ' . $this->data['config']['score_name'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($result['group_score'] > 0) {
|
|
|
+ $result['group'] = '组员贡献 '.$result['group_score'].' ' . $this->result['config']['score_name'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($result['total_score'] > 0) {
|
|
|
+ $result['total'] = '合计获得 '.$result['total_score'].' ' . $this->data['config']['score_name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 领取任务按钮的状态
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function button($data)
|
|
|
{
|
|
|
- # 领取任务按钮的状态
|
|
|
- # 1 可以领取 2 任务已过期 3 抢光了 4 已领取 5 等级不够 6 已领取过该商家任务 7 已领取过该类别任务
|
|
|
# 大于1都不能点击
|
|
|
$button = 1;
|
|
|
|
|
|
if ($this->data['time'] > $data['edate']) {
|
|
|
# 任务已到期
|
|
|
$button = 2;
|
|
|
- } elseif ($data['user_num'] >= $this->data['config']['num']) {
|
|
|
+ } elseif ($data['user_num'] >= $data['num']) {
|
|
|
# 抢光了
|
|
|
$button = 3;
|
|
|
} elseif (isset($this->data['uid']) && $this->data['uid']) {
|
|
|
- # 判断是否领取
|
|
|
- $user = Dever::db('task/user_task')->one(array('task_id' => $data['id'], 'uid' => $this->data['uid']));
|
|
|
-
|
|
|
- if ($user) {
|
|
|
- # 已领取
|
|
|
+ # 判断等级
|
|
|
+ $level = Dever::db('task/level')->one($data['level_id']);
|
|
|
+ if ($level && isset($this->data['user_score']) && $this->data['uesr_score'] && $level['score'] > $this->data['user_score']['score']) {
|
|
|
+ # 等级不够
|
|
|
$button = 4;
|
|
|
} else {
|
|
|
- # 判断商家领取次数
|
|
|
- $company = Dever::db('task/user_task')->total(array('company_id' => $data['company_id']));
|
|
|
- if ($data['company_'])
|
|
|
+ # 判断是否领取
|
|
|
+ $user = Dever::db('task/user_task')->one(array('task_id' => $data['id'], 'uid' => $this->data['uid']));
|
|
|
+ if ($user) {
|
|
|
+ # 已领取
|
|
|
+ $button = 5;
|
|
|
+ } else {
|
|
|
+ # 判断类别领取次数
|
|
|
+ $cate = Dever::db('task/user_task')->total(array('uid' => $this->data['uid'], 'cate_id' => $data['cate_id'], 'status' => 3));
|
|
|
+ if ($data['cate_num'] >= $cate) {
|
|
|
+ $button = 6;
|
|
|
+ } else {
|
|
|
+ # 判断商家领取次数
|
|
|
+ $company = Dever::db('task/user_task')->total(array('uid' => $this->data['uid'], 'company_id' => $data['company_id'], 'status' => 3));
|
|
|
+ if ($data['company_num'] >= $company) {
|
|
|
+ $button = 7;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $button;
|
|
|
+ $config = array
|
|
|
+ (
|
|
|
+ 1 => '可以领取',
|
|
|
+ 2 => '任务已过期',
|
|
|
+ 3 => '抢光了',
|
|
|
+ 4 => '等级不够',
|
|
|
+ 5 => '已领取',
|
|
|
+ 6 => '已领取过该商家'.$data['cate']['name'],
|
|
|
+ 7 => '已领取过该商家任务',
|
|
|
+ );
|
|
|
+
|
|
|
+ $result['status'] = $button;
|
|
|
+ $result['desc'] = $config[$button];
|
|
|
+ $result['icon'] = '';
|
|
|
+
|
|
|
+ if ($result['status'] == 4) {
|
|
|
+ $result['icon'] = 'level';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
}
|