属性名 4=>属性值 * Class SpecManage * @package JinDouYun\Controller\GoodsManage */ class SpecManage extends BaseController { /** * @var MSpec */ private $objMSpec; /** * SpecManage constructor. * @param bool $isCheckAcl * @param bool $isMustLogin * @param bool $checkToken * @param bool $getAreaCode * @throws \Exception */ public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = false) { parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode); $this->objMSpec = new MSpec($this->onlineUserId, $this->onlineEnterpriseId); } /** * 添加和编辑规格 * * @return array */ public function commonFieldFilter() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $data = [ 'specName' => isset($params['specName']) ? $params['specName'] : null, 'pid' => isset($params['pid']) ? $params['pid'] : 0, ]; foreach ($data as $key => $value) { if (empty($value) && $value !== 0) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } $data['hidden'] = isset($params['hidden']) ? $params['hidden'] : StatusCode::$standard;//5 不隐藏 4隐藏 return $data; } /** * 规格管理列表 */ public function getAll() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $result = $this->objMSpec->getAll($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 添加规格 * @param $params */ public function add() { $data = $this->commonFieldFilter(); $result = $this->objMSpec->add($data); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 编辑 */ public function edit() { $id = $this->request->param('request_id'); if (empty($id)) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $data = $this->commonFieldFilter(); $data['id'] = $id; $result = $this->objMSpec->edit($data); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 详情 */ public function info() { $id = $this->request->param('request_id'); if (empty($id)) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $result = $this->objMSpec->info($id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 删除 */ public function del() { $id = $this->request->param('request_id'); if (empty($id)) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $result = $this->objMSpec->del($id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 获取属性名 */ public function getAllSpecName() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $result = $this->objMSpec->getAllSpecName($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * pid => specValue */ public function getAllSpecValByPid() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } if (!isset($params['pid'])){ parent::sendOutput('pid参数错误', ErrorCode::$paramError); } $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['pid'] = $params['pid']; $result = $this->objMSpec->getAllSpecValByPid($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 5 => 隐藏 4=>不隐藏 * 添加自定义属性 */ public function defineSpec() { $data = $this->commonFieldFilter(); $result = $this->objMSpec->defineSpec($data); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } }