钱包修改
This commit is contained in:
@@ -6,6 +6,7 @@ use app\common\service\Jk8Services;
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\User as UserModel;
|
||||
use app\admin\model\UserScore;
|
||||
|
||||
class User extends Backend
|
||||
{
|
||||
@@ -14,6 +15,7 @@ class User extends Backend
|
||||
* @phpstan-var UserModel
|
||||
*/
|
||||
protected object $model;
|
||||
protected object $score;
|
||||
|
||||
protected array $withJoinTable = ['userGroup'];
|
||||
protected $jk8Services;
|
||||
@@ -28,6 +30,7 @@ class User extends Backend
|
||||
parent::initialize();
|
||||
$this->jk8Services = app(Jk8Services::class);
|
||||
$this->model = new UserModel();
|
||||
$this->score = new UserScore();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,4 +173,55 @@ class User extends Backend
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 钱包
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function wallet(): void
|
||||
{
|
||||
$miniGames = config('mini_game') ?: [];
|
||||
$pk = $this->model->getPk();
|
||||
$id = $this->request->param($pk);
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$this->model = new UserScore();
|
||||
parent::edit();
|
||||
return;
|
||||
}
|
||||
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
$this->error(__('Record not found'));
|
||||
}
|
||||
$existGameTypes = $row->userScore()
|
||||
->whereIn('game_type', array_keys($miniGames))
|
||||
->column('game_type');
|
||||
|
||||
$scoreInsert = [];
|
||||
foreach ($miniGames as $key => $name) {
|
||||
if (!in_array($key, $existGameTypes)) {
|
||||
$scoreInsert[] = [
|
||||
'user_id' => $id,
|
||||
'game_type' => $key,
|
||||
'score' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($scoreInsert)) {
|
||||
$row->userScore()->saveAll($scoreInsert);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'mini_game' => $miniGames,
|
||||
'score' => $row->userScore()
|
||||
->whereIn('game_type', array_keys($miniGames))
|
||||
->withoutField(['user_id'])
|
||||
->order('game_type', 'asc')
|
||||
->select()
|
||||
];
|
||||
$this->success('', $data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user