首页修改,jk8修改,历史记录相关,api权限
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\common\service\Jk8Services;
|
||||
use app\admin\model\MoneyLogHistory;
|
||||
use Throwable;
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\UserMoneyLog;
|
||||
@@ -16,19 +16,17 @@ class MoneyLog extends Backend
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
protected array $withJoinTable = ['user', 'admin'];
|
||||
protected array $withJoinTable = ['user', 'admin', 'bank'];
|
||||
protected array $withTable = ['scoreLog'];
|
||||
|
||||
// 排除字段
|
||||
protected string|array $preExcludeFields = ['create_time'];
|
||||
|
||||
protected string|array $quickSearchField = ['user.username', 'user.nickname'];
|
||||
protected $jk8Services;
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
$this->jk8Services = app(Jk8Services::class);
|
||||
$this->model = new UserMoneyLog();
|
||||
}
|
||||
|
||||
@@ -88,27 +86,13 @@ class MoneyLog extends Backend
|
||||
$result = false;
|
||||
$data = $this->excludeFields($data);
|
||||
|
||||
$user = User::where('id', $data['user_id'])->find();
|
||||
if ($data['type'] == 2) {
|
||||
$data['money'] = -$data['money'];
|
||||
}
|
||||
if ($user->money + $data['money'] < 0) {
|
||||
$this->error(__('Insufficient Credit'));
|
||||
}
|
||||
|
||||
try {
|
||||
// 模型验证
|
||||
$this->validateModelData($data, 'add');
|
||||
$transactionId = $this->jk8Services->setScore($user['jk_username'], $data['money']);
|
||||
} catch (Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
$data['transaction_id'] = $transactionId;
|
||||
$data['created_by'] = $this->auth->getInfo()['id'];
|
||||
// $data['type'] = $data['money'] > 0 ? 1 : 2;
|
||||
$result = $this->model->save($data);
|
||||
$this->model->commit();
|
||||
} catch (Throwable $e) {
|
||||
@@ -143,15 +127,49 @@ class MoneyLog extends Backend
|
||||
if (!$row) {
|
||||
$this->error(__('Record not found'));
|
||||
}
|
||||
$user = User::where('id', $row['user_id'])->find();
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
parent::edit();
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
$result = $row->save($data);
|
||||
$this->model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Update successful'));
|
||||
} else {
|
||||
$this->error(__('No rows updated'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
$row['username'] = $user['username'];
|
||||
$row['nickname'] = $user['nickname'];
|
||||
$this->success('', [
|
||||
'row' => $row
|
||||
]);
|
||||
}
|
||||
|
||||
public function logHistory($id): void
|
||||
{
|
||||
$bindFields = [
|
||||
'admin' => ['id','username'],
|
||||
];
|
||||
$history = MoneyLogHistory::withJoin($bindFields, 'left')
|
||||
->where('money_log_id', $id)
|
||||
->select();
|
||||
if (!empty($history)) {
|
||||
foreach ($history as &$item) {
|
||||
$item['admin_name'] = $item['admin']['username'] ?? '';
|
||||
unset($item['admin']);
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
$this->success('', $history);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user