123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- /**
- * 调价单管理
- * Created by PhpStorm.
- * User: xiaoming
- * Date: 2019/4/16
- * Time: 9:41 AM
- */
- namespace JinDouYun\Controller\Price;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Price\MPriceAdjustment;
- class PriceAdjustment extends BaseController
- {
- private $objMPriceAdjustment;
- /**
- * PriceAdjustment constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMPriceAdjustment = new MPriceAdjustment($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 公共接收参数方法
- * @return mixed
- */
- public function commonParams()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $sheetData = [];
- foreach ($params as $key => $value) {
- $sheetData[$key] = [
- 'createUserId' => $this->onlineUserId,
- 'createUserName' => isset($value['createUserName']) ? $value['createUserName'] : '',
- 'goodsName' => isset($value['goodsName']) ? $value['goodsName'] : '',
- 'goodsId' => isset($value['goodsId']) ? $value['goodsId'] : '',
- 'saleType' => isset($value['saleType']) ? $value['saleType'] : '', // 销售类型
- 'salePriceAreaType' => isset($value['salePriceAreaType']) ? $value['salePriceAreaType'] : '', // 销售价格生效区域类型
- 'salePriceType' => isset($value['salePriceType']) ? $value['salePriceType'] : '', // 价格类型
- 'salePrice' => isset($value['salePrice']) ? $value['salePrice'] : '', // 销售价
- 'shopId' => isset($value['shopId']) ? $value['shopId'] : '',
- 'shopName' => isset($value['shopName']) ? $value['shopName'] : '',
- 'createTime' => time(),
- 'updateTime' => time(),
- 'deleteStatus' => StatusCode::$standard,
- 'effectiveStatus' => StatusCode::$auditStatus['auditing'],
- ];
- foreach ($sheetData[$key] as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $sheetData[$key]['createTime'] = time();
- $sheetData[$key]['updateTime'] = time();
- $sheetData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $sheetData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']);
- $sheetData[$key]['salePrice'] = json_encode($sheetData[$key]['salePrice']);
- }
- return $sheetData;
- }
- /**
- * 新增调价单
- */
- public function add()
- {
- $sheetData = self::commonParams();
- $result = $this->objMPriceAdjustment->add($sheetData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 所有调价单列表
- */
- public function getAll()
- {
- $params['page'] = $this->request->param('page') ?: 1;
- $params['pageSize'] = $this->request->param('pageSize') ?: 10;
- $params['startTime'] = $this->request->param('startTime');
- $params['endTime'] = $this->request->param('endTime');
- $params['effectiveStatus'] = $this->request->param('effectiveStatus');
- $params['keyword'] = $this->request->param('keyword');
- $params['goodsId'] = $this->request->param('goodsId');
- $export = $this->request->param('export');
- if (isset($this->shopId) && !empty($this->shopId)) $params['shopId'] = $this->shopId;
- $result = $this->objMPriceAdjustment->getAll($params,$export);
- 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(), $result->getErrorCode());
- }
- }
- /**
- * 生效操作
- * @throws \Exception
- */
- public function effective()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- parent::sendOutput('请指定要生效的数据id', ErrorCode::$paramError);
- }
- $paramsData = $this->request->getRawJson();
- $params = [
- 'createTime' => isset($paramsData['createTime']) ? $paramsData['createTime'] : '',
- 'effectiveUserName' => isset($paramsData['effectiveUserName']) ? $paramsData['effectiveUserName'] : '',
- 'effectiveUserId' => $this->onlineUserId,
- ];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMPriceAdjustment->effective($id, $params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 自动创建调价单且自动生效接口
- */
- public function addAndEffective()
- {
- $sheetData = self::commonParams();
- $result = $this->objMPriceAdjustment->addAndEffective($sheetData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 商品调价单搜索
- */
- public function search()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [
- 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',//订单编号,收货人,商品名称
- 'startTime' => isset($params['startTime']) ? $params['startTime'] : '',//开始时间
- 'endTime' => isset($params['endTime']) ? $params['endTime'] : '',//结束时间
- 'effectiveStatus' => isset($params['effectiveStatus']) ? $params['effectiveStatus'] : '',//生效状态
- ];
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
- $result = $this->objMPriceAdjustment->search($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|