69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\library\DatabaseRoute;
|
|
use think\facade\Db;
|
|
|
|
class TaskCenterReward extends Backend
|
|
{
|
|
protected array $noNeedLogin = ['*'];
|
|
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
|
|
|
public function selectTaskCenterReward()
|
|
{
|
|
$params = $this->request->param();
|
|
$this->successWithData(DatabaseRoute::paginateDb('task_center_reward', function ($query) use ($params) {
|
|
if (!empty($params['taskId'])) {
|
|
$query->where([
|
|
'task_id' => $params['taskId']
|
|
]);
|
|
}
|
|
return $query->order('id', false);
|
|
|
|
}, $params['page'] ?? 1, $params['limit'] ?? 10));
|
|
}
|
|
|
|
public function updateTaskCenterReward()
|
|
{
|
|
$params = $this->request->param();
|
|
$params = convertKeysCamelToSnakeRecursive($params);
|
|
$info = Db::name('task_center_reward')->where([
|
|
'id' => $params['id']
|
|
]);
|
|
|
|
if (!empty($info['total_number']) && !empty($params['total_number']) && $info['total_number'] != $params['total_number']) {
|
|
$surplusNumber = $params['total_number'] - $info['total_number'];
|
|
$surplusNumber = $surplusNumber > 0 ?? $params['total_number'];
|
|
$params['total_number'] = $surplusNumber;
|
|
}
|
|
|
|
$params['update_time'] = getNormalDate();
|
|
Db::name('task_center_reward')->where([
|
|
'id' => $params['id']
|
|
])->update($params);
|
|
|
|
$this->success();
|
|
}
|
|
|
|
public function insertTaskCenterReward()
|
|
{
|
|
$params = $this->request->post();
|
|
$params = convertKeysCamelToSnakeRecursive($params);
|
|
$params['surplus_number'] = $params['total_number'];
|
|
unset($params['is_trusted']);
|
|
unset($params['id']);
|
|
Db::name('task_center_reward')->insert($params);
|
|
$this->success();
|
|
}
|
|
|
|
public function deleteTaskCenterReward()
|
|
{
|
|
$id = $this->request->param('id');
|
|
Db::name('task_center_reward')->delete([
|
|
'id' => $id
|
|
]);
|
|
$this->success();
|
|
}
|
|
} |