objMElement = new MElement(); } /** * 添加,编辑元素接收公共字段 * * @return array */ public function commonFieldFilter() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $elementFieldData = [ 'elementData' => isset($params['data']) ? $params['data'] : '',//字段数据 ]; foreach ($elementFieldData as $key => $value) { if (empty($value) && $value !== 0) { $this->sendOutput($key . '参数错误', ErrorCode::$paramError); } } $elementFieldData['startTime'] = isset($params['startTime']) ? $params['startTime'] : 0; $elementFieldData['endTime'] = isset($params['endTime']) ? $params['endTime'] : 0; $elementFieldData['sort'] = isset($params['sort']) ? $params['sort'] : 0; $elementFieldData['elementData'] = json_encode($elementFieldData['elementData']); return $elementFieldData; } /** * 添加区块下元素 */ public function addElement() { $zoneId = $this->request->param('zoneId'); if (empty($zoneId)) { $this->sendOutput('请指定zoneId', ErrorCode::$paramError); } $elementFieldData = $this->commonFieldFilter(); $elementFieldData['zoneId'] = $zoneId; $result = $this->objMElement->addElement($elementFieldData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 获取指定元素信息 */ public function getElementInfoById() { $id = $this->request->param('request_id'); if (!$id) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $result = $this->objMElement->getElementInfoById($id); if ($result->isSuccess()) { $resultData = $result->getData(); $resultData['elementData'] = json_decode($resultData['elementData'], true); $this->sendOutput($resultData); } $this->sendOutput($result->getData(), $result->getErrorCode()); } /** * 编辑指定元素信息 */ public function editElement() { $id = $this->request->param('request_id'); if (empty($id)) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $elementData = $this->commonFieldFilter(); $elementData['id'] = $id; unset($elementData['createTime']); $result = $this->objMElement->editElement($elementData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 删除指定元素 */ public function delElement() { $id = $this->request->param('request_id'); if (!$id) { $this->sendOutput('参数错误', ErrorCode::$paramError); } if (!is_array($id)) { $id = [$id]; } $result = $this->objMElement->delElement($id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 获取指定区块下的所有元素 */ public function getElementByZoneId() { $zoneId = $this->request->param('request_id'); if (empty($zoneId)) { $this->sendOutput('请指定zoneId', ErrorCode::$paramError); } $page = $this->request->param('page') ?: 1; $pageSize = $this->request->param('pageSize') ?: 10; $offset = ($page - 1) * $pageSize; $selectParams = [ 'limit' => $pageSize, 'offset' => $offset, 'zoneId' => $zoneId, 'type' => 'all',//后台用获取所有数据 ]; $result = $this->objMElement->getElementByZoneId($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $page, 'pageSize' => $pageSize, 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($result->getData(), ErrorCode::$dberror); } }