Automation/app/Controllers/Admin/UserController.php
2024-08-30 19:32:21 +09:00

49 lines
1.4 KiB
PHP

<?php
namespace App\Controllers\Admin;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Models\UserModel;
use App\Traits\MangboardTrait;
class UserController extends AdminController
{
use MangboardTrait;
private $_model = null;
public function __construct()
{
$this->_model = new UserModel();
}
public function index()
{
return __METHOD__;
}
public function update()
{
try {
$id = $this->request->getPost('id');
$point = $this->request->getPost('point');
$sign = $this->request->getPost('point') ?: "+";
$entity = is_numeric($id) ? $this->_model->getEntityByPK(intval($id)) : $this->_model->getEntityByID($id);
if (!$entity) {
throw new \Exception(sprintf("해당 회원[%s:%s]이 없습니다.", gettype($id), $id));
}
if (!is_numeric($point)) {
throw new \Exception("포인트 값에 {$point}를 사용할 수 없습니다.");
}
$entity = $this->setUserPointByMangboardTrait($entity, intval($point), $sign);
return "완료되었습니다.";
} catch (\Exception $e) {
log_message('error', $e->getMessage());
return $e->getMessage();
}
}
}