123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- <?php
- /**
- * 采购退货单数据模型
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/11
- * Time: 17:49
- */
- namespace JinDouYun\Model\Purchase;
- use Exception;
- use JinDouYun\Dao\Merchant\DMerchantApply;
- use JinDouYun\Model\GoodsManage\MSku;
- use JinDouYun\Model\Stock\MInventory;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Model\MBaseModel;
- use JinDouYun\Model\Purchase\MPurchase;
- use JinDouYun\Model\Stock\MWarehouse;
- use JinDouYun\Dao\Purchase\DPurchaseOut;
- use JinDouYun\Dao\Purchase\DPurchaseOutGoods;
- use JinDouYun\Model\Stock\MInventoryOut;
- class MPurchaseOut extends MBaseModel
- {
- private $objDPurchaseOut;
- private $onlineUserId;
- private $onlineEnterpriseId;
- private $objDPurchaseOutGoods;
- private $objDMerchantApply;
- /**
- * MOrder constructor.
- * @param $onlineUserId
- * @param $onlineEnterpriseId
- * @throws Exception
- */
- public function __construct($onlineUserId, $onlineEnterpriseId)
- {
- $this->onlineUserId = $onlineUserId;
- $this->onlineEnterpriseId = $onlineEnterpriseId;
- parent::__construct($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objDPurchaseOut = new DPurchaseOut('stock');
- $this->objDPurchaseOutGoods = new DPurchaseOutGoods('stock');
- $this->objDPurchaseOutGoods->setTable($this->objDPurchaseOutGoods->get_Table() . '_' . $this->onlineEnterpriseId);
- $this->objDPurchaseOut->setTable($this->objDPurchaseOut->get_Table() . '_' . $this->onlineEnterpriseId);
- $this->objDMerchantApply = new DMerchantApply();
- }
- /**
- * 增加采购退货订单
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function addPurchaseOut($params)
- {
- $goodData = $params['goodsData'];
- unset($params['goodsData']);
- $deleteArray = $params['deleteArray'];
- unset($params['deleteArray']);
- $purchaseAmount = 0;
- foreach ($goodData as $key => $val) {
- $purchaseAmount = bcadd($purchaseAmount, $val['subtotalPrice'], 4);
- }
- $params['purchaseAmount'] = $purchaseAmount;//采购总额
- //$params['couponAmount'] = sprintf("%.4f", array_sum(array_column($goodData, 'couponAmount')));//优惠总额
- //$params['otherAmount'] = sprintf("%.4f", array_sum(array_column($goodData, 'otherAmount')));//其他总额
- //添加采购退货退货订单
- // 生成编号
- $dbResult = $this->objDPurchaseOut->get('createTime >='.strtotime(date('Ymd'.'0:0:0')), 'no', 'createTime desc');
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- $params['no'] = createSerialNumberByDate('');
- }else{
- $params['no'] = createSerialNumberByDate($dbResult['no']);
- }
- //$no = createOrderSn(StatusCode::$source['manage'], StatusCode::$orderType['purchaseReturn'], $this->onlineUserId);
- //$params['no'] = $no;
- $params['createTime'] = time();
- $params['updateTime'] = time();
- $objMInventory = new MInventory($this->onlineEnterpriseId, $this->onlineUserId);
- $skuIds = [];
- foreach($goodData as $value){
- $skuIds[] = $value['skuId'];
- }
- //查询仓库库存剩余数量
- $modelResult = $objMInventory->getWarehouseInventoryData($params['warehouseId'], $skuIds);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $inventoryData = $modelResult->getData();
- unset($modelResult);
- if(empty($inventoryData)){
- return ResultWrapper::fail('库存查询失败', ErrorCode::$paramError);
- }
- //查询批次批次剩余数量
- $modelResult = $objMInventory->getBatchDataByOriginId($params['warehouseId'], $params['originId'], $skuIds);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $inventoryBatch = $modelResult->getData();
- unset($modelResult);
- if(empty($inventoryBatch)){
- return ResultWrapper::fail('批次库存查询失败', ErrorCode::$dberror);
- }
- foreach($goodData as $value){
- //判断库存剩余数量
- if(isset($inventoryData[$value['skuId']])){
- if($value['buyerNum'] > $inventoryData[$value['skuId']]['num']){
- return ResultWrapper::fail($value['goodsName'].'库存不足', ErrorCode::$dberror);
- }
- }else{
- return ResultWrapper::fail($value['goodsName'].'库存为空', ErrorCode::$dberror);
- }
- //判断批次剩余数量
- if(isset($inventoryBatch[$value['skuId']])){
- if($value['buyerNum'] > $inventoryBatch[$value['skuId']]['num']){
- return ResultWrapper::fail($value['goodsName'].' 批次库存不足', ErrorCode::$dberror);
- }
- }else{
- return ResultWrapper::fail($value['goodsName'].' 批次库存为空', ErrorCode::$dberror);
- }
- }
- $beginStatus = $this->objDPurchaseOut->beginTransaction();
- $purchaseOutId = $this->objDPurchaseOut->insert($params);
- if ($purchaseOutId === false) {
- $this->objDPurchaseOut->rollBack();
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- foreach ($goodData as $key => &$val) {
- $val['purchaseOutId'] = $purchaseOutId;
- }
- unset($val);
- $objPurchaseGoods = new MPurchaseOutGoods($this->onlineUserId, $this->onlineEnterpriseId);
- $dbResult = $objPurchaseGoods->addPurchaseGoods($goodData);
- if (!$dbResult->isSuccess()) {
- $this->objDPurchaseOut->rollBack();
- return ResultWrapper::fail($dbResult->getData(), ErrorCode::$dberror);
- }
- $beginStatus && $this->objDPurchaseOut->commit();
- return ResultWrapper::success($purchaseOutId);
- }
- /**
- * 采购退货订单详情
- * @param $id
- * @return ResultWrapper
- * @throws Exception
- */
- public function getPurchaseOutInfoById($id)
- {
- $dbResult = $this->objDPurchaseOut->get($id);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::fail('单据不存在', ErrorCode::$paramError);
- }
- $returnData = $dbResult;
- $returnData['type'] = StatusCode::$orderType['purchaseReturn'];
- unset($dbResult);
- $dbResult = $this->objDPurchaseOutGoods->select(['purchaseOutId' => $id, 'deleteStatus' => StatusCode::$standard]);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $skuIds = [];
- foreach($dbResult as $value){
- $skuIds[] = $value['skuId'];
- }
- //查询出采购数量
- $objMPurchaseGoods = new MPurchaseGoods($this->onlineUserId, $this->onlineEnterpriseId);
- $purchaseDetailsWhere = [
- 'purchaseId' => $returnData['originId'],
- 'skuId' => $skuIds
- ];
- $modelResult = $objMPurchaseGoods->getPurchaseGoodsData($purchaseDetailsWhere);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $purchaseGoodsData = $modelResult->getData();
- unset($modelResult);
- //查询库存剩余数量
- $objMPurchase = new MPurchase($this->onlineUserId, $this->onlineEnterpriseId);
- $purchaseWhere = [
- 'id' => $returnData['originId'],
- 'warehouseId' => $returnData['warehouseId'],
- ];
- $modelResult = $objMPurchase->getPurchaseAndBatchInfoById($purchaseWhere);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $batchResult = $modelResult->getData();
- unset($modelResult);
- $batchData = [];
- foreach($batchResult as $value){
- $batchData[$value['skuId']] = $value;
- }
- foreach($dbResult as &$value){
- $value['purchaseNum'] = isset($purchaseGoodsData[$value['skuId']]) ? $purchaseGoodsData[$value['skuId']]['buyerNum'] : 0;
- $value['inNum'] = isset($purchaseGoodsData[$value['skuId']]) ? $purchaseGoodsData[$value['skuId']]['inNum'] : 0;
- $value['inOfNum'] = isset($purchaseGoodsData[$value['skuId']]) ? $purchaseGoodsData[$value['skuId']]['inOfNum'] : 0;
- $value['returnOnNum'] = isset($purchaseGoodsData[$value['skuId']]) ? $purchaseGoodsData[$value['skuId']]['returnOnNum'] : 0;
- $value['returnNum'] = isset($purchaseGoodsData[$value['skuId']]) ? $purchaseGoodsData[$value['skuId']]['returnNum'] : 0;
- $value['inventoryNum'] = isset($batchData[$value['skuId']]) ? $batchData[$value['skuId']]['num'] : 0;
- }
- unset($value);
- $returnData['details'] = $dbResult;
- unset($dbResult);
- $formatResult = self::format($returnData);
- return ResultWrapper::success(empty($formatResult) ? [] : $formatResult[0]);
- }
- /**
- * 编辑采购退货订单
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function editPurchase($params)
- {
- if (empty($params['id'])) {
- return ResultWrapper::fail('id参数为空', ErrorCode::$paramError);
- }
- if( isset($params['no']) ){
- unset($params['no']);
- }
- $id = $params['id'];
- unset($params['id']);
- unset($params['source']);
- $deleteArray = $params['deleteArray'];
- unset($params['deleteArray']);
- $beginStatus = $this->objDPurchaseOut->beginTransaction();
- $goodData = $params['goodsData'];
- unset($params['goodsData']);
- $dbResult = $this->objDPurchaseOut->update($params, $id);
- if ($dbResult === false) {
- $this->objDPurchaseOut->rollBack();
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $objPurchaseOutGoods = new MPurchaseOutGoods($this->onlineUserId, $this->onlineEnterpriseId);
- $modelResult = $objPurchaseOutGoods->editPurchaseOutGoods($goodData, $id, $deleteArray);
- if (!$modelResult->isSuccess()) {
- $this->objDPurchaseOut->rollBack();
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $beginStatus && $this->objDPurchaseOut->commit();
- return ResultWrapper::success($dbResult);
- }
- /**
- * 更新审核状态
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function updateAuditStatus($params)
- {
- $id = $params['id'];
- unset($params['id']);
- $beginStatus = $this->objDPurchaseOut->beginTransaction();
- $dbResult = $this->objDPurchaseOut->update($params, $id);
- if ($dbResult === false) {
- $this->objDPurchaseOut->rollBack();
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $return = $dbResult;
- unset($dbResult);
- $dbResult = $this->objDPurchaseOut->get(['id' => $id]);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $purchaseOutData = $dbResult;
- unset($dbResult);
- $dbResult = $this->objDPurchaseOutGoods->select(['purchaseOutId' => $id]);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $purchaseOutGoodsData = $dbResult;
- //兼容商户
- if($purchaseOutData['purchaseStatus'] == StatusCode::$standard){//商户
- //查询商户信息
- $sql = 'select contactMobile as mobile from qianniao_merchant_apply where id = '.$purchaseOutData['merchantId'] .' and enterpriseId='.$this->onlineEnterpriseId;
- unset($dbResult);
- $dbResult = $this->objDMerchantApply->query($sql);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::fail('供应商信息为空', ErrorCode::$paramError);
- }
- }else{
- //查询供应商信息
- $sql = 'select code,mobile from qianniao_supplier_'.$this->onlineEnterpriseId.' where id = '.$purchaseOutData['supplierId'];
- unset($dbResult);
- $dbResult = $this->objDPurchaseOut->query($sql);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::fail('供应商信息为空', ErrorCode::$paramError);
- }
- }
- $supplierData = array_shift($dbResult);
- unset($dbResult);
- //拼数据加出库
- $outData = [
- 'sourceId' => $purchaseOutData['id'],
- 'sourceNo' => $purchaseOutData['no'],
- 'originNo' => $purchaseOutData['originNo'],
- 'originId' => $purchaseOutData['originId'],
- 'materielNum' => 0,
- 'amount' => $purchaseOutData['purchaseAmount'],
- 'customerId' => $purchaseOutData['supplierId'],//供应商id
- 'customerName' => $purchaseOutData['supplierName'],//供应商名称
- 'customerCode' => $supplierData['code'] ? $supplierData['code'] : '',//供应商编码
- 'customerMobile' => $supplierData['mobile'],//供应商联系方式
- 'operatorId' => $params['auditId'],
- 'operatorName' => $params['auditName'],
- 'remark' => $purchaseOutData['remark'],
- 'source' => StatusCode::$orderType['purchaseReturn'],
- 'type' => StatusCode::$orderType['purchaseReturnOut'],
- 'deleteStatus' => StatusCode::$standard,
- 'auditStatus' => StatusCode::$auditStatus['auditing'],
- 'createTime' => time(),
- 'updateTime' => time(),
- 'orderGoodsData' => [],
- 'shopId' => $purchaseOutData['shopId'],
- 'shopName' => $purchaseOutData['shopName'],
- ];
- $detailsData = [];
- foreach ($purchaseOutGoodsData as $value) {
- $detailsData[$value['skuId']]['num'] = $value['buyerNum'];
- $outData['materielNum']++;
- $details = [
- 'materielId' => $value['goodsId'],
- 'materielName' => $value['goodsName'],
- 'materielCode' => $value['goodsCode'],
- 'outWarehouse' => json_encode([['warehouseId' => $purchaseOutData['warehouseId'], 'num' => $value['buyerNum']]]),
- 'skuId' => $value['skuId'],
- 'unitName' => $value['unitName'],
- 'skuName' => $value['skuName'],
- 'num' => 0,
- 'outNum' => $value['buyerNum'],
- 'otherNum' => $value['otherNum'],
- 'total' => $value['buyerNum'],
- 'unitPrice' => $value['buyerUnitPrice'],
- 'totalPrice' => $value['subtotalPrice'],
- ];
- $outData['orderGoodsData'][] = $details;
- }
- //增加出库单
- $objMInventoryOut = new MInventoryOut($this->onlineEnterpriseId, $this->onlineUserId);
- $modelResult = $objMInventoryOut->addInventoryOut($outData);
- if (!$modelResult->isSuccess()) {
- $this->objDPurchaseOut->rollBack();
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- unset($modelResult);
- //修改采购订单退货状态
- $objMPurchase = new MPurchase($this->onlineUserId, $this->onlineEnterpriseId);
- $modelResult = $objMPurchase->updatePurchaseDetailsReturnStatus($purchaseOutData['originId'], $detailsData);
- if(!$modelResult->isSuccess()){
- $this->objDPurchaseOut->rollBack();
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $beginStatus && $this->objDPurchaseOut->commit();
- return ResultWrapper::success($return);
- }
- /**
- * 删除采购退货单
- * @param $id
- * @return ResultWrapper
- */
- public function delPurchaseOut($id)
- {
- $dbResult = $this->objDPurchaseOut->update(['deleteStatus' => StatusCode::$delete], $id);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- } else {
- return ResultWrapper::success($dbResult);
- }
- }
- /**
- * 采购退货单列表
- * @param $selectParams
- * @param $export
- * @return ResultWrapper
- * @throws Exception
- */
- public function getAllPurchaseOut($selectParams, $export)
- {
- $selectParams = parent::getStaffQueryParams($selectParams, 'buyerId');
- $selectParams = parent::getShopIdQueryParams($selectParams);
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $selectParams['deleteStatus'] = StatusCode::$standard;
- if($export){
- $modelResult = self::export($selectParams);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- exit;
- }
- $dbResult = $this->objDPurchaseOut->select($selectParams, '*', 'createTime desc', $limit, $offset);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $total = $this->objDPurchaseOut->count($selectParams);
- $return = [
- 'data' => self::format($dbResult),
- 'total' => ($total) ? intval($total) : 0,
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 格式化数据
- * @param $data
- * @return array
- * @throws Exception
- */
- public function format($data)
- {
- if (isset($data['id'])) {
- $dimension = $data;
- unset($data);
- $data[] = $dimension;
- }
- $allPurchaseOutIds = [];
- foreach ($data as $key => $val) {
- $allPurchaseOutIds[] = $val['id'];
- $data[$key]['no'] = StatusCode::$noPrefix[4].'-'.$val['no'];
- }
- $objMPurchaseOutGoods = new MPurchaseOutGoods($this->onlineUserId, $this->onlineEnterpriseId);
- $dbResult = $objMPurchaseOutGoods->getGoodsByPurchaseIds($allPurchaseOutIds);
- if (!$dbResult->isSuccess()) {
- return $data;
- }
- $goodsData = $dbResult->getData();
- foreach ($goodsData as $key => $value) {
- $allGoodsData[$value['purchaseId']][] = $value;
- }
- foreach ($data as $key => $value) {
- $data[$key]['goodsData'] = isset($allGoodsData[$value['id']]) ? $allGoodsData[$value['id']] : [];
- }
- return $data;
- }
- /**
- * 根据商铺id查询物料退货记录
- * @param array $shopIds //商铺id
- * @return ResultWrapper
- */
- public function getReturnDataByShopIds(array $shopIds)
- {
- if(empty($shopIds)) return ResultWrapper::success([]);
- $sql = 'SELECT g.goodsId,SUM(g.buyerNum) AS num FROM '.$this->objDPurchaseOut->get_Table().' p LEFT JOIN '.$this->objDPurchaseOutGoods->get_Table().' g ON p.id = g.purchaseOutId WHERE p.auditStatus = '.StatusCode::$auditStatus['auditPass'].' AND p.deleteStatus = '.StatusCode::$standard.' AND g.deleteStatus = '.StatusCode::$standard.' AND p.shopId in('.implode(',', $shopIds).') GROUP BY g.goodsId';
- $dbResult = $this->objDPurchaseOut->query($sql);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $formatData = [];
- foreach($dbResult as $value){
- $formatData[$value['goodsId']] = $value;
- }
- unset($dbResult);
- return ResultWrapper::success($formatData);
- }
- /**
- * 导出方法
- * @param $condition
- * @return ResultWrapper
- */
- public function export($condition)
- {
- $result = $this->objDPurchaseOut->exportSelect($condition,'id,no,originNo,supplierName,purchaseAmount,operatorName,createTime,auditStatus,outStatus');
- if($result === false){
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- $formatIds = [];
- $formatData = [];
- foreach($result as $value){
- $formatData[$value['id']] = $value;
- $formatIds[] = $value['id'];
- }
- $dbResult = $this->objDPurchaseOutGoods->exportSelect(['purchaseOutId' => $formatIds, 'deleteStatus'=> StatusCode::$standard]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDPurchaseOutGoods->error(), ErrorCode::$paramError);
- }
- //导出到本地
- header ( "Content-type:application/vnd.ms-excel" );
- header ( "Content-Disposition:filename=采购退货记录表.csv" );
- header ('Cache-Control: max-age=0');
- $fp = fopen('php://output', 'a');
- $head = ['编号','采购退货单号','供应商','退货金额','采购关联单号','制单人员','制单日期','审核状态','出库状态','商品名称','商品编码','单位','采购数量','采购单价','采购总价'];//定义标题
- foreach ($head as $i => $v) {
- $head[$i] = mb_convert_encoding($v, 'GBK', 'utf-8');//将中文标题转换编码,否则乱码
- }
- fputcsv($fp, $head);
- $limit = 10000;
- $num = 0; //计数器
- foreach ( $dbResult as $value ) { //循环数据
- $num++;
- if($num == $limit){
- ob_flush(); //释放内存
- flush();
- }
- $value = parent::formatOrderMan($this->onlineEnterpriseId, $value);
- $v = $formatData[$value['purchaseOutId']];
- $rows['id'] = isset($v['id']) ? $v['id'] : null;
- $rows['no'] = isset($v['no']) ? $v['no'] : null;
- $rows['supplierName'] = isset($v['supplierName']) ? $v['supplierName'] : null;
- $rows['purchaseAmount'] = isset($v['purchaseAmount']) ? $v['purchaseAmount'] : null;
- $rows['originNo'] = isset($v['originNo']) ? $v['originNo'] : null;
- $rows['operatorName'] = isset($v['operatorName']) ? $v['operatorName'] : null;
- $rows['createTime'] = isset($v['operatorName']) ? date('Y-m-d H:i:s',$v['createTime']) : null;
- $rows['auditStatus'] = isset($v['auditStatus']) ? $v['auditStatus'] == StatusCode::$auditStatus['auditPass'] ? '已审核' : '未审核' : null;
- $rows['outStatus'] = isset($v['outStatus']) ? $v['outStatus'] == StatusCode::$standard ? '已出库' : '未出库' : null;
- $rows['goodsName'] = isset($value['goodsName']) ? $value['goodsName'] : null;
- $rows['goodsCode'] = isset($value['goodsCode']) ? $value['goodsCode'] : null;
- $rows['skuName'] = isset($value['skuName']) ? $value['skuName'] : null;
- $rows['buyerNum'] = isset($value['buyerNum']) ? $value['buyerNum'] : null;
- $rows['buyerUnitPrice'] = isset($value['buyerUnitPrice']) ? $value['buyerUnitPrice'] : null;
- $rows['subtotalPrice'] = isset($value['subtotalPrice']) ? $value['subtotalPrice'] : null;
- foreach ( $rows as $kk => $vv){
- $rs[$kk] = mb_convert_encoding($vv, 'GBK', 'utf-8'); //转译编码
- }
- fputcsv($fp, $rs);
- $rows = [];
- }
- return ResultWrapper::success('成功');
- }
- /**
- * 修改采购退货
- * @param $updateData
- * @param $where
- * @return ResultWrapper
- */
- public function updatePurchaseOutData($updateData, $where)
- {
- $dbResult = $this->objDPurchaseOut->update($updateData, $where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDPurchaseOut->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- }
|