123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- /**
- * 区块管理后台
- * Created by PhpStorm.
- * User: QianNiao-C
- * Date: 2019/10/25
- * Time: 11:32
- */
- namespace JinDouYun\Controller\BlockManage;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\BlockManage\MZone;
- class Zone extends BaseController
- {
- public $objMZone;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMZone = new MZone();
- }
- /**
- * 添加,编辑区块接收公共字段
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $zoneFieldData = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- 'zoneData' => isset($params['data']) ? $params['data'] : '',
- ];
- foreach ($zoneFieldData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $zoneFieldData['zoneData'] = json_encode($zoneFieldData['zoneData']);
- return $zoneFieldData;
- }
- /**
- * 添加区块
- */
- public function addZone()
- {
- $zoneData = $this->commonFieldFilter();
- $result = $this->objMZone->addZone($zoneData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 区块启用和禁用
- */
- public function updateEnableStatus()
- {
- $params['id'] = $this->request->param('request_id');
- $params['enableStatus'] = $this->request->param('enableStatus');//5启用 4停用
- foreach ($params as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMZone->updateEnableStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取指定区块信息
- */
- public function getZoneInfoById()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMZone->getZoneInfoById($id);
- if ($result->isSuccess()) {
- $resultData = $result->getData();
- $resultData['zoneData'] = json_decode($resultData['zoneData'], true);
- parent::sendOutput($resultData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 编辑区块信息
- */
- public function editZone()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $zoneData = $this->commonFieldFilter();
- $zoneData['id'] = $id;
- unset($zoneData['createTime']);
- $result = $this->objMZone->editZone($zoneData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取所有区块
- */
- public function getAllZone()
- {
- $page = $this->request->param('page') ?: 1;
- $pageSize = $this->request->param('pageSize') ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- $result = $this->objMZone->getAllZone($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);
- }
- }
|