123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- /**
- * 系统模版
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/29
- * Time: 15:38
- */
- namespace JinDouYun\Controller\System;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\System\MSystemTemplate;
- class SystemTemplate extends BaseController
- {
- private $objMSystemTemplate;
- /**
- * SystemTemplate constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMSystemTemplate = new MSystemTemplate($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 添加,编辑系统模版
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete;
- return $data;
- }
- /**
- * 添加系统模版
- * @throws \Exception
- */
- public function add()
- {
- $data = $this->commonFieldFilter();
- $result = $this->objMSystemTemplate->add($data);
- 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');
- foreach ($params as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMSystemTemplate->updateEnableStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取模版列表
- */
- public function getAll()
- {
- $page = $this->request->param('page') ?: 1;
- $pageSize = $this->request->param('pageSize') ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- $dbResult = $this->objMSystemTemplate->getAll($selectParams);
- if ($dbResult->isSuccess()) {
- $returnData = $dbResult->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
- }
- /**
- * 编辑系统模版
- */
- public function edit()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $data = $this->commonFieldFilter();
- $data['id'] = $id;
- $result = $this->objMSystemTemplate->edit($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 删除系统模版
- */
- public function del()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- if (!is_array($id)) {
- $id = [$id];
- }
- $result = $this->objMSystemTemplate->del($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
|