123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Gss
- * Date: 2021/4/15 0015
- * Time: 14:48
- */
- namespace JinDouYun\Controller\Goods;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Goods\MGoodsGroups;
- class GoodsGroups extends BaseController
- {
- private $objMGoodsGroups;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMGoodsGroups = new MGoodsGroups($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 获取参数
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- "name" => isset($params['name']) ? $params['name'] : '',
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['explain'] = getArrayItem($params,'explain','');
- $data['sort'] = getArrayItem($params,'sort','');
- return $data;
- }
- /**
- * 商品分组添加
- */
- public function addGoodsGroups()
- {
- $data = $this->commonFieldFilter();
- $data['createTime'] = time();
- $result = $this->objMGoodsGroups->addGoodsGroups($data);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 商品分组删除
- */
- public function deleteGoodsGroups()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $update = [
- 'deleteStatus' => StatusCode::$delete
- ];
- $result = $this->objMGoodsGroups->updateGoodsGroups($update, ['id' => $id]);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 商品分组修改
- */
- public function updateGoodsGroups()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $update = $this->commonFieldFilter();
- $update['updateTime'] = time();
- $result = $this->objMGoodsGroups->updateGoodsGroups($update, ['id' => $id]);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 商品分组启用/禁用
- */
- public function enableGoodsGroups()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $params = $this->request->getRawJson();
- $data = [
- 'status' => isset($params['status']) ? $params['status'] : '',
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMGoodsGroups->updateGoodsGroups($data, ['id' => $id]);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 商品分组列表
- */
- public function getAllGoodsGroups()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['name'] = getArrayItem($params,'name',"");
- $result = $this->objMGoodsGroups->getAllGoodsGroups($selectParams);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * 商品分组详情
- */
- public function getReservoirInfo()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params['id'])) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMGoodsGroups->getReservoirInfo($params);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- }
|