128 lines
4.3 KiB
Smarty
128 lines
4.3 KiB
Smarty
<?php
|
|
namespace app\api\controller;
|
|
use think\facade\Db;
|
|
use support\Request;
|
|
use taoser\facade\Validate;
|
|
use support\Jwt;
|
|
use hg\apidoc\annotation as Apidoc;
|
|
/**
|
|
* @ControllerAnnotation('{$description}')
|
|
* Class {$controllerClass}
|
|
* @package app\api\controller
|
|
*/
|
|
class {$controllerClass} extends BaseController
|
|
{
|
|
/**
|
|
* 不需要鉴权的方法
|
|
* @var array
|
|
*/
|
|
protected array \$noNeedRight = [];
|
|
/**
|
|
* 无需登录及鉴权的方法
|
|
* @var array
|
|
*/
|
|
protected array \$noNeedLogin = [];
|
|
|
|
function __construct()
|
|
{
|
|
$this->model = new \app\model\{:(str_replace('','',$controllerClass)};
|
|
}
|
|
|
|
/**
|
|
* 列表
|
|
* @Apidoc\Method("POST")
|
|
* @Apidoc\Query("network", type="string", require=true, desc="网络")
|
|
* @Apidoc\Query("page", type="int", require=true, desc="页码",default=1)
|
|
* @Apidoc\Query("limit", type="int", require=true, desc="分页大小",default=10)
|
|
*/
|
|
public function list()
|
|
{
|
|
$limit = (int)input('limit',10);
|
|
$page = (int)input('page',1);
|
|
$status = (int)input('status',-1);
|
|
$network = input('network');
|
|
$type = input('type');
|
|
$model = $this->model->where('user_id',\support\Jwt\JwtToken::getCurrentId());
|
|
//->where('network','BEP-20');
|
|
if($type){
|
|
$model = $model->where('status',1);
|
|
}
|
|
if($network){
|
|
$model = $model->where('network',$network);
|
|
}
|
|
$list = $model->paginate($limit);
|
|
return $this->success(__('successful'),$list->toArray());
|
|
|
|
}
|
|
/**
|
|
* 创建
|
|
* @Apidoc\Method("POST")
|
|
* @Apidoc\Param("network", type="string", require=true, desc="网络,BEP-20,TRC-20",default="BEP-20")
|
|
* @Apidoc\Param("address", type="string", require=true, desc="地址")
|
|
* @Apidoc\Param("title", type="string", require=true, desc="名称")
|
|
* @Apidoc\Param("status", type="string", require=true, desc="状态,可选,1,0,默认1")
|
|
*/
|
|
public function create()
|
|
{
|
|
//captcha_verfiy('image','create_address');
|
|
//* @Apidoc\Param("code", type="string", require=true, desc="图形验证码 event=create_address")
|
|
//$trade_password = input('trade_password');
|
|
//\support\Jwt::verify_trade_password($trade_password);
|
|
//* @Apidoc\Param("trade_password", type="string", require=true, desc="交易密码")
|
|
$data = [
|
|
'title' => input('title',''),
|
|
'network' => input('network','BEP-20'),
|
|
'address' => input('address'),
|
|
'status' => input('status',0),
|
|
'user_id' => \support\Jwt\JwtToken::getCurrentId()
|
|
];
|
|
if(!$data['title']){
|
|
return $this->error(__('Invalid title'));
|
|
}
|
|
// || substr($data['address'],0,2)!='0x'
|
|
if(!$data['address']){
|
|
return $this->error(__('Invalid address'));
|
|
}
|
|
$this->model->create($data);
|
|
return $this->success(__('successful'));
|
|
}
|
|
/**
|
|
* 编辑
|
|
* @Apidoc\Method("POST")
|
|
* @Apidoc\Param("id", type="string", require=true, desc="id")
|
|
* @Apidoc\Param("title", type="string", require=true, desc="名称")
|
|
* @Apidoc\Param("status", type="string", require=true, desc="状态,可选,1,0,默认1")
|
|
*/
|
|
public function update()
|
|
{
|
|
//captcha_verfiy('image','update_address');
|
|
//$trade_password = input('trade_password');
|
|
//\support\Jwt::verify_trade_password($trade_password);
|
|
$data = [
|
|
'id' => input('id',''),
|
|
'title' => input('title',''),
|
|
'status' => input('status',1)
|
|
];
|
|
if(!$data['id']){
|
|
return $this->error(__('Invalid parameters'));
|
|
}
|
|
if(!$data['title']){
|
|
return $this->error(__('Invalid title'));
|
|
}
|
|
$this->model->where('id',$data['id'])->save($data);
|
|
return $this->success(__('successful'));
|
|
}
|
|
/**
|
|
* 详情
|
|
* @Apidoc\Query("id", type="int", require=true, desc="id")
|
|
*/
|
|
public function detail(){
|
|
$id = input('id');
|
|
$vo = $this->model->where('id',$id)->find();
|
|
if($vo) {
|
|
return $this->success(__('successful'),$vo->toArray());
|
|
}else{
|
|
return $this->error(__("Record is not exist"));
|
|
}
|
|
}
|
|
} |