20240120-ljl-routeConfig
parent
7b148c25b8
commit
06d0651dea
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Service\Order\OrderMergeService;
|
||||
use Service\Order\OrderPrintService;
|
||||
use Service\Order\OrderService;
|
||||
|
||||
class LogisticsController extends AbstractApiController {
|
||||
private $orderPrintService;
|
||||
private $orderService;
|
||||
private $orderMergeService;
|
||||
|
||||
public function __construct($route) {
|
||||
parent::__construct($route);
|
||||
$this->orderService = OrderService::instance();
|
||||
$this->orderPrintService = OrderPrintService::instance();
|
||||
$this->orderMergeService = OrderMergeService::instance();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class FulfillmentOrderCollectLogDao extends AbstractDao {
|
||||
public function getByFulfillmentOrderId($fulfillmentOrderId) {
|
||||
return $this->queryFirstRow('select * from %b where fulfillment_order_id = %i', $this->getTable(), $fulfillmentOrderId);
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
use FulfillmentOrderConst;
|
||||
use ZcArrayHelper;
|
||||
|
||||
class FulfillmentOrderDao extends AbstractDao {
|
||||
public function searchPage($mallId, $filter, $page, $pageSize) {
|
||||
$mallIds = $filter['authMallIds'] ? $filter['authMallIds'] : array($mallId);
|
||||
list($whereArr, $joinTables) = $this->getSearchOrderCondition($filter, $mallIds);
|
||||
$whereStr = !empty($whereArr) ? implode(' ', $whereArr) : '';
|
||||
$joinStr = !empty($joinTables) ? implode(' ', $joinTables) : '';
|
||||
|
||||
$orderByQuery = $this->getOrderByQueryString($filter['sortType']);
|
||||
return $this->queryPage("SELECT fo.* FROM %b fo %l WHERE fo.mall_id in %li %l %l", $this->getTable(), $joinStr, $mallIds, $whereStr, $orderByQuery, $page, $pageSize);
|
||||
}
|
||||
|
||||
private function getSearchOrderCondition($filter, $mallIds) {
|
||||
$foeTbl = FulfillmentOrderExtDao::tableName();
|
||||
$whereConditions = [];
|
||||
$joinTables = [];
|
||||
|
||||
if ($filter['fulfillmentStatus']) {
|
||||
$whereConditions[] = $this->prepare('and fo.fulfillment_status = %i', $filter['fulfillmentStatus']);
|
||||
}
|
||||
|
||||
if (!empty($filter['fulfillmentSn'])) {
|
||||
$orderSns = is_array($filter['orderSn']) ? $filter['orderSn'] : array($filter['orderSn']);
|
||||
$whereConditions[] = $this->prepare('and fo.fulfillment_sn in %ls', $orderSns);
|
||||
}
|
||||
|
||||
if (!empty($filter['orderStartTime'])) {
|
||||
$whereConditions[] = $this->prepare('and fo.confirm_time >= %s', $filter['orderStartTime']);
|
||||
}
|
||||
|
||||
if (!empty($filter['orderEndTime'])) {
|
||||
$whereConditions[] = $this->prepare('and fo.confirm_time <= %s', $filter['orderEndTime']);
|
||||
}
|
||||
|
||||
if ($filter['goodsId']) {
|
||||
$filter['goodsId'] = is_array($filter['goodsId']) ? $filter['goodsId'] : [$filter['goodsId']];
|
||||
$whereConditions[] = $this->prepare('and fo.goods_id in %li', $filter['goodsId']);
|
||||
}
|
||||
|
||||
if ($filter['goodsName']) {
|
||||
$whereConditions[] = $this->prepare('and fo.goods_name like %ss', $filter['goodsName']);
|
||||
}
|
||||
|
||||
if ($filter['sellerNote']) {
|
||||
$whereConditions[] = $this->prepare('and fo.seller_note like %ss', $filter['sellerNote']);
|
||||
}
|
||||
|
||||
if ($filter['promiseDeliveryTimeFilter']) {
|
||||
if ($filter['promiseDeliveryTimeFilter'] == FulfillmentOrderConst::promiseDeliverTimeOvertime) {
|
||||
$whereConditions[] = $this->prepare('and fo.promise_delivery_time < %s', date('Y-m-d H:i:s'));
|
||||
} elseif (in_array($filter['promiseDeliveryTimeFilter'], [FulfillmentOrderConst::promiseDeliverTimeOneDay, FulfillmentOrderConst::promiseDeliverTimeTwoDay, FulfillmentOrderConst::promiseDeliverTimeThreeDay])) {
|
||||
$promiseDeliverTime = date('Y-m-d H:i:s', strtotime("+{$filter['promiseDeliveryTimeFilter']} hours"));
|
||||
$whereConditions[] = $this->prepare('and fo.promise_delivery_time > %s and fo.promise_delivery_time < %s', date('Y-m-d H:i:s'), $promiseDeliverTime);
|
||||
}
|
||||
}
|
||||
|
||||
if ($filter['goodsLabelCodePrintFilter'] == FulfillmentOrderConst::goodsLabelCodePrinted) {
|
||||
$joinTables[$foeTbl] = $this->prepare('left join %b foe on fo.fulfillment_sn = foe.fulfillment_sn', $foeTbl);
|
||||
$whereConditions[] = $this->prepare('and foe.filter_goods_label_code_printed = 1');
|
||||
} elseif ($filter['goodsLabelCodePrintFilter'] == FulfillmentOrderConst::goodsLabelCodeNoPrinted) {
|
||||
$joinTables[$foeTbl] = $this->prepare('left join %b foe on fo.fulfillment_sn = foe.fulfillment_sn', $foeTbl);
|
||||
$whereConditions[] = $this->prepare('and foe.filter_goods_label_code_printed = 0 or foe.filter_goods_label_code_printed is null');
|
||||
}
|
||||
|
||||
return [$whereConditions, $joinTables];
|
||||
}
|
||||
|
||||
public function getOrderByQueryString($sortType) {
|
||||
switch ($sortType) {
|
||||
case 'orderConfirmTimeDesc':
|
||||
$query = 'order by fo.`confirm_time` desc';
|
||||
break;
|
||||
case 'orderConfirmTimeAsc':
|
||||
$query = 'order by fo.`confirm_time` asc';
|
||||
break;
|
||||
case 'promiseDeliveryTimeDesc':
|
||||
$query = 'order by fo.`promise_delivery_time` desc';
|
||||
break;
|
||||
case 'promiseDeliveryTimeAsc':
|
||||
$query = 'order by fo.`promise_delivery_time` asc';
|
||||
break;
|
||||
default:
|
||||
$query = 'order by fo.`confirm_time` desc';
|
||||
break;
|
||||
}
|
||||
return empty($query) ? '' : $query;
|
||||
}
|
||||
|
||||
public function getStatusAndOrderCountMap($mallIds) {
|
||||
$orderStatusAndOrderCountMap = $this->query('select fulfillment_status, count(*) as order_count from %b WHERE mall_id in %li group by fulfillment_status', $this->getTable(), $mallIds);
|
||||
return ZcArrayHelper::mapNameValue($orderStatusAndOrderCountMap, 'fulfillmentStatus', 'orderCount');
|
||||
}
|
||||
|
||||
public function getWillDelaySendOrderCount($mallIds) {
|
||||
return $this->queryFirstField('select count(*) from %b where mall_id in %li and fulfillment_status = %i and promise_delivery_time > %s and promise_delivery_time < %s', $this->getTable(), $mallIds, FulfillmentOrderConst::fulfillmentOrderStatusWaitSellerSendGoods, date('Y-m-d H:i:s'), date('Y-m-d H:i:s', strtotime("+24 hours")));
|
||||
}
|
||||
|
||||
public function getHasDelaySendOrderCount($mallIds) {
|
||||
return $this->queryFirstField('select count(*) from %b where mall_id in %li and fulfillment_status = %i and promise_delivery_time < %s', $this->getTable(), $mallIds, FulfillmentOrderConst::fulfillmentOrderStatusWaitSellerSendGoods, date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function getCourierCollectOrderCount($mallIds) {
|
||||
return $this->queryFirstField('select count(*) from %b where mall_id in %li and courier_door_to_door_collect = 1', $this->getTable(), $mallIds);
|
||||
}
|
||||
|
||||
public function getByFulfillmentSn($fulfillmentSn) {
|
||||
return $this->queryFirstRow('select * FROM %b WHERE fulfillment_sn = %s', $this->getTable(), $fulfillmentSn);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class FulfillmentOrderEncryptDao extends AbstractDao {
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class FulfillmentOrderExtDao extends AbstractDao {
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class FulfillmentOrderGoodsLabelCodeDao extends AbstractDao {
|
||||
public function getByFulfillmentSn($fulfillmentSn) {
|
||||
if (empty($fulfillmentSn)) {
|
||||
return null;
|
||||
}
|
||||
return $this->queryFirstRow('select * from %b where fulfillment_sn = %s', $this->getTable(), $fulfillmentSn);
|
||||
}
|
||||
|
||||
public function searchPage($mallId, $filter, $page, $pageSize) {
|
||||
$mallIds = !empty($filter['authMallIds']) ? (is_array($filter['authMallIds']) ? $filter['authMallIds'] : [$filter['authMallIds']]) : [$mallId];
|
||||
$where = $this->getSearchLogWhere($filter);
|
||||
return $this->queryPage("SELECT * FROM %b WHERE `mall_id` IN %li and is_preview != 1 %l ORDER BY `op_print_goods_label_code_log_id` DESC", $this->getTable(), $mallIds, $where, $page, $pageSize);
|
||||
}
|
||||
|
||||
private function getSearchLogWhere($filter) {
|
||||
$whereArray = array();
|
||||
if ($filter['startTime']) {
|
||||
$whereArray[] = $this->prepare('and gmt_create >= %s', $filter['startTime']);
|
||||
}
|
||||
if ($filter['endTime']) {
|
||||
$whereArray[] = $this->prepare('and gmt_create <= %s', $filter['endTime']);
|
||||
}
|
||||
if ($filter['fulfillmentSn']) {
|
||||
$whereArray[] = $this->prepare('and fulfillment_sn in %ls', $filter['fulfillmentSn']);
|
||||
}
|
||||
if ($filter['logisticsId']) {
|
||||
$whereArray[] = $this->prepare('and logistics_id = %s', $filter['logisticsId']);
|
||||
}
|
||||
if ($filter['waybillCode']) {
|
||||
$whereArray[] = $this->prepare('and waybill_code = %s', $filter['waybillCode']);
|
||||
}
|
||||
if ($filter['waybillCodes']) {
|
||||
$whereArray[] = $this->prepare('and express_no in %ls', $filter['waybillCodes']);
|
||||
}
|
||||
if($filter['status']) {
|
||||
$whereArray[] = $this->prepare('and status = %s', $filter['status']);
|
||||
}
|
||||
$where = implode(' ', $whereArray);
|
||||
return $where;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
use ZcArrayHelper;
|
||||
|
||||
class FulfillmentOrderInsensitiveInfoDao extends AbstractDao {
|
||||
public function getFulfillmentOrderIdAndReceiverInfoMap($fulfillmentOrderIds) {
|
||||
$encryptTbl = FulfillmentOrderEncryptDao::tableName();
|
||||
$rows = $this->query('select foe.*, foii.receiver_name, foii.receiver_phone, foii.receiver_address from %b foii left join %b foe on foii.fulfillment_order_id = foe.fulfillment_order_id where foii.fulfillment_order_id in %li', $this->getTable(), $encryptTbl, $fulfillmentOrderIds);
|
||||
return ZcArrayHelper::changeKeyRow($rows, 'fulfillmentOrderId');
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class FulfillmentOrderOutstorageHistoryDao extends AbstractDao {
|
||||
public function searchPage($mallId, $filter, $page, $pageSize) {
|
||||
$mallIds = !empty($filter['authMallIds']) ? (is_array($filter['authMallIds']) ? $filter['authMallIds'] : [$filter['authMallIds']]) : [$mallId];
|
||||
$where = $this->getSearchLogWhere($filter);
|
||||
return $this->queryPage("SELECT * FROM %b WHERE `mall_id` IN %li %l ORDER BY `fulfillment_order_outstorage_history_id` DESC", $this->getTable(), $mallIds, $where, $page, $pageSize);
|
||||
}
|
||||
|
||||
private function getSearchLogWhere($filter) {
|
||||
$whereArray = [];
|
||||
if ($filter['startTime']) {
|
||||
$whereArray[] = $this->prepare('and gmt_create >= %s', $filter['startTime']);
|
||||
}
|
||||
if ($filter['endTime']) {
|
||||
$whereArray[] = $this->prepare('and gmt_create <= %s', $filter['endTime']);
|
||||
}
|
||||
if ($filter['fulfillmentSn']) {
|
||||
$whereArray[] = $this->prepare('and fulfillment_sn in %ls', $filter['fulfillmentSn']);
|
||||
}
|
||||
if ($filter['logisticsId']) {
|
||||
$whereArray[] = $this->prepare('and logistics_id = %s', $filter['logisticsId']);
|
||||
}
|
||||
if ($filter['waybillCode']) {
|
||||
$whereArray[] = $this->prepare('and waybill_code = %s', $filter['waybillCode']);
|
||||
}
|
||||
if ($filter['waybillCodes']) {
|
||||
$whereArray[] = $this->prepare('and express_no in %ls', $filter['waybillCodes']);
|
||||
}
|
||||
if($filter['status']) {
|
||||
$whereArray[] = $this->prepare('and status = %s', $filter['status']);
|
||||
}
|
||||
$where = implode(' ', $whereArray);
|
||||
return $where;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class FulfillmentOrderOutstorageStopDao extends AbstractDao {
|
||||
public function getByFulfillmentSn($mallId, $fulfillmentSn) {
|
||||
return $this->queryFirstRow('select * from %b where mall_id = %i and fulfillment_sn = %s ', $this->getTable(), $mallId, $fulfillmentSn);
|
||||
}
|
||||
|
||||
public function add($mallId, $fulfillmentSn, $reason) {
|
||||
return $this->insert(array(
|
||||
'mall_id' => $mallId,
|
||||
'fulfillment_sn' => $fulfillmentSn,
|
||||
'reason' => $reason,
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class OpPrintGoodsLabelCodeLogDao extends AbstractDao {
|
||||
protected $hasGmtModified = false;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\FulfillmentOrder;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
use OrderPrintTool;
|
||||
|
||||
class OpSysFulfillmentGoodsLabelCodeTplDao extends AbstractDao {
|
||||
public function getDefault() {
|
||||
$row = $this->queryFirstRow('select * from %b where is_default = 1', $this->getTable());
|
||||
if (empty($row)) {
|
||||
return null;
|
||||
}
|
||||
$row['globalStyle'] = unserialize($row['globalStyle']);
|
||||
$row['positionMap'] = unserialize($row['positionMap']);
|
||||
foreach ($row['positionMap'] as &$item) {
|
||||
if ($item['nv']['field'] == 'image' || $item['nv']['field'] == 'logo') {
|
||||
$item['nv']['imgSrc'] = OrderPrintTool::opPubAbsUrl($item['nv']['imgPath']);
|
||||
}
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\Order;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class OpOrderLogisticsTraceDao extends AbstractDao {
|
||||
public function getLogisticsAndTraceListMap($logisticsIds , $expressNos) {
|
||||
$logisticsIds = array_unique(array_filter($logisticsIds));
|
||||
$expressNos = array_unique(array_filter($expressNos));
|
||||
if (empty($logisticsIds) || empty($expressNos)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$list = $this->query('select * from %b where logistics_id in %li and tracking_number in %ls order by status_time desc', $this->getTable(), $logisticsIds, $expressNos);
|
||||
$traceMap = [];
|
||||
foreach ($list as $trace) {
|
||||
$traceMap[$trace['logisticsId'].'_'.$trace['trackingNumber']][] = $trace;
|
||||
}
|
||||
foreach ($traceMap as &$traceList) {
|
||||
uasort($traceList, function ($v1, $v2) {
|
||||
return $v1['statusTime'] < $v2['statusTime'];
|
||||
});
|
||||
}
|
||||
return $traceMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\PendingMatter;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
use OrderPrintTool;
|
||||
|
||||
class PendingMasterQueueDao extends AbstractDao {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\PendingMatter;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class PendingMatterBufferDao extends AbstractDao {
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\PendingMatter;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
use OrderPrintTool;
|
||||
|
||||
class PendingMatterCategoryDao extends AbstractDao {
|
||||
public function searchPage($mallId, $page, $pageSize) {
|
||||
return $this->queryPage('select * from %b where mall_id = %i order by pending_matter_category_id desc', $this->getTable(), $mallId, $page, $pageSize);
|
||||
}
|
||||
|
||||
public function getAllByMallId($mallId) {
|
||||
return $this->query('select * from %b where mall_id = %i order by pending_matter_category_id desc', $this->getTable(), $mallId);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\PendingMatter;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
use ZcArrayHelper;
|
||||
|
||||
class PendingMatterDao extends AbstractDao {
|
||||
public function getOrderSnAndCountMap($orderSns) {
|
||||
if (empty($orderSns)) {
|
||||
return [];
|
||||
}
|
||||
$orderSns = is_array($orderSns) ? $orderSns : [$orderSns];
|
||||
$rows = $this->query('select order_sn, count(*) as pending_matter_count from %b where order_sn IN %ls and status = %s group by order_sn', $this->getTable(), $orderSns, \StatusConst::wait);
|
||||
return ZcArrayHelper::changeKeyRow($rows, 'orderSn');
|
||||
}
|
||||
|
||||
private function getSearchCondition($filter) {
|
||||
$wheres = [];
|
||||
if (!empty($filter['orderSn'])) {
|
||||
$filterOrderSn = is_array($filter['orderSn']) ? $filter['orderSn'] : [$filter['orderSn']];
|
||||
$wheres[] = $this->prepare('and pm.order_sn IN %ls', $filterOrderSn);
|
||||
}
|
||||
if (isset($filter['pendingMatterCategoryId']) && is_numeric($filter['pendingMatterCategoryId'])) {
|
||||
$wheres[] = $this->prepare('and pm.pending_matter_category_id = %i', $filter['pendingMatterCategoryId']);
|
||||
}
|
||||
if (!empty($filter['status'])) {
|
||||
$wheres[] = $this->prepare('and pm.status = %s', $filter['status']);
|
||||
}
|
||||
return $wheres;
|
||||
}
|
||||
|
||||
public function searchPage($mallId, $filter, $page, $pageSize) {
|
||||
$authMallIds = empty($filter['authMallIds']) ? [$mallId] : (is_array($filter['authMallIds']) ? $filter['authMallIds'] : [$filter['authMallIds']]);
|
||||
|
||||
$wheres = $this->getSearchCondition($filter);
|
||||
$whereString = implode(' ', $wheres);
|
||||
return $this->queryPage('select pm.* from %b pm where pm.mall_id IN %li %l order by pm.pending_matter_id desc', $this->getTable(), $authMallIds, $whereString, $page, $pageSize);
|
||||
}
|
||||
}
|
@ -0,0 +1,553 @@
|
||||
<?php
|
||||
namespace Service\FulfillmentOrder;
|
||||
|
||||
use AppConst;
|
||||
use CommonTool;
|
||||
use Dao\Common\LogisticsDao;
|
||||
use Dao\Common\LogisticsPlatformDao;
|
||||
use Dao\FulfillmentOrder\FulfillmentOrderCollectLogDao;
|
||||
use Dao\FulfillmentOrder\FulfillmentOrderDao;
|
||||
use Dao\FulfillmentOrder\FulfillmentOrderExtDao;
|
||||
use Dao\FulfillmentOrder\FulfillmentOrderGoodsLabelCodeDao;
|
||||
use Dao\FulfillmentOrder\FulfillmentOrderInsensitiveInfoDao;
|
||||
use Dao\FulfillmentOrder\FulfillmentOrderOutstorageHistoryDao;
|
||||
use Dao\FulfillmentOrder\FulfillmentOrderOutstorageStopDao;
|
||||
use Dao\FulfillmentOrder\OpPrintGoodsLabelCodeLogDao;
|
||||
use Dao\FulfillmentOrder\OpSysFulfillmentGoodsLabelCodeTplDao;
|
||||
use Dao\Mall\MallSDao;
|
||||
use DbTool;
|
||||
use Exception\BizException;
|
||||
use Exception\CheckClientException;
|
||||
use FulfillmentOrderConst;
|
||||
use FulfillmentOrderTool;
|
||||
use LogisticsConst;
|
||||
use OrderConst;
|
||||
use OrderPrintTool;
|
||||
use PddApi;
|
||||
use PermissionTool;
|
||||
use Repository\Mall\MallRepository;
|
||||
use Service\AbstractService;
|
||||
use StatusConst;
|
||||
use ZcArrayHelper;
|
||||
use ZcDateHelper;
|
||||
|
||||
class FulfillmentOrderService extends AbstractService {
|
||||
private $mallSDao;
|
||||
private $fulfillmentOrderDao;
|
||||
private $fulfillmentOrderExtDao;
|
||||
private $fulfillmentOrderInsensitiveInfoDao;
|
||||
private $logisticsDao;
|
||||
private $logisticsPlatformDao;
|
||||
private $fulfillmentOrderOutstorageStopDao;
|
||||
private $fulfillmentOrderOutstorageHistoryDao;
|
||||
private $fulfillmentOrderCollectLogDao;
|
||||
private $fulfillmentOrderGoodsLabelCodeDao;
|
||||
private $opSysFulfillmentGoodsLabelCodeTplDao;
|
||||
private $opPrintGoodsLabelCodeLogDao;
|
||||
|
||||
private $mallRepository;
|
||||
|
||||
protected function __construct() {
|
||||
$this->mallSDao = MallSDao::instance();
|
||||
$this->fulfillmentOrderDao = FulfillmentOrderDao::instance();
|
||||
$this->fulfillmentOrderExtDao = FulfillmentOrderExtDao::instance();
|
||||
$this->fulfillmentOrderInsensitiveInfoDao = FulfillmentOrderInsensitiveInfoDao::instance();
|
||||
$this->logisticsDao = LogisticsDao::instance();
|
||||
$this->logisticsPlatformDao = LogisticsPlatformDao::instance();
|
||||
$this->fulfillmentOrderOutstorageStopDao = FulfillmentOrderOutstorageStopDao::instance();
|
||||
$this->fulfillmentOrderOutstorageHistoryDao = FulfillmentOrderOutstorageHistoryDao::instance();
|
||||
$this->fulfillmentOrderCollectLogDao = FulfillmentOrderCollectLogDao::instance();
|
||||
$this->fulfillmentOrderGoodsLabelCodeDao = FulfillmentOrderGoodsLabelCodeDao::instance();
|
||||
$this->opSysFulfillmentGoodsLabelCodeTplDao = OpSysFulfillmentGoodsLabelCodeTplDao::instance();
|
||||
$this->opPrintGoodsLabelCodeLogDao = OpPrintGoodsLabelCodeLogDao::instance();
|
||||
|
||||
$this->mallRepository = MallRepository::instance();
|
||||
}
|
||||
|
||||
public function searchOrderList($mallId, $params) {
|
||||
$page = intval($params['page'] ?: 1);
|
||||
$pageSize = intval($params['pageSize'] ?: 20);
|
||||
$filter = $this->getSearchOrderFilter($mallId, $params);
|
||||
list($orderList, $total) = $this->fulfillmentOrderDao->searchPage($mallId, $filter, $page, $pageSize);
|
||||
if (empty($orderList)) {
|
||||
return [
|
||||
'orderList' => $orderList,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
$mallIds = $filter['authMallIds'] ? $filter['authMallIds'] : array($mallId);
|
||||
$fulfillmentOrderIds = ZcArrayHelper::getSub($orderList, 'fulfillmentOrderId');
|
||||
$fulfillmentOrderIdAndReceiverInfoMap = $this->fulfillmentOrderInsensitiveInfoDao->getFulfillmentOrderIdAndReceiverInfoMap($fulfillmentOrderIds);
|
||||
|
||||
$mallIdAndMallNameMap = $this->mallSDao->getMallIdAndMallNameMap($mallIds);
|
||||
foreach ($orderList as &$order) {
|
||||
$receiverInfo = $fulfillmentOrderIdAndReceiverInfoMap[$order['fulfillmentOrderId']];
|
||||
$order['mallName'] = $mallIdAndMallNameMap[$order['mallIid']];
|
||||
$order['receiverName'] = $receiverInfo['receiverName'] ? : '';
|
||||
$order['receiverPhone'] = $receiverInfo['receiverPhone'] ?: '';
|
||||
$order['receiverAddress'] = $receiverInfo['receiverAddress'] ?: '';
|
||||
$order['realReceiverName'] = $receiverInfo['receiverNameS'] ? CommonTool::decrypt($receiverInfo['receiverNameS']) : '';
|
||||
$order['realReceiverPhone'] = $receiverInfo['receiverPhoneS'] ? CommonTool::decrypt($receiverInfo['receiverPhoneS']) : '';
|
||||
$order['realReceiverAddress'] = $receiverInfo['receiverAddressS'] ? CommonTool::decrypt($receiverInfo['receiverAddressS']) : '';
|
||||
}
|
||||
$orderList = ZcArrayHelper::rebuildArrayKeyToCamelCase($orderList);
|
||||
return [
|
||||
'orderList' => $orderList,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
private function getSearchOrderFilter($mallId, $params) {
|
||||
$filter = [];
|
||||
|
||||
$params['authMallIds'] = empty($params['authMallIds']) ? array($mallId) : (is_array($params['authMallIds']) ? $params['authMallIds'] : explode(',', $params['authMallIds']));
|
||||
PermissionTool::checkMultiShopValid($mallId, $params['authMallIds']);
|
||||
|
||||
$filter['authMallIds'] = $params['authMallIds'];
|
||||
|
||||
if ($params['orderTab'] == FulfillmentOrderConst::orderTabWaitSend) {
|
||||
$filter['fulfillmentStatus'] = FulfillmentOrderConst::fulfillmentOrderStatusWaitSellerSendGoods;
|
||||
} elseif ($params['orderTab'] == FulfillmentOrderConst::orderTabHasSend) {
|
||||
$filter['fulfillmentStatus'] = FulfillmentOrderConst::fulfillmentOrderStatusWaitBuyerConfirmGoods;
|
||||
} elseif ($params['orderTab'] == FulfillmentOrderConst::orderTabFinished) {
|
||||
$filter['fulfillmentStatus'] = FulfillmentOrderConst::fulfillmentOrderStatusFinished;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($params['fulfillmentSn'])) {
|
||||
$filter['fulfillmentSn'] = is_array($params['fulfillmentSn']) ? $params['fulfillmentSn'] : CommonTool::splitWithComma($params['fulfillmentSn']);
|
||||
unset($filter['fulfillmentStatus']);
|
||||
}
|
||||
|
||||
if (empty($params['orderStartTime'])) {
|
||||
$params['orderStartTime'] = date('Y-m-d H:i:s', strtotime('-7 days'));
|
||||
}
|
||||
|
||||
if (!empty($params['orderStartTime'])) {
|
||||
$filter['orderStartTime'] = ZcDateHelper::formatDate($params['orderStartTime']);
|
||||
}
|
||||
if (!empty($params['orderEndTime']) && ($params['orderEndTime'] >= $params['orderStartTime'])) {
|
||||
if (empty($params['orderFilterDatePickTime'])) {
|
||||
$filter['orderEndTime'] = date('Y-m-d 23:59:59', strtotime($params['orderEndTime']));
|
||||
} else {
|
||||
$filter['orderEndTime'] = ZcDateHelper::formatDate($params['orderEndTime']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($params['goodsId'])) {
|
||||
$filter['goodsId'] = is_array($params['goodsId']) ? $params['goodsId'] : CommonTool::splitWithComma($params['goodsId']);
|
||||
}
|
||||
|
||||
if (!empty($params['goodsName'])) {
|
||||
$filter['goodsName'] = $params['goodsName'];
|
||||
}
|
||||
|
||||
if (!empty($params['sellerNote'])) {
|
||||
$filter['sellerNote'] = trim($params['sellerNote']);
|
||||
}
|
||||
|
||||
if (!empty($params['sortType'])) {
|
||||
$filter['sortType'] = trim($params['sortType']);
|
||||
}
|
||||
|
||||
if ($params['promiseDeliveryTimeFilter']) {
|
||||
$filter['promiseDeliveryTimeFilter'] = $params['promiseDeliveryTimeFilter'];
|
||||
}
|
||||
|
||||
if ($params['goodsLabelCodePrintFilter']) {
|
||||
$filter['goodsLabelCodePrintFilter'] = $params['goodsLabelCodePrintFilter'];
|
||||
}
|
||||
|
||||
if (!empty($params['delaySendStatus'])) {
|
||||
if ($params['delaySendStatus'] == FulfillmentOrderConst::willDelaySend) {
|
||||
$filter['promiseDeliveryTimeFilter'] = FulfillmentOrderConst::promiseDeliverTimeOneDay;
|
||||
} elseif ($params['delaySendStatus'] == FulfillmentOrderConst::hasDelaySend) {
|
||||
$filter['promiseDeliveryTimeFilter'] = FulfillmentOrderConst::promiseDeliverTimeOvertime;
|
||||
} elseif ($params['delaySendStatus'] == FulfillmentOrderConst::courierCollect) {
|
||||
$filter['courierDoorToDoorCollect'] = 1;
|
||||
}
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
public function getOrderCountMap($mallId, $params) {
|
||||
$filter = $this->getSearchOrderFilter($mallId, $params);
|
||||
$mallIds = $filter['authMallIds'] ? $filter['authMallIds'] : array($mallId);
|
||||
|
||||
$orderStatusAndOrderCountMap = $this->fulfillmentOrderDao->getStatusAndOrderCountMap($mallIds);
|
||||
$willDelaySendOrderCount = $this->fulfillmentOrderDao->getWillDelaySendOrderCount($mallIds);
|
||||
$hasDelaySendOrderCount = $this->fulfillmentOrderDao->getHasDelaySendOrderCount($mallIds);
|
||||
$courierCollectOrderCount = $this->fulfillmentOrderDao->getCourierCollectOrderCount($mallIds);
|
||||
return [
|
||||
'waitSendOrderCount' => $orderStatusAndOrderCountMap[FulfillmentOrderConst::fulfillmentOrderStatusWaitSellerSendGoods] ?: 0,
|
||||
'hasSendOrderCount' => $orderStatusAndOrderCountMap[FulfillmentOrderConst::fulfillmentOrderStatusWaitBuyerConfirmGoods] ?: 0,
|
||||
'finishOrderCount' => $orderStatusAndOrderCountMap[FulfillmentOrderConst::fulfillmentOrderStatusFinished] ?: 0,
|
||||
'willDelaySendOrderCount' => $willDelaySendOrderCount,
|
||||
'hasDelaySendOrderCount' => $hasDelaySendOrderCount,
|
||||
'courierCollectOrderCount' => $courierCollectOrderCount,
|
||||
];
|
||||
}
|
||||
|
||||
public function saveBatchSellerNote($mallId, $params) {
|
||||
$fulfillmentOrderIds = $params['fulfillmentOrderIds'];
|
||||
$note = $params['note'];
|
||||
$coverOriginal = (int)$params['coverOriginal'];
|
||||
if (empty($fulfillmentOrderIds)) {
|
||||
throw new CheckClientException('请先选择订单');
|
||||
}
|
||||
if (mb_strlen($note, 'utf-8') > 500) {
|
||||
throw new CheckClientException('便笺信息不能超过500个字');
|
||||
}
|
||||
$orders = $this->fulfillmentOrderDao->getMapByIds($fulfillmentOrderIds);
|
||||
$autoMallIds = array_values(array_unique(ZcArrayHelper::getSub($orders, 'mallId')));
|
||||
PermissionTool::checkMultiShopValid($mallId, $autoMallIds);
|
||||
|
||||
$errorMap = array();
|
||||
$successCount = 0;
|
||||
foreach ($fulfillmentOrderIds as $fulfillmentOrderId) {
|
||||
if (!isset($orders[$fulfillmentOrderId])) {
|
||||
$errorMap[$fulfillmentOrderId] = '订单不存在';
|
||||
continue;
|
||||
}
|
||||
$order = $orders[$fulfillmentOrderId];
|
||||
$orderMallId = $order['mallId'];
|
||||
$updateNote = $note;
|
||||
if (!$coverOriginal) {
|
||||
$updateNote = $order ? ($order['sellerNote'] . $updateNote) : $updateNote;
|
||||
}
|
||||
if (mb_strlen($updateNote, 'utf-8') > 500) {
|
||||
$errorMap[$fulfillmentOrderId] = '便笺信息不能超过500个字';
|
||||
continue;
|
||||
}
|
||||
$updateRet = $this->updateFulfillmentOrderSellerNote($orderMallId, $fulfillmentOrderId, $updateNote);
|
||||
if (!$updateRet) {
|
||||
$errorMap[$fulfillmentOrderId] = '更新失败';
|
||||
continue;
|
||||
}
|
||||
$successCount ++;
|
||||
}
|
||||
return [
|
||||
'successCount' => $successCount,
|
||||
'errorCount' => count($errorMap),
|
||||
'errorMap' => $errorMap,
|
||||
'newNote' => $updateNote,
|
||||
];
|
||||
}
|
||||
|
||||
public function updateFulfillmentOrderSellerNote($mallId, $fulfillmentOrderId, $sellerNote) {
|
||||
if (empty($mallId) || empty($fulfillmentOrderId)) {
|
||||
return false;
|
||||
}
|
||||
$order = $this->fulfillmentOrderDao->getById($fulfillmentOrderId);
|
||||
if (!$order || $order['mallId'] != $mallId) {
|
||||
return false;
|
||||
}
|
||||
$update = array(
|
||||
'seller_note' => $sellerNote,
|
||||
);
|
||||
$ret = $this->fulfillmentOrderDao->update($update, 'fulfillment_order_id = %i', $fulfillmentOrderId);
|
||||
return $ret === false ? false : true;
|
||||
}
|
||||
|
||||
public function getRefundAddressList($mallId, $operatorInfo) {
|
||||
$operatorMallId = $operatorInfo['mallId'];
|
||||
if ($operatorMallId == $mallId) {
|
||||
$accessToken = $operatorInfo['accessToken'];
|
||||
} else {
|
||||
$authMalls = PermissionTool::checkMultiShopValid($operatorMallId, [$mallId]);
|
||||
$accessToken = $authMalls[$mallId]['accessToken'];
|
||||
}
|
||||
return PddApi::getRefundAddressList($accessToken);
|
||||
}
|
||||
|
||||
public function manualOrderOutStorage($mallId, $params) {
|
||||
$orderId = $params['orderId'];
|
||||
$logisticsId = $params['logisticsId'];
|
||||
$expressNo = $params['expressNo'];
|
||||
$refundAddressId = $params['refundAddressId'] ?: null;
|
||||
$redeliveryType = $params['isUpdate'] ? FulfillmentOrderConst::orderLogisticsSendRedeliveryTypeModify : FulfillmentOrderConst::orderLogisticsSendRedeliveryTypeFirst;
|
||||
|
||||
$orders = $this->fulfillmentOrderDao->getMapByIds([$orderId]);
|
||||
$authMallIds = array_values(array_unique(ZcArrayHelper::getSub($orders, 'mallId')));
|
||||
|
||||
$authMalls = PermissionTool::checkMultiShopValid($mallId, $authMallIds);
|
||||
|
||||
$order = $orders[$orderId];
|
||||
$accessToken = $authMalls[$order['mallId']]['accessToken'];
|
||||
$companyId = $this->logisticsPlatformDao->getCompanyCodeByLogisticsId([$logisticsId], \AppConst::appPlatformPdd);
|
||||
$deliveryInfo = FulfillmentOrderTool::buildDeliveryInfo($order['fulfillmentSn'], $logisticsId, $companyId, $expressNo, $refundAddressId, $redeliveryType);
|
||||
$this->logisticsSend($order['mallId'], $mallId, $deliveryInfo, $accessToken, FulfillmentOrderConst::outstorageSourceManual);
|
||||
}
|
||||
|
||||
public function logisticsSend($mallId, $operatorMallId, $deliveryInfo, $accessToken, $source = '', $needRetry = false) {
|
||||
if (CommonTool::anyEmpty($mallId, $operatorMallId, $deliveryInfo, $accessToken)) {
|
||||
throw new CheckClientException('参数错误');
|
||||
}
|
||||
$this->checkLogisticsSend($mallId, $deliveryInfo);
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$outstorageRet = PddApi::fulfillmentSend($deliveryInfo, $accessToken);
|
||||
if (CommonTool::isSuccessRet($outstorageRet)) {
|
||||
break;
|
||||
}
|
||||
$failReason = $outstorageRet['reason'];
|
||||
if (preg_match('/(商家后台发货|订单已发货|当前发货单不支持发货)/isU', $failReason)) {
|
||||
$this->fulfillmentOrderOutstorageStopDao->add($mallId, $deliveryInfo['fulfillmentSn'], $failReason);
|
||||
break;
|
||||
}
|
||||
if (!$needRetry) {
|
||||
break;
|
||||
}
|
||||
if (preg_match('/重试/', $failReason)) {
|
||||
sleep(10);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->addFulfillmentOrderOutstorageHistory($mallId, $operatorMallId, $deliveryInfo, $outstorageRet, $source);
|
||||
if (CommonTool::isSuccessRet($outstorageRet)) {
|
||||
$this->updateFulfillmentOrderCollectLog($deliveryInfo['fulfillmentSn'], $deliveryInfo['logisticsId'], $deliveryInfo['trackingNumber']);
|
||||
} else {
|
||||
throw new BizException($outstorageRet['reason']);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkLogisticsSend($mallId, $deliveryInfo) {
|
||||
if ($deliveryInfo['redeliveryType'] == OrderConst::orderLogisticsSendRedeliveryTypeFirst) {
|
||||
$fulfillmentSn = $deliveryInfo['fulfillmentSn'];
|
||||
$orderOutstorageStop = $this->fulfillmentOrderOutstorageStopDao->getByFulfillmentSn($mallId, $fulfillmentSn);
|
||||
if ($orderOutstorageStop) {
|
||||
throw new BizException($orderOutstorageStop['reason']);
|
||||
}
|
||||
$order = $this->fulfillmentOrderDao->getByFulfillmentSn($fulfillmentSn);
|
||||
if (in_array($order['fulfillmentStatus'], [FulfillmentOrderConst::fulfillmentOrderStatusWaitBuyerConfirmGoods, FulfillmentOrderConst::fulfillmentOrderStatusFinished])) {
|
||||
$failReason = $order['fulfillmentStatus'] == FulfillmentOrderConst::fulfillmentOrderStatusWaitBuyerConfirmGoods ? '订单已发货' : '订单已签收';
|
||||
$this->fulfillmentOrderOutstorageStopDao->add($mallId, $fulfillmentSn, $failReason);
|
||||
return CommonTool::failResult($failReason);
|
||||
throw new BizException($failReason);
|
||||
}
|
||||
}
|
||||
|
||||
$logisticsInfo = $this->logisticsPlatformDao->getByCompanyId($deliveryInfo['companyId'], AppConst::appPlatformPdd);
|
||||
if (empty($logisticsInfo)) {
|
||||
throw new CheckClientException('发货物流公司未找到');
|
||||
}
|
||||
}
|
||||
|
||||
public function addFulfillmentOrderOutstorageHistory($mallId, $operatorMallId, $deliveryInfo, $outstorageRet, $source = '') {
|
||||
$status = CommonTool::isSuccessRet($outstorageRet) ? StatusConst::success : StatusConst::fail;
|
||||
$trans = DbTool::beginTrans(FulfillmentOrderDao::tableName());
|
||||
$this->fulfillmentOrderOutstorageHistoryDao->insert(array(
|
||||
'mall_id' => $mallId,
|
||||
'fulfillment_sn' => $deliveryInfo['fulfillmentSn'],
|
||||
'logistics_id' => $deliveryInfo['logisticsId'],
|
||||
'company_id' => $deliveryInfo['companyId'],
|
||||
'express_no' => $deliveryInfo['trackingNumber'],
|
||||
'source' => $source,
|
||||
'status' => $status,
|
||||
'reason' => $outstorageRet['reason'],
|
||||
'detail' => $outstorageRet['detail'],
|
||||
'is_cover_old_logistics' => $deliveryInfo['redeliveryType'] == FulfillmentOrderConst::fulfillmentOrderStatusWaitBuyerConfirmGoods ? 1 : 0,
|
||||
'operator_mall_id' => $operatorMallId,
|
||||
'gmt_outstorage' => \ZcDbEval::now(),
|
||||
));
|
||||
if ($status == \StatusConst::success) {
|
||||
//更新订单信息
|
||||
$update = [
|
||||
'tracking_number' => $deliveryInfo['trackingNumber'],
|
||||
'gmt_modified' => \ZcDbEval::now()
|
||||
];
|
||||
if ($deliveryInfo['redeliveryType'] == FulfillmentOrderConst::orderLogisticsSendRedeliveryTypeFirst) {
|
||||
$update['fulfillment_status'] = FulfillmentOrderConst::fulfillmentOrderStatusWaitBuyerConfirmGoods;
|
||||
}
|
||||
$this->fulfillmentOrderDao->update($update, 'mall_id = %i and order_sn = %s', $mallId, $deliveryInfo['orderSn']);
|
||||
}
|
||||
DbTool::commitTrans($trans);
|
||||
}
|
||||
|
||||
private function updateFulfillmentOrderCollectLog($fulfillmentOrderSn, $logisticsId, $expressNo) {
|
||||
$order = $this->fulfillmentOrderDao->getByFulfillmentSn($fulfillmentOrderSn);
|
||||
if (empty($order)) {
|
||||
return false;
|
||||
}
|
||||
$log = $this->fulfillmentOrderCollectLogDao->getByFulfillmentOrderId($order['fulfillmentOrderId']);
|
||||
if (empty($log)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->fulfillmentOrderCollectLogDao->update([
|
||||
'logistics_id' => $logisticsId,
|
||||
'express_no' => $expressNo,
|
||||
'shipping_time' => \ZcDbEval::now(),
|
||||
], 'fulfillment_order_id = %i', $order['fulfillmentOrderId']);
|
||||
}
|
||||
|
||||
public function searchOutstorageLog($mallId, $params) {
|
||||
$page = intval($params['page'] ?: 1);
|
||||
$pageSize = intval($params['pageSize'] ?: 20);
|
||||
|
||||
$filter = $this->getSearchLogFilter($mallId, $params);
|
||||
|
||||
list($outstorageRows, $total) = $this->fulfillmentOrderOutstorageHistoryDao->searchPage($mallId, $filter, $page, $pageSize);
|
||||
$outstorageRows = $this->buildUserOutstorageLog($outstorageRows);
|
||||
return [
|
||||
'outstorageRows' => $outstorageRows,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
public function buildUserOutstorageLog($rows) {
|
||||
$mallIds = array_column($rows, 'mallId');
|
||||
$mallIdAndMallNameMap = $this->mallSDao->getMallIdAndMallNameMap($mallIds);
|
||||
$logisticsMap = $this->logisticsDao->getLogisticsMap();
|
||||
foreach ($rows as &$row) {
|
||||
$row['mallName'] = $mallIdAndMallNameMap[$row['mallId']];
|
||||
$row['logisticsName'] = $logisticsMap[$row['logisticsId']];
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function getSearchLogFilter($mallId, $data) {
|
||||
$filter = array();
|
||||
if ($data['isMultiShop']) {
|
||||
$data['authMallIds'] = empty($data['authMallIds']) ? array($mallId) : $data['authMallIds'];
|
||||
PermissionTool::checkMultiShopValid($mallId, $data['authMallIds']);
|
||||
$filter['authMallIds'] = $data['authMallIds'];
|
||||
}
|
||||
$filter['isMultiShop'] = $data['isMultiShop'];
|
||||
if ($data['logIds']) {
|
||||
$filter['logIds'] = $data['logIds'];
|
||||
}
|
||||
if ($data['startTime']) {
|
||||
$pattern = '/^([0-9]{4})-([0-9]{2})-([0-9]{2})\s+([0-9]{2})\:([0-9]{2})\:([0-9]{2})$/';
|
||||
if (preg_match($pattern, $data['startTime'])) {
|
||||
$filter['startTime'] = $data['startTime'];
|
||||
} else {
|
||||
$filter['startTime'] = date('Y-m-d 00:00:00', strtotime($data['startTime']));
|
||||
}
|
||||
}
|
||||
if ($data['endTime']) {
|
||||
$pattern = '/^([0-9]{4})-([0-9]{2})-([0-9]{2})\s+([0-9]{2})\:([0-9]{2})\:([0-9]{2})$/';
|
||||
if (preg_match($pattern, $data['endTime'])) {
|
||||
$filter['endTime'] = $data['endTime'];
|
||||
} else {
|
||||
$filter['endTime'] = date('Y-m-d 23:59:59', strtotime($data['endTime']));
|
||||
}
|
||||
}
|
||||
if ($data['fulfillmentSn']) {
|
||||
$filter['fulfillmentSn'] = CommonTool::convertValToArray($data['fulfillmentSn']);
|
||||
}
|
||||
if ($data['logisticsId']) {
|
||||
$filter['logisticsId'] = $data['logisticsId'];
|
||||
}
|
||||
if ($_POST['waybillCode']) {
|
||||
$filter['waybillCode'] = CommonTool::convertValToArray($data['waybillCode']);
|
||||
}
|
||||
if ($_POST['waybillCodes']) {
|
||||
$filter['waybillCodes'] = CommonTool::convertValToArray($data['waybillCodes']);
|
||||
}
|
||||
|
||||
if ($data['status']) {
|
||||
$filter['status'] = $data['status'];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
public function getGoodsLabelCodeTplDetail() {
|
||||
$fulfillmentSn = $_POST['fulfillmentSn'];
|
||||
$goodsLabelCodeInfo = $this->fulfillmentOrderGoodsLabelCodeDao->getByFulfillmentSn($fulfillmentSn);
|
||||
if (empty($goodsLabelCodeInfo)) {
|
||||
throw new BizException('获取商品标签失败');
|
||||
}
|
||||
|
||||
$tpl = $this->opSysFulfillmentGoodsLabelCodeTplDao->getDefault();
|
||||
if (empty($tpl)) {
|
||||
throw new BizException('获取商品标签模板失败');
|
||||
}
|
||||
|
||||
$tplData = OrderPrintTool::convertTplInfo($tpl);
|
||||
$goodsLabelCodeInfo = ZcArrayHelper::rebuildArrayKeyToCamelCase($goodsLabelCodeInfo);
|
||||
$tplData['nodes'] = $this->buildNodePrintText($tplData['nodes'], $goodsLabelCodeInfo);
|
||||
return [
|
||||
'tplData' => empty($tplData) ? null : $tplData,
|
||||
'goodsLabelCodeInfo' => $goodsLabelCodeInfo
|
||||
];
|
||||
}
|
||||
|
||||
private function buildNodePrintText($nodes, $goodsLabelCodeInfo) {
|
||||
foreach ($nodes as &$node) {
|
||||
switch ($node['nv']['field']) {
|
||||
case LogisticsConst::labelCodeBarcode:
|
||||
$node['printText'] = $goodsLabelCodeInfo['labelCode'];
|
||||
break;
|
||||
case LogisticsConst::bgProdSkcId:
|
||||
$node['printText'] = $goodsLabelCodeInfo['bgProdSkcId'];
|
||||
break;
|
||||
case LogisticsConst::spec:
|
||||
$node['printText'] = $goodsLabelCodeInfo['spec'];
|
||||
break;
|
||||
case LogisticsConst::bgProdSkuId:
|
||||
$node['printText'] = $goodsLabelCodeInfo['bgProdSkuId'];
|
||||
break;
|
||||
case LogisticsConst::madeIn:
|
||||
$node['printText'] = $goodsLabelCodeInfo['madeIn'];
|
||||
break;
|
||||
case LogisticsConst::clothesSpec:
|
||||
$node['printText'] = $goodsLabelCodeInfo['clothesSpec'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
|
||||
}
|
||||
|
||||
public function updateGoodsLabelCodePrintStatus($operateMallId, $params) {
|
||||
$fulfillmentSn = $params['fulfillmentSn'];
|
||||
$printRet = $params['printRet'];
|
||||
$isPreview = $params['isPreview'] ? 1 : 0;
|
||||
$printStatus = CommonTool::isFailRet($printRet) ? StatusConst::fail : StatusConst::success;
|
||||
$printReason = isset($printRet['reason']) ? $printRet['reason'] : null;
|
||||
$fulfillmentOrderInfo = $this->fulfillmentOrderDao->getByFulfillmentSn($fulfillmentSn);
|
||||
$trans = DbTool::beginTrans(FulfillmentOrderExtDao::instance());
|
||||
$insertDto = [
|
||||
'mall_id' => $fulfillmentOrderInfo['mallId'],
|
||||
'fulfillment_sn' => $fulfillmentOrderInfo['fulfillmentSn'],
|
||||
'operator_mall_id' => $operateMallId,
|
||||
'status' => $printStatus,
|
||||
'reason' => $printReason,
|
||||
'is_preview' => $isPreview,
|
||||
];
|
||||
|
||||
$this->opPrintGoodsLabelCodeLogDao->insert($insertDto);
|
||||
|
||||
$extUpdateDto = [
|
||||
'mall_id' => $fulfillmentOrderInfo['mall_id'],
|
||||
'fulfillment_sn' => $fulfillmentOrderInfo['fulfillment_sn'],
|
||||
'filter_goods_label_code_printed' => 1,
|
||||
];
|
||||
$this->fulfillmentOrderExtDao->insertUpdate($extUpdateDto);
|
||||
DbTool::commitTrans($trans);
|
||||
}
|
||||
|
||||
public function searchGoodsLabelCodePrintLog($mallId, $params) {
|
||||
$page = intval($params['page'] ?: 1);
|
||||
$pageSize = intval($params['pageSize'] ?: 20);
|
||||
|
||||
$filter = $this->getSearchLogFilter($mallId, $params);
|
||||
|
||||
list($goodsLabelCodePrintLogRows, $total) = $this->fulfillmentOrderGoodsLabelCodeDao->searchPage($mallId, $filter, $page, $pageSize);
|
||||
$goodsLabelCodePrintLogRows = $this->buildGoodsLabelCodePrintLog($goodsLabelCodePrintLogRows);
|
||||
return [
|
||||
'goodsLabelCodePrintLogRows' => $goodsLabelCodePrintLogRows,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
private function buildGoodsLabelCodePrintLog($rows) {
|
||||
$rows = $this->mallRepository->appendMallFields($rows);
|
||||
return $rows;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
namespace Service\OrderPrint;
|
||||
|
||||
use CommonTool;
|
||||
use Dao\Mall\MallSDao;
|
||||
use Dao\Order\OpOrderDao;
|
||||
use Dao\PendingMatter\PendingMasterQueueDao;
|
||||
use Dao\PendingMatter\PendingMatterBufferDao;
|
||||
use Dao\PendingMatter\PendingMatterCategoryDao;
|
||||
use Dao\PendingMatter\PendingMatterDao;
|
||||
use DbTool;
|
||||
use ExcelTool;
|
||||
use Exception\BizException;
|
||||
use Exception\CheckClientException;
|
||||
use PermissionTool;
|
||||
use Service\AbstractService;
|
||||
use StatusConst;
|
||||
use ZcArrayHelper;
|
||||
|
||||
class PendingMatterService extends AbstractService {
|
||||
private $mallSDao;
|
||||
private $opOrderDao;
|
||||
private $pendingMatterDao;
|
||||
private $pendingMatterCategoryDao;
|
||||
private $pendingMatterBufferDao;
|
||||
private $pendingMasterQueueDao;
|
||||
|
||||
protected function __construct() {
|
||||
$this->mallSDao = MallSDao::instance();
|
||||
$this->opOrderDao = OpOrderDao::instance();
|
||||
$this->pendingMatterDao = PendingMatterDao::instance();
|
||||
$this->pendingMatterCategoryDao = PendingMatterCategoryDao::instance();
|
||||
$this->pendingMatterBufferDao = PendingMatterBufferDao::instance();
|
||||
$this->pendingMasterQueueDao = PendingMasterQueueDao::instance();
|
||||
}
|
||||
|
||||
public function deletePendingMatterCategory($mallId, $pendingMatterCategoryId) {
|
||||
if (CommonTool::anyEmpty($mallId, $pendingMatterCategoryId)) {
|
||||
throw new CheckClientException('参数错误');
|
||||
}
|
||||
$trans = DbTool::beginTrans(PendingMatterDao::instance());
|
||||
$this->pendingMatterCategoryDao->delete('pending_matter_category_id = %i and mall_id = %i', $pendingMatterCategoryId, $mallId);
|
||||
$updatePendingMatterData = [
|
||||
'pending_matter_category_id' => 0,
|
||||
];
|
||||
$this->pendingMatterDao->update($updatePendingMatterData, 'pending_matter_category_id = %i', $pendingMatterCategoryId);
|
||||
DbTool::commitTrans($trans);
|
||||
}
|
||||
|
||||
public function savePendingMatterCategory($mallId, $pendingMatterCategoryId, $categoryName) {
|
||||
if (CommonTool::anyEmpty($mallId, $categoryName)) {
|
||||
throw new CheckClientException('参数错误');
|
||||
}
|
||||
$data = [
|
||||
'mall_id' => $mallId,
|
||||
'category_name' => $categoryName,
|
||||
];
|
||||
if ($pendingMatterCategoryId) {
|
||||
$affect = $this->pendingMatterCategoryDao->update($data, 'pending_matter_category_id = %i and mall_id = %i', $pendingMatterCategoryId, $mallId);
|
||||
} else {
|
||||
$affect = $this->pendingMatterCategoryDao->insert($data);
|
||||
}
|
||||
if ($affect === false) {
|
||||
throw new BizException('保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function searchPendingMatterCategoryList($mallId, $page, $pageSize) {
|
||||
return $this->pendingMatterCategoryDao->searchPage($mallId, $page, $pageSize);
|
||||
}
|
||||
|
||||
public function getAllPendingMatterCategoryList($mallId) {
|
||||
return $this->pendingMatterCategoryDao->getAllByMallId($mallId);
|
||||
}
|
||||
|
||||
public function getOrderPendingMattersByPendingMatterIds($pendingMatterIds) {
|
||||
return $this->pendingMatterDao->getListByIds($pendingMatterIds);
|
||||
}
|
||||
|
||||
private function checkOrderPendingMatterData($params) {
|
||||
if (empty($params['orderSn'])) {
|
||||
throw new CheckClientException('请输入订单号');
|
||||
}
|
||||
if (empty($params['mallId'])) {
|
||||
throw new CheckClientException('请选择店铺');
|
||||
}
|
||||
$orderInfo = $this->opOrderDao->getByOrderSn($params['orderSn']);
|
||||
if (empty($orderInfo)) {
|
||||
throw new CheckClientException('订单不存在 或者 未同步');
|
||||
}
|
||||
if ($orderInfo['mallId'] != $params['mallId']) {
|
||||
throw new CheckClientException('订单所属店铺与选择的不一致');
|
||||
}
|
||||
if (!empty($params['isTimerRemind']) && empty($params['gmtRemind'])) {
|
||||
throw new CheckClientException('未设置提醒时间');
|
||||
}
|
||||
}
|
||||
|
||||
public function saveOrderPendingMatter($pendingMatterData) {
|
||||
$this->checkOrderPendingMatterData($pendingMatterData);
|
||||
|
||||
$orderMallId = $pendingMatterData['mallId'];
|
||||
$pendingMatterId = $pendingMatterData['pendingMatterId'];
|
||||
$isTimerRemind = empty($pendingMatterData['isTimerRemind']) ? 0 : 1;
|
||||
$gmtRemind = $isTimerRemind && !empty($pendingMatterData['gmtRemind']) ? $pendingMatterData['gmtRemind'] : null;
|
||||
if ($gmtRemind) {
|
||||
$gmtRemind = date('Y-m-d H:i:s', strtotime($gmtRemind));
|
||||
}
|
||||
$data = [
|
||||
'mall_id' => $pendingMatterData['mallId'],
|
||||
'order_sn' => $pendingMatterData['orderSn'],
|
||||
'is_timer_remind' => $isTimerRemind,
|
||||
'gmt_remind' => $gmtRemind,
|
||||
'pending_matter_category_id' => empty($pendingMatterData['pendingMatterCategoryId']) ? 0 : $pendingMatterData['pendingMatterCategoryId'],
|
||||
'desc' => empty($pendingMatterData['desc']) ? null : $pendingMatterData['desc'],
|
||||
'status' => !empty($pendingMatterData['status']) && in_array($pendingMatterData['status'], [StatusConst::wait, StatusConst::finish]) ? $pendingMatterData['status'] : StatusConst::wait,
|
||||
];
|
||||
|
||||
$trans = DbTool::beginTrans(PendingMatterDao::class);
|
||||
if ($pendingMatterId) {
|
||||
$this->pendingMatterDao->update($data, 'pending_matter_id = %i', $pendingMatterId);
|
||||
} else {
|
||||
$this->pendingMatterDao->insert($data);
|
||||
$pendingMatterId = $this->pendingMatterDao->lastInsertId();
|
||||
}
|
||||
|
||||
if (!$isTimerRemind) {
|
||||
$this->pendingMatterBufferDao->delete('mall_id = %i and pending_matter_id = %i', $orderMallId, $pendingMatterId);
|
||||
$this->pendingMasterQueueDao->delete('mall_id = %i and pending_matter_id = %i', $orderMallId, $pendingMatterId);
|
||||
} else {
|
||||
$this->insertUpdatePendingMatterBuffer($orderMallId, $pendingMatterId, $gmtRemind);
|
||||
}
|
||||
DbTool::commitTrans($trans);
|
||||
}
|
||||
|
||||
private function insertUpdatePendingMatterBuffer($mallId, $pendingMatterId, $gmtRemind) {
|
||||
if (CommonTool::anyEmpty($mallId, $pendingMatterId, $gmtRemind)) {
|
||||
return false;
|
||||
}
|
||||
$updateData = [
|
||||
'mall_id' => $mallId,
|
||||
'pending_matter_id' => $pendingMatterId,
|
||||
'gmt_exec' => $gmtRemind,
|
||||
];
|
||||
return $this->pendingMatterBufferDao->insertUpdate($updateData);
|
||||
}
|
||||
|
||||
public function searchOrderPendingMatterList($mallId, $params) {
|
||||
$page = intval($params['page'] ?: 1);
|
||||
$pageSize = intval($params['pageSize'] ?: 20);
|
||||
$filter = $this->getOrderPendingMatterFilter($params);
|
||||
list($pendingMatterList, $total) = $this->pendingMatterDao->searchPage($mallId, $filter, $page, $pageSize);
|
||||
if (empty($pendingMatterList)) {
|
||||
return [];
|
||||
}
|
||||
$pendingMatterCategoryIds = ZcArrayHelper::getSub($pendingMatterList, 'pendingMatterCategoryId');
|
||||
$pendingMatterCategoryIds = array_unique(array_filter($pendingMatterCategoryIds, 'isNumeric'));
|
||||
$mallIds = array_column($pendingMatterList, 'mallId');
|
||||
$mallIdAndMallNameMap = $this->mallSDao->getMallIdAndMallNameMap($mallIds);
|
||||
$categoryIdAndPendingMatterCategoryInfoMap = $this->getPendingMatterCategoryListByCategoryIds($pendingMatterCategoryIds);
|
||||
foreach ($pendingMatterList as &$pendingMatter) {
|
||||
$categoryName = $categoryIdAndPendingMatterCategoryInfoMap[$pendingMatter['pendingMatterCategoryId']]['categoryName'];
|
||||
if ($pendingMatter['pendingMatterCategoryId'] == 0) {
|
||||
$categoryName = '默认分类';
|
||||
}
|
||||
$pendingMatter['mallName'] = $mallIdAndMallNameMap[$pendingMatter['mallId']];
|
||||
$pendingMatter['categoryName'] = $categoryName;
|
||||
}
|
||||
return [$pendingMatterList, $total];
|
||||
}
|
||||
|
||||
private function getOrderPendingMatterFilter($params) {
|
||||
$filter = [];
|
||||
if (!empty($params['authMallIds'])) {
|
||||
$filter['authMallIds'] = is_array($params['authMallIds']) ? $params['authMallIds'] : [$params['authMallIds']];
|
||||
}
|
||||
if (!empty($params['orderSn'])) {
|
||||
$filter['orderSn'] = is_array($params['orderSn']) ? $params['orderSn'] : CommonTool::splitWithComma($params['orderSn']);
|
||||
}
|
||||
if (isset($params['pendingMatterCategoryId']) && is_numeric($params['pendingMatterCategoryId'])) {
|
||||
$filter['pendingMatterCategoryId'] = $params['pendingMatterCategoryId'];
|
||||
}
|
||||
if (!empty($params['status']) && in_array($params['status'], [StatusConst::wait, StatusConst::finish])) {
|
||||
$filter['status'] = $params['status'];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
public function getPendingMatterCategoryListByCategoryIds($pendingMatterCategoryIds) {
|
||||
return $this->pendingMatterCategoryDao->getMapByIds($pendingMatterCategoryIds);
|
||||
}
|
||||
|
||||
public function deletePendingMatter($pendingMatterIds) {
|
||||
if (empty($pendingMatterIds)) {
|
||||
return false;
|
||||
}
|
||||
$pendingMatterIds = is_array($pendingMatterIds) ? $pendingMatterIds : [$pendingMatterIds];
|
||||
$trans = DbTool::beginTrans(PendingMatterDao::class);
|
||||
$this->pendingMatterDao->delete('pending_matter_id IN %li', $pendingMatterIds);
|
||||
$this->pendingMatterBufferDao->delete('pending_matter_id IN %li', $pendingMatterIds);
|
||||
$this->pendingMasterQueueDao->delete('pending_matter_id IN %li', $pendingMatterIds);
|
||||
DbTool::commitTrans($trans);
|
||||
}
|
||||
|
||||
public function markPendingMatter($mallId, $pendingMatterId, $status) {
|
||||
if (CommonTool::anyEmpty($pendingMatterId, $status)) {
|
||||
return false;
|
||||
}
|
||||
$pendingMatterInfo = $this->pendingMatterDao->getById($pendingMatterId);
|
||||
if (!$status || !$pendingMatterId || !$pendingMatterInfo) {
|
||||
throw new BizException('参数错误');
|
||||
}
|
||||
|
||||
PermissionTool::checkMultiShopValid($mallId, [$pendingMatterInfo['mallId']]);
|
||||
|
||||
$pendingMatterInfo = $this->pendingMatterDao->getById($pendingMatterId);
|
||||
|
||||
$trans = DbTool::beginTrans(PendingMatterDao::class);
|
||||
$updateData = [
|
||||
'status' => $status,
|
||||
];
|
||||
$this->pendingMatterDao->update($updateData, 'pending_matter_id = %i', $pendingMatterId);
|
||||
if ($status == StatusConst::finish) {
|
||||
$this->pendingMatterBufferDao->delete('pending_matter_id = %i', $pendingMatterId);
|
||||
$this->pendingMasterQueueDao->delete('pending_matter_id = %i', $pendingMatterId);
|
||||
}
|
||||
if ($status == StatusConst::wait && $pendingMatterInfo['isTimerRemind'] && $pendingMatterInfo['gmtRemind'] && (strtotime($pendingMatterInfo['gmtRemind']) > time())) {
|
||||
$this->insertUpdatePendingMatterBuffer($pendingMatterInfo['mallId'], $pendingMatterId, $pendingMatterInfo['gmtRemind']);
|
||||
}
|
||||
DbTool::commitTrans($trans);
|
||||
}
|
||||
|
||||
public function getOrderPendingMatter($mallId, $pendingMatterId) {
|
||||
$pendingMatterInfo = $this->pendingMatterDao->getById($pendingMatterId);
|
||||
|
||||
if (!$pendingMatterInfo) {
|
||||
throw new BizException('待处理事项不存在');
|
||||
}
|
||||
PermissionTool::checkMultiShopValid($mallId, [$pendingMatterInfo['mallId']]);
|
||||
return [
|
||||
'pendingMatterId' => $pendingMatterInfo['pendingMatterId'],
|
||||
'pendingMatterCategoryId' => $pendingMatterInfo['pendingMatterCategoryId'],
|
||||
'mallId' => $pendingMatterInfo['mallId'],
|
||||
'orderSn' => $pendingMatterInfo['orderSn'],
|
||||
'isTimerRemind' => $pendingMatterInfo['isTimerRemind'],
|
||||
'gmtRemind' => $pendingMatterInfo['gmtRemind'],
|
||||
'desc' => $pendingMatterInfo['desc'],
|
||||
'status' => $pendingMatterInfo['status'],
|
||||
];
|
||||
}
|
||||
|
||||
public function getOrderPendingMatterCount($orderSn) {
|
||||
$orderSn = CommonTool::convertValToArray($orderSn);
|
||||
$orderSnAndPendingMatterCountMap = $this->pendingMatterDao->getOrderSnAndCountMap($orderSn);
|
||||
$data = [];
|
||||
foreach ($orderSnAndPendingMatterCountMap as $orderSnAndPendingMatterCountInfo) {
|
||||
$data[] = [
|
||||
'orderSn' => $orderSnAndPendingMatterCountInfo['orderSn'],
|
||||
'count' => $orderSnAndPendingMatterCountInfo['pendingMatterCount'],
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function exportPendingMatter($mallId, $params) {
|
||||
$orderPendingMatterData = $this->getExportPendingMatter($mallId, $params);
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
$activeSheet = ExcelTool::createNewSheetAndSetTitle($objPHPExcel, 0);
|
||||
$headers = ['店铺', '订单号', '事项描述', '事项分类', '提醒时间', '状态'];
|
||||
ExcelTool::setSheetRowValues($activeSheet, 1, $headers);
|
||||
|
||||
$row = 2;
|
||||
foreach ($orderPendingMatterData as $orderPendingMatter) {
|
||||
$column = 1;
|
||||
ExcelTool::setCellValue($activeSheet, $column++, $row, empty($orderPendingMatter['mallName']) ? '' : $orderPendingMatter['mallName']);
|
||||
ExcelTool::setCellValue($activeSheet, $column++, $row, $orderPendingMatter['orderSn']);
|
||||
ExcelTool::setCellValue($activeSheet, $column++, $row, $orderPendingMatter['desc']);
|
||||
ExcelTool::setCellValue($activeSheet, $column++, $row, empty($orderPendingMatter['categoryName']) ? '' : $orderPendingMatter['categoryName']);
|
||||
|
||||
$gmtRemind = $orderPendingMatter['isTimerRemind'] ? $orderPendingMatter['gmtRemind'] : '';
|
||||
ExcelTool::setCellValue($activeSheet, $column++, $row, $gmtRemind);
|
||||
ExcelTool::setCellValue($activeSheet, $column++, $row, $orderPendingMatter['status'] == StatusConst::finish ? '已处理' : '未处理');
|
||||
$row++;
|
||||
}
|
||||
ExcelTool::downloadExcel($objPHPExcel, date('Y-m-d', time()) . '-待处理事项');
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getExportPendingMatter($mallId, $params) {
|
||||
$page = 1;
|
||||
$pageSize = 50;
|
||||
$orderPendingMatterList = [];
|
||||
while (true) {
|
||||
$params['page'] = $page;
|
||||
$params['pageSize'] = $pageSize;
|
||||
list($pendingMatterList, $total) = $this->searchOrderPendingMatterList($mallId, $params);
|
||||
if (empty($pendingMatterList)) {
|
||||
break;
|
||||
}
|
||||
$orderPendingMatterList = array_merge($orderPendingMatterList, $pendingMatterList);
|
||||
if (count($pendingMatterList) < $pageSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $orderPendingMatterList;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue