123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- /**
- * 素材库Controller
- * Created by PhpStorm.
- * User: 小威
- * Date: 2020/04/27
- * Time: 14:20
- */
- namespace JinDouYun\Controller\Material;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Material\MMaterial;
- class Material extends BaseController
- {
- private $objMMaterial;
- public function __construct($isCheckAcl = false, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMMaterial = new MMaterial($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 素材内容添加
- * @throws Exception
- */
- public function addMaterialContent()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'name' => isset($params['name']) ? $params['name'] : '',
- 'content' => isset($params['content']) ? $params['content'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $this->shopId && $data['shopId'] = $this->shopId;
- $data['categoryId'] = isset($params['categoryId']) ? $params['categoryId'] : 0;
- $result = $this->objMMaterial->addMaterialContent($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 素材分类添加
- * @throws Exception
- */
- public function addMaterialCategory()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $data['pid'] = isset($params['pid']) ? $params['pid'] : 0;
- $this->shopId && $data['shopId'] = $this->shopId;
- $result = $this->objMMaterial->addMaterialCategory($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 素材内容编辑
- * @throws Exception
- */
- public function updateMaterialContent()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
- 'id' => isset($params['id']) ? $params['id'] : '',
- ];
- $result = $this->objMMaterial->updateMaterialContent($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 素材分类编辑
- * @throws Exception
- */
- public function updateMaterialCategory()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- 'id' => isset($params['id']) ? $params['id'] : '',
- ];
- $result = $this->objMMaterial->updateMaterialCategory($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 素材内容删除
- */
- public function delMaterialContent()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- if (!isset($params['id']) || empty($params['id'])) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMMaterial->delMaterialContent($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 素材分类删除
- */
- public function delMaterialCategory()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMMaterial->delMaterialCategory($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 素材分类列表
- */
- public function getAllMaterialCategory()
- {
- $params = [];
- $this->shopId && $params['shopId'] = $this->shopId;
- $result = $this->objMMaterial->getAllMaterialCategory($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 素材内容列表
- */
- public function getAllMaterialContent()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['categoryId'] = isset($params['categoryId']) ? $params['categoryId'] : 0;
- $selectParams['name'] = isset($params['name']) ? $params['name'] : '';
- $this->shopId && $selectParams['shopId'] = $this->shopId;
- $result = $this->objMMaterial->getAllMaterialContent($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- }
|