123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <?php
- /**
- * 采购退货订单
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/11
- * Time: 17:51
- */
- namespace JinDouYun\Controller\Purchase;
- use JinDouYun\Controller\BaseController;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Model\Purchase\MPurchaseOut;
- class PurchaseOut extends BaseController
- {
- private $objMPurchaseOut;
- /**
- * Purchase constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMPurchaseOut = new MPurchaseOut($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 添加,编辑采购退货订单
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'originId' => isset($params['originId']) ? $params['originId'] : '',
- 'originNo' => isset($params['originNo']) ? $params['originNo'] : '',
- 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
- 'warehouseName' => isset($params['warehouseName']) ? $params['warehouseName'] : '',
- 'buyerId' => isset($params['buyerId']) ? $params['buyerId'] : '',
- 'buyerName' => isset($params['buyerName']) ? $params['buyerName'] : '',
- 'operatorId' => $this->onlineUserId,
- 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
- 'couponAmount' => isset($params['couponAmount']) ? sprintf("%.4f", $params['couponAmount']) : '',
- 'otherAmount' => isset($params['otherAmount']) ? sprintf("%.4f", $params['otherAmount']) : '',
- ];
- $data['goodsData'] = [];
- foreach($params['goodsData'] as $value){
- $goodsData = [
- 'goodsId' => isset($value['goodsId']) ? $value['goodsId'] : '',
- 'skuId' => isset($value['skuId']) ? $value['skuId'] : '',
- 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
- 'skuName' => isset($value['skuName']) ? $value['skuName'] : '',
- 'goodsCode' => isset($value['goodsCode']) ? $value['goodsCode'] : '',
- 'goodsName' => isset($value['goodsName']) ? $value['goodsName'] : '',
- 'buyerNum' => isset($value['buyerNum']) ? abs($value['buyerNum']) : '',
- 'otherNum' => isset($value['otherNum']) ? abs($value['otherNum']) : '',
- 'buyerUnitPrice' => isset($value['buyerUnitPrice']) ? $value['buyerUnitPrice'] : '',
- 'subtotalPrice' => isset($value['subtotalPrice']) ? $value['subtotalPrice'] : '',
- 'couponAmount' => isset($value['couponAmount']) ? $value['couponAmount'] : '',
- 'otherAmount' => isset($value['otherAmount']) ? $value['otherAmount'] : '',
- ];
- if($value['buyerNum'] < 0){
- parent::sendOutput('退货数量参数错误', ErrorCode::$paramError);
- }
- isset($value['id']) && $goodsData['id'] = $value['id'];
- $data['goodsData'][] = $goodsData;
- }
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['supplierId'] = isset($params['supplierId']) ? $params['supplierId'] : 0;
- $data['supplierName'] = isset($params['supplierName']) ? $params['supplierName'] : '';
- $data['merchantId'] = isset($params['merchantId']) ? $params['merchantId'] : 0;
- $data['merchantName'] = isset($params['merchantName']) ? $params['merchantName'] : '';
- $data['purchaseStatus'] = getArrayItem($params, 'purchaseStatus', 4);
- $data['deleteArray'] = isset($params['deleteArray']) ? $params['deleteArray'] : [];
- $data['remark'] = isset($params['remark']) ? $params['remark'] : null;
- return $data;
- }
- /**
- * 添加采购退货订单
- * @throws \Exception
- */
- public function addPurchaseOut()
- {
- $data = $this->commonFieldFilter();
- $result = $this->objMPurchaseOut->addPurchaseOut($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 采购退货信息
- * @throws \Exception
- */
- public function getPurchaseOutInfoById()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMPurchaseOut->getPurchaseOutInfoById($id);
- if ($result->isSuccess()) {
- $resultData = $result->getData();
- $this->sendOutput($resultData);
- }
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 编辑采购退货
- * @throws \Exception
- */
- public function editPurchase()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $data = $this->commonFieldFilter();
- $data['id'] = $id;
- $result = $this->objMPurchaseOut->editPurchase($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 更新审核状态
- */
- public function updateAuditStatus()
- {
- $id = $this->request->param('request_id');
- $params = $this->request->getRawJson();
- $data = [
- 'id' => $id,
- 'auditStatus' => $params['auditStatus'],
- 'auditName' => $params['auditName'],
- 'auditId' => $this->onlineUserId,
- 'auditTime' => time(),
- ];
- foreach ($data as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMPurchaseOut->updateAuditStatus($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 删除采购退货
- */
- public function delPurchaseOut()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- if (!is_array($id)) {
- $id = [$id];
- }
- $result = $this->objMPurchaseOut->delPurchaseOut($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 采购退货列表
- * @throws \Exception
- */
- public function getAllPurchaseOut()
- {
- $params = $this->request->getRawJson();
- $page = $params['page'] ?: 1;
- $pageSize = $params['pageSize'] ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- if(isset($params['auditStatus']) && !empty($params['auditStatus'])) $selectParams['auditStatus'] = $params['auditStatus'];
- if(isset($params['sourceNo']) && !empty($params['sourceNo'])) $selectParams['no'] = $params['sourceNo'];
- if(isset($params['shopId']) && !empty($params['shopId'])) $selectParams['shopId'] = $params['shopId'];
- if(isset($params['purchaseStatus']) && !empty($params['purchaseStatus'])) $selectParams['purchaseStatus'] = $params['purchaseStatus'];
- //判断是否是打印
- $export = isset($params['export']) ? $params['export'] : 0;
- $orderData = $this->objMPurchaseOut->getAllPurchaseOut($selectParams, $export);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- }
- }
|