123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- <?php
- /**
- * 采购订单
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/11
- * Time: 17:51
- */
- namespace JinDouYun\Controller\Purchase;
- use Exception;
- use JinDouYun\Controller\BaseController;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Model\Purchase\MPurchase;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- class Purchase extends BaseController
- {
- private $objMPurchase;
- /**
- * Purchase constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMPurchase = new MPurchase($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 添加,编辑采购订单
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
- 'buyerId' => isset($params['buyerId']) ? $params['buyerId'] : '',
- 'buyerName' => isset($params['buyerName']) ? $params['buyerName'] : '',
- 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
- 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : '',//采购商品详情json
- 'operatorId' => $this->onlineUserId,
- 'couponAmount' => isset($params['couponAmount']) ? sprintf("%.4f", $params['couponAmount']) : '',
- 'otherAmount' => isset($params['otherAmount']) ? sprintf("%.4f", $params['otherAmount']) : '',
- 'purchaseType' => isset($params['purchaseType']) ? $params['purchaseType'] : StatusCode::$delete,
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- if(isset($params['departmentPath'])){
- $data['extends'] = json_encode(['departmentPath' => $params['departmentPath']]);
- }
- $data['deleteArray'] = isset($params['deleteArray']) ? $params['deleteArray'] : [];//删除的采购商品id
- $goodsData = [];
- foreach ($data['goodsData'] as $key => $val) {
- $goodsData[$key] = [
- 'basicGoodsId' => isset($val['basicGoodsId']) ? $val['basicGoodsId'] : '',
- 'goodsCode' => isset($val['goodsCode']) ? $val['goodsCode'] : '',
- 'goodsName' => isset($val['goodsName']) ? $val['goodsName'] : '',
- 'skuId' => isset($val['skuId']) ? $val['skuId'] : '',
- 'buyerNum' => isset($val['buyerNum']) ? abs($val['buyerNum']) : '',
- 'buyerUnitPrice' => isset($val['buyerUnitPrice']) ? abs($val['buyerUnitPrice']) : '',
- 'subtotalPrice' => isset($val['subtotalPrice']) ? abs($val['subtotalPrice']) : '',
- ];
- foreach ($goodsData[$key] as $k => $v) {
- if (empty($v)) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- if (isset($val['id'])) $goodsData[$key]['id'] = $val['id'];
- $goodsData[$key]['couponAmount'] = isset($val['couponAmount']) ? $val['couponAmount'] : 0;
- $goodsData[$key]['otherAmount'] = isset($val['otherAmount']) ? $val['otherAmount'] : 0;
- $goodsData[$key]['categoryId'] = isset($val['categoryId']) ? $val['categoryId'] : 0;
- $goodsData[$key]['categoryName'] = isset($val['categoryName']) ? $val['categoryName'] : 0;
- $goodsData[$key]['unitName'] = isset($val['unitName']) ? $val['unitName'] : '';
- $goodsData[$key]['skuName'] = isset($val['skuName']) ? $val['skuName'] : '';
- $goodsData[$key]['otherNum'] = isset($val['otherNum']) ? $val['otherNum'] : '';
- }
- $data['goodsData'] = $goodsData;
- $data['remark'] = isset($params['remark']) ? $params['remark'] : null;
- if( $data['purchaseType'] == StatusCode::$standard ){
- $data['merchantId'] = isset($params['merchantId']) ? $params['merchantId'] : 0;
- $data['merchantName'] = isset($params['merchantName']) ? $params['merchantName'] : 0;
- if( empty($data['merchantId']) ){
- parent::sendOutput('merchantId参数错误', ErrorCode::$paramError);
- }
- } else {
- $data['supplierId'] = isset($params['supplierId']) ? $params['supplierId'] : '';
- $data['supplierName'] = isset($params['supplierName']) ? $params['supplierName'] : '';
- if( empty($data['supplierId']) ){
- parent::sendOutput('supplierId参数错误', ErrorCode::$paramError);
- }
- }
- $data['warehouseName'] = isset($params['warehouseName']) ? $params['warehouseName'] : '';
- return $data;
- }
- /**
- * 添加采购订单
- * @throws Exception
- */
- public function addPurchase()
- {
- $data = $this->commonFieldFilter();
- $this->shopId && $data['shopId'] = $this->shopId;
- $result = $this->objMPurchase->addPurchase($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 采购订单信息
- * @throws Exception
- */
- public function getPurchaseInfoById()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMPurchase->getPurchaseInfoById($id);
- if ($result->isSuccess()) {
- $resultData = $result->getData();
- parent::sendOutput($resultData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 采购订单详情和批次数据(采购退货单用)
- * @throws Exception
- */
- public function getPurchaseAndBatchInfoById()
- {
- $params = $this->request->getRawJson();
- $where = [
- 'id' => isset($params['id']) ? $params['id'] : '',
- 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
- ];
- foreach($where as $key => $value){
- if(empty($where)) parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMPurchase->getPurchaseAndBatchInfoById($where);
- if ($result->isSuccess()) {
- $resultData = $result->getData();
- parent::sendOutput($resultData);
- }
- parent::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->objMPurchase->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->objMPurchase->updateAuditStatus($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 删除采购单
- */
- public function delPurchase()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- if (!is_array($id)) {
- $id = [$id];
- }
- $result = $this->objMPurchase->delPurchase($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 采购单列表
- * @throws Exception
- */
- public function getAllPurchase()
- {
- $params = $this->request->getRawJson();
- $page = isset($params['page']) ? $params['page'] : 1;
- $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- (isset($params['deleteStatus']) && !empty($params['deleteStatus'])) && $selectParams['deleteStatus'] = $params['deleteStatus'];
- if(isset($params['returnStatus']) && !empty($params['returnStatus'])){
- $selectParams['returnStatus'] = strpos($params['returnStatus'],',') ? explode(',',$params['returnStatus']) : $params['returnStatus'];
- }
- if(isset($params['inStatus']) && !empty($params['inStatus'])){
- $selectParams['inStatus'] = strpos($params['inStatus'],',') ? explode(',',$params['inStatus']) : $params['inStatus'];
- }
- if (isset($params['warehouseId']) && !empty($params['warehouseId'])) {
- $selectParams['warehouseId'] = $params['warehouseId'];
- }
- if (isset($params['isSelectInventory']) && !empty($params['isSelectInventory'])) {
- $selectParams['isSelectInventory'] = $params['isSelectInventory'];
- }
- $selectParams['purchaseType'] = isset($params['purchaseType']) ? $params['purchaseType'] : 4;
- if (isset($params['merchantId']) && !empty($params['merchantId'])) {
- $selectParams['merchantId'] = $params['merchantId'];
- }
- if (isset($params['keyword']) && !empty($params['keyword'])) {
- $selectParams['no']= substr($params['keyword'],strpos($params['keyword'],'-')+1);
- }
- if (isset($params['auditStatus']) && !empty($params['auditStatus'])) {
- if ($params['auditStatus']) $selectParams['auditStatus']=$params['auditStatus'] ;
- }
- if (isset($params['supplierId']) && !empty($params['supplierId'])) {
- $selectParams['supplierId']= $params['supplierId']; //供应商id
- }
- if (isset($params['buyerId']) && !empty($params['buyerId'])) {
- $selectParams['buyerId']= $params['buyerId']; //采购员id
- }
- !empty($this->shopId) && $selectParams['shopId'] = $this->shopId;
- //判断是否是打印
- $export = isset($params['export']) ? $params['export'] : 0;
- !empty($this->supplierId) && $selectParams['supplierId'] = $this->supplierId;
- if (isset($params['start']) && !empty($params['start'])) {
- $selectParams[] = ['createTime', '>=', $params['start']];
- }
- if (isset($params['end']) && !empty($params['end'])) {
- $selectParams[] = ['createTime', '<=', $params['end']];
- }
- $orderData = $this->objMPurchase->getAllPurchase($selectParams, $export);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- /**
- * 根据采购单查询批次商品sku剩余库存数量
- */
- public function getInventoryBatchNum()
- {
- $id = $this->request->param('request_id');
- if(empty($id)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMPurchase->getInventoryBatchNum($id);
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 采购汇总
- * @throws Exception
- */
- public function getAllPurchaseByFields()
- {
- $params = $this->request->getRawJson();
- $page = $params['page'] ?: 1;
- $pageSize = $params['pageSize'] ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- isset($params['inStatus']) && $selectParams['inStatus'] = $params['inStatus'];
- isset($params['goodsName']) && $selectParams['goodsName'] = $params['goodsName'];
- isset($params['categoryId']) && $selectParams['categoryId'] = $params['categoryId'];
- isset($params['warehouseId']) && $selectParams['warehouseId'] = $params['warehouseId'];
- isset($params['start']) && $selectParams['start'] = $params['start'];
- isset($params['end']) && $selectParams['end'] = $params['end'];
- isset($params['supplierId']) && $selectParams['supplierId'] = $params['supplierId'];//供应商id
- isset($params['buyerId']) && $selectParams['buyerId'] = $params['buyerId'];//采购员id
- isset($params['shopId']) && $selectParams['shopId'] = $params['shopId'];//门店id
- $selectParams['onReturn'] = isset($params['onReturn']) ? $params['onReturn'] : 0;
- $type = isset($params['type']) ? $params['type'] : 0;
- $export = isset($params['export']) ? $params['export'] : 0;
- $orderData = $this->objMPurchase->getAllPurchaseByFields($selectParams, $type ,$export);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- /**
- * 汇总搜索 (暂未使用)
- */
- public function searchAllPurchaseByFields()
- {
- $params = $this->request->getRawJson();
- if( empty($params) ){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $selectParams = [
- 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
- 'inStatus' => isset($params['inStatus']) ? $params['inStatus'] : '',
- 'start' => isset($params['start']) ? $params['start'] : '',
- 'end' => isset($params['end']) ? $params['end'] : '',
- 'search' => isset($params['search']) ? $params['search'] : '',
- ];
- $pageParams = pageToOffset($params['page'] ? : 1, $params['pageSize'] ? : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['onReturn'] = isset($params['onReturn']) ? $params['onReturn'] : 0;
- $type = isset($params['type']) ? $params['type'] : 0;
- $export = isset($params['export']) ? $params['export'] : 0;
- $result = $this->objMPurchase->searchAllPurchaseByFields($selectParams, $type, $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 getAllPurchaseAndDetails()
- {
- $params = $this->request->getRawJson();
- $page = $params['page'] ?: 1;
- $pageSize = $params['pageSize'] ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- (isset($params['orderStatus']) && !empty($params['orderStatus'])) && $selectParams['orderStatus'] = $params['orderStatus'];
- $orderData = $this->objMPurchase->getAllPurchaseAndDetails($selectParams);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- /**
- * 采购明细
- * @throws Exception
- */
- public function getAllPurchaseDetails()
- {
- $params = $this->request->getRawJson();
- $page = $params['page'] ?: 1;
- $pageSize = $params['pageSize'] ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'merchantId' => isset($params['merchantId']) ? $params['merchantId'] : '',
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- $export = isset($params['export']) ? $params['export'] : 0;
-
- if(!empty($this->shopId)){
- $selectParams["shopId"] = $this->shopId;
- }
- $orderData = $this->objMPurchase->getAllPurchaseDetails($selectParams, $export);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- /**
- * 采购明细搜索
- */
- public function searchAllPurchaseDetails()
- {
- $params = $this->request->getRawJson();
- if( empty($params) ){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $selectParams = [
- 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
- 'supplierId' => isset($params['supplierId']) ? $params['supplierId'] : '',
- 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '',
- 'start' => isset($params['start']) ? $params['start'] : '',
- 'end' => isset($params['end']) ? $params['end'] : '',
- 'search' => isset($params['search']) ? $params['search'] : '',
- 'merchantId' => isset($params['merchantId']) ? $params['merchantId'] : '',
- 'shopId'=>isset($params['shopId']) ? $params['shopId'] : '',
- ];
- $pageParams = pageToOffset($params['page'] ? : 1, $params['pageSize'] ? : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $export = isset($params['export']) ? $params['export'] : 0;
- $result = $this->objMPurchase->getAllPurchaseDetails($selectParams, $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 getAllData()
- {
- $modelResult = $this->objMPurchase->getAllData();
- if (!$modelResult->isSuccess()) {
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 采购订单再次入库
- */
- public function reStockIn()
- {
- $purchaseId = $this->request->param('request_id');
- if (empty($purchaseId)){
- parent::sendOutput('purchaseId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMPurchase->reStockIn($purchaseId);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 采购订单直接退款
- */
- public function retMoney()
- {
- $purchaseId = $this->request->param('request_id');
- if (empty($purchaseId)){
- parent::sendOutput('purchaseId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMPurchase->retMoney($purchaseId);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 智能采购列表
- */
- public function getAllOrderPurchase()
- {
- $params = $this->request->getRawJson();
- if( empty($params) ){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $params['no'] = getArrayItem($params,'no',"");
- if( isset($params['no']) || !empty($params['no']) ){
- $tmpSelectParams['no'] = explode('-',$params['no']);
- if(count($tmpSelectParams['no'])==3){
- $params['no'] = $tmpSelectParams['no'][1].'-'.$tmpSelectParams['no'][2];
- }
- }
- $params['customerName'] = getArrayItem($params,'customerName',"");
- $params['payStatus'] = getArrayItem($params,'payStatus',StatusCode::$standard);
- $params['orderStatus'] = getArrayItem($params,'orderStatus',StatusCode::$orderStatus['waitDelivery']);
- $params['auditStatus'] = getArrayItem($params,'auditStatus',StatusCode::$auditStatus['auditPass']);
- $params['start'] = getArrayItem($params,'start',"");
- $params['end'] = getArrayItem($params,'end',"");
- $returnData = $this->objMPurchase->getAllOrderPurchase($params);
- if ($returnData->isSuccess()) {
- $returnData = $returnData->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
- }
- }
- }
|