130 lines
3.9 KiB
PHP
130 lines
3.9 KiB
PHP
<?php
|
|
namespace app\api\controller\v1;
|
|
|
|
use app\api\model\Currency as CurrencyModel;
|
|
use app\api\validate\Currency as CurrencyValidate;
|
|
|
|
/**
|
|
* 货币类
|
|
* Class Currency
|
|
* @package app\api\controller
|
|
*/
|
|
class Currency extends Base
|
|
{
|
|
public function initialize()
|
|
{
|
|
parent::initialize(); // TODO: Change the autogenerated stub
|
|
$this->model = new CurrencyModel();
|
|
$this->validate = new CurrencyValidate();
|
|
}
|
|
|
|
/**
|
|
* 列表
|
|
*/
|
|
public function index(): \think\response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (isset($inputData['status']) && $inputData['status'] != '') {
|
|
$this->focus['status'] = $inputData['status'];
|
|
}
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
|
|
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order,$this->field);
|
|
return $this->msg(200,'获取列表成功',$result);
|
|
}
|
|
|
|
/**
|
|
* 修改
|
|
*/
|
|
public function update():\think\response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
$result = $this->model->editData($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,'更改成功');
|
|
} else {
|
|
return $this->msg(504,'更改失败');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 新增
|
|
*/
|
|
public function create():\think\response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
|
|
$result = $this->model->addData($inputData);
|
|
|
|
if ($result) {
|
|
return $this->msg(200,'新增成功');
|
|
} else {
|
|
return $this->msg(504,'新增失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 启用禁用
|
|
*/
|
|
public function changeStatus():\think\response\Json
|
|
{
|
|
$inputData = $this->request->param(['id','status']);
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
//查找是否有平台使用此币种。
|
|
$data = $this->model->find($inputData['id']);
|
|
$hasPlatformUse = $this->model->getPlatformCoin($inputData['id']);
|
|
if (!$hasPlatformUse || $data['status'] == 1) {
|
|
$result = $this->model->changeStatus($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,"操作成功");
|
|
} else {
|
|
return $this->msg(504,"操作失败");
|
|
}
|
|
} else {
|
|
return $this->msg(504,"有平台使用了此币种,不能进行禁用/启用操作");
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
public function del():\think\response\Json
|
|
{
|
|
$inputData = $this->request->param(['id']);
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
//查找是否有平台使用此币种。
|
|
$hasPlatformUse = $this->model->getPlatformCoin($inputData['id']);
|
|
if (!$hasPlatformUse) {
|
|
$result = $this->model->delData($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,"删除成功");
|
|
} else {
|
|
return $this->msg(504,"删除失败");
|
|
}
|
|
} else {
|
|
return $this->msg(504,"有平台使用此币种,不能进行删除操作");
|
|
}
|
|
|
|
}
|
|
|
|
}
|