123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- /**
- * 计量单位
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2020/3/17
- * Time: 16:52
- */
- namespace JinDouYun\Controller\GoodsManage;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\GoodsManage\MUnits;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- class Units extends BaseController
- {
- private $objMUnits;
- /**
- * Units constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMUnits = new MUnits($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 添加和编辑计量单位公共字段
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'unitName' => isset($params['unitName']) ? $params['unitName'] : '',
- 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete
- ];
- foreach ($data as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- return $data;
- }
- /**
- * 添加计量单位
- */
- public function add()
- {
- $data = $this->commonFieldFilter();
- $result = $this->objMUnits->add($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 删除计量单位
- */
- public function del()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMUnits->del($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 更新 启用/禁用状态
- *
- */
- public function updateEnablesStatus()
- {
- $params = $this->request->getRawJson();
- if (empty($params['id']) && empty($params['enableStatus'])) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMUnits->updateEnableStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 编辑计量单位
- */
- public function edit()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $data = $this->commonFieldFilter();
- $data['id'] = $id;
- $result = $this->objMUnits->edit($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取单位列表
- */
- public function getAll()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['enableStatus'] = !empty($params['source']) ? $params['source'] :"";
- $result = $this->objMUnits->getAll($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
|