113 lines
3.2 KiB
PHP
113 lines
3.2 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ywxapp<admin@ywxapp.cn>
|
|
// +----------------------------------------------------------------------
|
|
declare(strict_types=1);
|
|
|
|
namespace app\member\controller;
|
|
|
|
use ywxapp\model\Task as TaskModel;
|
|
use ywxapp\controller\MemberBase;
|
|
use ywxapp\model\BaseModel;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 会员任务中心
|
|
*/
|
|
class Task extends MemberBase
|
|
{
|
|
protected $noNeedLogin = [];
|
|
protected $noNeedVerify = ['*'];
|
|
|
|
protected function initialize() {}
|
|
|
|
/**
|
|
* 任务中心列表页
|
|
*/
|
|
public function index()
|
|
{
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 任务列表(AJAX):返回启用任务 + 当前用户已领取状态
|
|
*/
|
|
public function list()
|
|
{
|
|
$uid = (int) ($this->auth->model->uid ?? 0);
|
|
$tasks = TaskModel::getEnabledList();
|
|
$claimed = TaskModel::getClaimedTaskIds($uid);
|
|
|
|
$list = [];
|
|
foreach ($tasks as $t) {
|
|
$t = $t->toArray();
|
|
$list[] = [
|
|
'id' => $t['id'],
|
|
'title' => $t['title'],
|
|
'description' => $t['description'],
|
|
'reward_type' => $t['reward_type'],
|
|
'reward_type_text' => TaskModel::getRewardTypeText((int) $t['reward_type']),
|
|
'reward_num' => $t['reward_num'],
|
|
'claimed' => in_array($t['id'], $claimed, true),
|
|
];
|
|
}
|
|
$this->result->success($list);
|
|
}
|
|
|
|
/**
|
|
* 领取任务奖励(AJAX)
|
|
*/
|
|
public function claim()
|
|
{
|
|
if (! $this->request->isPost()) {
|
|
$this->result->error('请求方式错误');
|
|
}
|
|
$uid = (int) ($this->auth->model->uid ?? 0);
|
|
$taskId = (int) $this->request->param('task_id', 0);
|
|
if ($uid <= 0) {
|
|
$this->result->error('请先登录会员中心');
|
|
}
|
|
if ($taskId <= 0) {
|
|
$this->result->error('任务参数错误');
|
|
}
|
|
[$ok, $msg] = TaskModel::claim($uid, $taskId);
|
|
if ($ok) {
|
|
$this->result->success([], $msg);
|
|
}
|
|
$this->result->error($msg);
|
|
}
|
|
|
|
/**
|
|
* 我的道具页
|
|
*/
|
|
public function myProp()
|
|
{
|
|
return $this->view->fetch('task/myprop');
|
|
}
|
|
|
|
/**
|
|
* 我的道具列表(AJAX)
|
|
*/
|
|
public function myPropList()
|
|
{
|
|
$uid = (int) ($this->auth->model->uid ?? 0);
|
|
\ywxapp\model\Task::ensureSchema(); // 确保 user_prop 关联表已就绪
|
|
if ($uid <= 0) {
|
|
$this->result->error('请先登录');
|
|
}
|
|
$list = Db::name('member_prop')
|
|
->alias('up')
|
|
->join('prop p', 'p.id = up.prop_id', 'left')
|
|
->where('up.uid', $uid)
|
|
->field('up.id, up.prop_id, up.num, up.create_at, p.title, p.icon')
|
|
->order('up.create_at', 'desc')
|
|
->select()
|
|
->toArray();
|
|
$this->result->success($list);
|
|
}
|
|
}
|