106 lines
2.6 KiB
PHP
106 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\user;
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\library\Auth;
|
|
use app\common\model\User;
|
|
use app\common\model\ScoreLog;
|
|
use app\common\model\MoneyLog;
|
|
/**
|
|
* 资产管理
|
|
*
|
|
* @icon fa fa-user
|
|
*/
|
|
class Assets extends Backend
|
|
{
|
|
|
|
protected $relationSearch = true;
|
|
|
|
/**
|
|
* @var \app\admin\model\User
|
|
*/
|
|
protected $model = null;
|
|
protected $validate = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new ScoreLog();
|
|
$this->validate = new \app\admin\validate\user\Score();
|
|
}
|
|
|
|
/**
|
|
* 查看
|
|
*
|
|
* @return string|Json
|
|
* @throws \think\Exception
|
|
* @throws DbException
|
|
*/
|
|
public function index()
|
|
{
|
|
$type = $this->request->post("type");
|
|
|
|
if($type == 'money'){
|
|
$this->model = new MoneyLog();
|
|
}else{
|
|
$this->model = new ScoreLog();
|
|
}
|
|
|
|
//设置过滤方法
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
//如果发送的来源是 Selectpage,则转发到 Selectpage
|
|
if ($this->request->request('keyField')) {
|
|
return $this->selectpage();
|
|
}
|
|
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
|
$list = $this->model
|
|
->where($where)
|
|
->order($sort, $order)
|
|
->paginate($limit);
|
|
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
|
return $this->success("",$result);
|
|
}
|
|
|
|
/**
|
|
* 变更会员积分
|
|
* @param int $score 积分
|
|
* @param int $user_id 会员ID
|
|
* @param string $memo 备注
|
|
*/
|
|
public function change()
|
|
{
|
|
$params = $this->request->post("row/a");
|
|
$type = $this->request->post("type");
|
|
|
|
|
|
//验证
|
|
$result = $this->validate->scene('change')->check($params);
|
|
if(true !== $result){
|
|
// 验证失败 输出错误信息
|
|
$result = $result===false ? '数据效验失败' : $result;
|
|
$this->error($result);
|
|
}
|
|
|
|
//获取用户信息
|
|
$userInfo = User::getUserInfo($params['user_id']);
|
|
if(!$userInfo){
|
|
$this->error("获取用户信息失败");
|
|
}
|
|
|
|
if($params['type']=='0'){
|
|
$params['num'] *= -1;
|
|
}
|
|
|
|
if($type == 'money'){
|
|
User::money($params['num'], $params['user_id'], $params['memo']);
|
|
}else{
|
|
User::score($params['num'], $params['user_id'], $params['memo']);
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->success("操作成功");
|
|
}
|
|
} |