123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- /**
- * 商品品牌
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/5
- * Time: 11:25
- */
- namespace JinDouYun\Controller\GoodsManage;
- use JinDouYun\Controller\BaseController;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Model\GoodsManage\MGoodsBrand;
- class GoodsBrand extends BaseController
- {
- private $objMGoodsBrand;
- /**
- * GoodsBrand constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMGoodsBrand = new MGoodsBrand($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 添加和编辑商品品牌
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $goodsBrandData = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- ];
- foreach ($goodsBrandData as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $goodsBrandData['supplier'] = isset($params['supplier']) ? $params['supplier'] : '';
- $goodsBrandData['images'] = isset($params['images']) ? $params['images'] : null;
- $goodsBrandData['sort'] = isset($params['sort']) ? $params['sort'] : 0;
- $goodsBrandData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;
- $goodsBrandData['createTime'] = time();
- $goodsBrandData['updateTime'] = time();
- return $goodsBrandData;
- }
- /**
- * 添加商品品牌
- * @throws \Exception
- */
- public function addBrand()
- {
- $brandData = $this->commonFieldFilter();
- $result = $this->objMGoodsBrand->addBrand($brandData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 编辑品牌信息
- * @throws \Exception
- */
- public function editBrand()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $brandData = $this->commonFieldFilter();
- $brandData['id'] = $id;
- unset($brandData['createTime']);
- $result = $this->objMGoodsBrand->editBrand($brandData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取指定id的品牌详情
- * @throws \Exception
- */
- public function getBrandInfoById()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMGoodsBrand->getBrandInfoById($id);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- }
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 品牌的显示和隐藏
- * @throws \Exception
- */
- public function updateBrandStatus()
- {
- $params['id'] = $this->request->param('request_id');
- $params['enableStatus'] = $this->request->param('enableStatus');//4禁用 5启用
- foreach ($params as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMGoodsBrand->updateBrandStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取所有品牌
- * @throws \Exception
- */
- public function getAllBrand()
- {
- $page = $this->request->param('page') ? $this->request->param('page') : 1;
- $pageSize = $this->request->param('pageSize') ? $this->request->param('pageSize') : 10;
- $keyword = $this->request->param('keyword') ? $this->request->param('keyword') : '';
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- if (!empty($keyword)) {
- $selectParams['keyword'] = $keyword;
- }
- $reportData = $this->objMGoodsBrand->getAllBrand($selectParams);
- if ($reportData->isSuccess()) {
- $returnData = $reportData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($reportData->getData(), ErrorCode::$dberror);
- }
- /**
- * 删除分类
- * @throws \Exception
- */
- public function delBrand()
- {
- $brandId = $this->request->param('request_id');
- if (!$brandId) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- if (!is_array($brandId)) {
- $brandId = [$brandId];
- }
- $result = $this->objMGoodsBrand->delBrand($brandId);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
|