123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- /**
- * 客户类型调价单
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2020/4/8
- * Time: 17:56
- */
- namespace JinDouYun\Controller\Price;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Price\MCustomerTypePriceAdjustment;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- class CustomerTypePriceAdjustment extends BaseController
- {
- private $objMCustomerTypePriceAdjustment;
- /**
- * CustomerPriceAdjustment constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMCustomerTypePriceAdjustment = new MCustomerTypePriceAdjustment($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'] : '',
- 'shopId' => isset($value['shopId']) ? $value['shopId'] : '',
- 'shopName' => isset($value['shopName']) ? $value['shopName'] : '',
- 'salePrice' => isset($value['salePrice']) ? $value['salePrice'] : '',
- 'createTime' => time(),
- 'updateTime' => time(),
- 'deleteStatus' => StatusCode::$standard,
- 'effectiveStatus' => StatusCode::$auditStatus['auditing'],
- 'customerName' => isset($value['customerName']) ? $value['customerName'] : '',
- 'customerType' => isset($value['customerType']) ? $value['customerType'] : '',
- ];
- 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]['startTime'] = isset($value['startTime']) ? $value['startTime'] : '';
- $sheetData[$key]['endTime'] = isset($value['endTime']) ? $value['endTime'] : '';
- $sheetData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $sheetData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']);
- $sheetData[$key]['salePrice'] = json_encode($sheetData[$key]['salePrice']);
- $sheetData[$key]['effective'] = getArrayItem($value,'effective',StatusCode::$delete);
- }
- return $sheetData;
- }
- /**
- * 新增客户调价单
- *
- * @throws \Exception
- */
- public function add()
- {
- $sheetData = self::commonParams();
- $result = $this->objMCustomerTypePriceAdjustment->add($sheetData);
- if ($result->isSuccess()) {
- //调价单生效操作
- $sheetIds = $result->getData();
- foreach ($sheetIds as $key => $id){
- $row = getArrayItem($sheetData,$key,[]);
- if($row['effective'] == StatusCode::$standard){
- $effectiveResult = $this->objMCustomerTypePriceAdjustment->effective($id,$row);
- if (!$effectiveResult->isSuccess()){
- parent::sendOutput($effectiveResult->getData());
- }
- }
- }
- parent::sendOutput($result->getData());
- }
- 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->objMCustomerTypePriceAdjustment->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->objMCustomerTypePriceAdjustment->effective($id, $params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
-
- /**
- * 获取指定商品的最后生效的客户类型调价数据
- */
- public function getCustomerTypePriceByGoodsIds()
- {
- $params['page'] = $this->request->param('page') ?: 1;
- $params['pageSize'] = $this->request->param('pageSize') ?: 10;
- $params['goodsId'] = $this->request->param('goodsId');
- $result = $this->objMCustomerTypePriceAdjustment->getCustomerTypePriceByGoodsIds($params);
- 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());
- }
- }
-
- /**
- * 删除指定商品的最后生效的客户类型调价数据
- */
- public function delCustomerTypePrice()
- {
- $paramsDate = $this->request->getRawJson();
- $params['id'] = $paramsDate['id'];
- $params['skuId'] = $paramsDate['skuId'];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMCustomerTypePriceAdjustment->delCustomerTypePrice($params);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|