init: 项目初始代码
This commit is contained in:
73
app/api/controller/v1/Attribute.php
Normal file
73
app/api/controller/v1/Attribute.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Attribute as AttributeModel;
|
||||
use app\api\validate\Attribute as AttributeValidate;
|
||||
|
||||
/**
|
||||
* Class Attribute
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Attribute extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new AttributeModel();
|
||||
$this->validate = new AttributeValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
if (isset($inputData['page']) && $inputData['page'] != '') {
|
||||
$this->page = $inputData['page'];
|
||||
}
|
||||
|
||||
if (isset($inputData['size']) && $inputData['size'] != '') {
|
||||
$this->page = $inputData['size'];
|
||||
}
|
||||
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->simple,$this->focus,$this->order,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
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());
|
||||
}
|
||||
$hasGoodsAttr = $this->model->getGoodsAttrById($inputData);
|
||||
|
||||
if (!$hasGoodsAttr) {
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,"此属性有商品引用,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user