[色子游戏]玩家
This commit is contained in:
122
server/app/dice/controller/player/DicePlayerController.php
Normal file
122
server/app/dice/controller/player/DicePlayerController.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\player;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\player\DicePlayerLogic;
|
||||
use app\dice\validate\player\DicePlayerValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家控制器
|
||||
*/
|
||||
class DicePlayerController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DicePlayerLogic();
|
||||
$this->validate = new DicePlayerValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家列表', 'dice:player:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['username', ''],
|
||||
['name', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家读取', 'dice:player:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家添加', 'dice:player:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家修改', 'dice:player:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家删除', 'dice:player:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
27
server/app/dice/logic/player/DicePlayerLogic.php
Normal file
27
server/app/dice/logic/player/DicePlayerLogic.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\player;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家逻辑层
|
||||
*/
|
||||
class DicePlayerLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DicePlayer();
|
||||
}
|
||||
|
||||
}
|
||||
65
server/app/dice/model/player/DicePlayer.php
Normal file
65
server/app/dice/model/player/DicePlayer.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\player;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家模型
|
||||
*
|
||||
* dice_player 大富翁-玩家
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $username 用户名
|
||||
* @property $name 昵称
|
||||
* @property $password 密码
|
||||
* @property $status 状态
|
||||
* @property $coin 平台币
|
||||
* @property $is_up 倍率
|
||||
* @property $t1_wight T1池权重
|
||||
* @property $t2_wight T2池权重
|
||||
* @property $t3_wight T3池权重
|
||||
* @property $t4_wight T4池权重
|
||||
* @property $t5_wight T5池权重
|
||||
* @property $total_draw_count 总抽奖次数
|
||||
* @property $paid_draw_count 购买抽奖次数
|
||||
* @property $free_draw_count 赠送抽奖次数
|
||||
* @property $created_at 创建时间
|
||||
* @property $updated_at 更新时间
|
||||
* @property $deleted_at 删除时间
|
||||
*/
|
||||
class DicePlayer extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 数据库表名称
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'dice_player';
|
||||
|
||||
/**
|
||||
* 用户名 搜索
|
||||
*/
|
||||
public function searchUsernameAttr($query, $value)
|
||||
{
|
||||
$query->where('username', 'like', '%'.$value.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
* 昵称 搜索
|
||||
*/
|
||||
public function searchNameAttr($query, $value)
|
||||
{
|
||||
$query->where('name', 'like', '%'.$value.'%');
|
||||
}
|
||||
|
||||
}
|
||||
58
server/app/dice/validate/player/DicePlayerValidate.php
Normal file
58
server/app/dice/validate/player/DicePlayerValidate.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\player;
|
||||
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家验证器
|
||||
*/
|
||||
class DicePlayerValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'username' => 'require',
|
||||
'name' => 'require',
|
||||
'password' => 'require',
|
||||
'status' => 'require',
|
||||
'coin' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'username' => '用户名必须填写',
|
||||
'name' => '昵称必须填写',
|
||||
'password' => '密码必须填写',
|
||||
'status' => '状态必须填写',
|
||||
'coin' => '平台币必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'save' => [
|
||||
'username',
|
||||
'name',
|
||||
'password',
|
||||
'status',
|
||||
'coin',
|
||||
],
|
||||
'update' => [
|
||||
'username',
|
||||
'name',
|
||||
'password',
|
||||
'status',
|
||||
'coin',
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user