123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- /**
- * 元素管理
- * Created by PhpStorm.
- * User: QianNiao-C
- * Date: 2019/10/25
- * Time: 14:56
- */
- namespace JinDouYun\Controller\BlockManage;
- use JinDouYun\Controller\BaseController;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Model\BlockManage\MElement;
- class Element extends BaseController
- {
- public $objMElement;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->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);
- }
- }
|