|
|
@@ -15,168 +15,168 @@ use linslin\yii2\curl;
|
|
|
|
|
|
class OrderSendService extends BaseService
|
|
|
{
|
|
|
-
|
|
|
- public static $baseFile = '\biz\order\classes\OrderSendClass';
|
|
|
-
|
|
|
- //制单 shish 2019.12.17
|
|
|
- public static function printOrder($data)
|
|
|
- {
|
|
|
- $id = $data['id'];
|
|
|
- $option = $data['option'];
|
|
|
- $actionIdList = OrderSendClass::$actionId;
|
|
|
- $printOrderId = $actionIdList['printOrder'];
|
|
|
- $currentId = OrderSendClass::toDoActionId($id);
|
|
|
- if ($printOrderId != $currentId) {
|
|
|
- util::fail('当前流程无法操作');
|
|
|
- }
|
|
|
- //1有配送单 2 填单制单
|
|
|
- if (in_array($option, [1, 2]) == false) {
|
|
|
- util::fail('操作无效');
|
|
|
- }
|
|
|
- $time = time();
|
|
|
- OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $printOrderId], ['option' => $option, 'finishTime' => $time]);
|
|
|
- $hasDeliver = 0;
|
|
|
- if ($option == 1) {
|
|
|
- //有纸质配送单
|
|
|
- $hasDeliver = 1;
|
|
|
- }
|
|
|
- if ($option == 2) {
|
|
|
- //填单制单
|
|
|
- $hasDeliver = 2;
|
|
|
- }
|
|
|
- OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_UN_SEND, 'currentFlow' => 2, 'printStatus' => 1, 'hasDeliver' => $hasDeliver]);
|
|
|
-
|
|
|
- //进入发货流程
|
|
|
- $deliverId = $actionIdList['deliver'];
|
|
|
- $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId];
|
|
|
- OrderSendClass::add($data);
|
|
|
- $actionList = OrderSendClass::$action;
|
|
|
- $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
|
|
|
- util::success(['nextAction' => $data]);
|
|
|
- }
|
|
|
-
|
|
|
- //发货 shish 2019.12.17
|
|
|
- public static function deliver($data)
|
|
|
- {
|
|
|
- $id = $data['id'];
|
|
|
- $option = $data['option'];
|
|
|
- $actionIdList = OrderSendClass::$actionId;
|
|
|
- $deliverId = $actionIdList['deliver'];
|
|
|
- $currentId = OrderSendClass::toDoActionId($id);
|
|
|
- if ($deliverId != $currentId) {
|
|
|
- util::fail('当前流程无法操作');
|
|
|
- }
|
|
|
- $time = time();
|
|
|
-
|
|
|
- $sendType = isset($data['sendType']) ? $data['sendType'] : OrderClass::SEND_TYPE_UNKNOWN;
|
|
|
-
|
|
|
- $sendInfo = [];
|
|
|
- if ($sendType == OrderClass::SEND_TYPE_OTHER) {
|
|
|
-
|
|
|
- util::fail('即将开通...');
|
|
|
-
|
|
|
- $side = $data['sendSide'];
|
|
|
- $sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
|
|
|
- if ($sendTime < ($time + 20 * 60)) {
|
|
|
- util::fail('请选择20分钟之后的时间');
|
|
|
- }
|
|
|
- $sendInfo = [
|
|
|
- 'sideId' => $side,
|
|
|
- 'sendTime' => $sendTime,
|
|
|
- 'addTime' => $time,
|
|
|
- 'sendTip' => 0,
|
|
|
- 'merchantId' => $data['merchantId'],
|
|
|
- 'orderId' => $id,
|
|
|
- 'cost' => 6,
|
|
|
- 'tip' => 0,
|
|
|
- 'distance' => 7,
|
|
|
- 'sendTime' => $sendTime,
|
|
|
- 'side' => $side,
|
|
|
- ];
|
|
|
- OrderExpressClass::add($sendInfo);
|
|
|
- }
|
|
|
-
|
|
|
- OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $deliverId], ['option' => $option, 'finishTime' => $time]);
|
|
|
- OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_SENDING, 'currentFlow' => 3, 'sendType' => $sendType]);
|
|
|
-
|
|
|
- //待发货订单-1,配送中订单+1
|
|
|
- $merchantId = $data['merchantId'];
|
|
|
- $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
- $asset->unSendOrder -= 1;
|
|
|
- $asset->sendingOrder += 1;
|
|
|
- $asset->save();
|
|
|
-
|
|
|
- //进入送达流程
|
|
|
- $reachId = $actionIdList['reach'];
|
|
|
- $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId];
|
|
|
- OrderSendClass::add($data);
|
|
|
- $actionList = OrderSendClass::$action;
|
|
|
- $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';
|
|
|
- util::success(['nextAction' => $data, 'sendInfo' => $sendInfo]);
|
|
|
- }
|
|
|
-
|
|
|
- //送达 shish 2019.12.17
|
|
|
- public static function reach($order, $data)
|
|
|
- {
|
|
|
- $id = $order['id'];
|
|
|
- $actionIdList = OrderSendClass::$actionId;
|
|
|
- $reachId = $actionIdList['reach'];
|
|
|
- $currentId = OrderSendClass::toDoActionId($id);
|
|
|
- if ($reachId != $currentId) {
|
|
|
- util::fail('当前流程无法操作');
|
|
|
- }
|
|
|
- OrderSendClass::reach($order);
|
|
|
- OrderClass::complete($order, OrderClass::ORDER_TOTAL_FLOW);
|
|
|
- //配送中订单-1,完成订单+1
|
|
|
- $merchantId = $order['merchantId'];
|
|
|
- $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
- $asset->sendingOrder -= 1;
|
|
|
- $asset->finishOrder += 1;
|
|
|
- $asset->save();
|
|
|
- util::complete();
|
|
|
- }
|
|
|
-
|
|
|
- //发货详情 shish 2019.12.15
|
|
|
- public static function sendList($order)
|
|
|
- {
|
|
|
- $orderId = $order['id'];
|
|
|
- $list = OrderSendClass::getAllByCondition(['orderId' => $orderId], 'inTurn DESC', '*');
|
|
|
- if (empty($list)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- $nameList = OrderSendClass::$action;
|
|
|
- $idList = OrderSendClass::$actionId;
|
|
|
- foreach ($list as $key => $val) {
|
|
|
- $actionId = $val['actionId'];
|
|
|
- $list[$key]['actionName'] = isset($nameList[$actionId]['name']) ? $nameList[$actionId]['name'] : '';
|
|
|
- $list[$key]['actionSign'] = isset($nameList[$actionId]['sign']) ? $nameList[$actionId]['sign'] : '';
|
|
|
- if ($actionId == $idList['printOrder']) {
|
|
|
- $list[$key]['receive'] = [];
|
|
|
- if (!empty($order['receiveUserName'])) {
|
|
|
- $list[$key]['receive'] = [
|
|
|
- 'receiveUserName' => $order['receiveUserName'],
|
|
|
- 'receiveMobile' => $order['receiveMobile'],
|
|
|
- 'receiveAddress' => $order['receiveAddress'],
|
|
|
- 'receiveFloor' => $order['receiveFloor'],
|
|
|
- 'receiveFullAddress' => $order['receiveFullAddress'],
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- if ($actionId == $idList['deliver']) {
|
|
|
- $list[$key]['sendInfo'] = $order['sendType'] == OrderClass::SEND_TYPE_OTHER ? OrderExpressClass::getExpress($orderId) : [];
|
|
|
- }
|
|
|
- if ($actionId == $idList['reach']) {
|
|
|
- $list[$key]['classify'] = [];
|
|
|
- if ($order['classify'] == 1) {
|
|
|
- $category = CategoryClass::getById($order['categoryId']);
|
|
|
- $categoryName = isset($category['categoryName']) ? $category['categoryName'] : '';
|
|
|
- $usage = UsageClass::getById($order['usageId']);
|
|
|
- $usageName = isset($usage['usageName']) ? $usage['usageName'] : '';
|
|
|
- $list[$key]['classify'] = ['category' => $categoryName, 'usage' => $usageName];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return $list;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ public static $baseFile = '\biz\order\classes\OrderSendClass';
|
|
|
+
|
|
|
+ //制单 shish 2019.12.17
|
|
|
+ public static function printOrder($data)
|
|
|
+ {
|
|
|
+ $id = $data['id'];
|
|
|
+ $option = $data['option'];
|
|
|
+ $actionIdList = OrderSendClass::$actionId;
|
|
|
+ $printOrderId = $actionIdList['printOrder'];
|
|
|
+ $currentId = OrderSendClass::toDoActionId($id);
|
|
|
+ if ($printOrderId != $currentId) {
|
|
|
+ util::fail('当前流程无法操作');
|
|
|
+ }
|
|
|
+ //1有配送单 2 填单制单
|
|
|
+ if (in_array($option, [1, 2]) == false) {
|
|
|
+ util::fail('操作无效');
|
|
|
+ }
|
|
|
+ $time = time();
|
|
|
+ OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $printOrderId], ['option' => $option, 'finishTime' => $time]);
|
|
|
+ $hasDeliver = 0;
|
|
|
+ if ($option == 1) {
|
|
|
+ //有纸质配送单
|
|
|
+ $hasDeliver = 1;
|
|
|
+ }
|
|
|
+ if ($option == 2) {
|
|
|
+ //填单制单
|
|
|
+ $hasDeliver = 2;
|
|
|
+ }
|
|
|
+ OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_UN_SEND, 'currentFlow' => 2, 'printStatus' => 1, 'hasDeliver' => $hasDeliver]);
|
|
|
+
|
|
|
+ //进入发货流程
|
|
|
+ $deliverId = $actionIdList['deliver'];
|
|
|
+ $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId];
|
|
|
+ OrderSendClass::add($data);
|
|
|
+ $actionList = OrderSendClass::$action;
|
|
|
+ $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
|
|
|
+ util::success(['nextAction' => $data]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //发货 shish 2019.12.17
|
|
|
+ public static function deliver($data)
|
|
|
+ {
|
|
|
+ $id = $data['id'];
|
|
|
+ $option = $data['option'];
|
|
|
+ $actionIdList = OrderSendClass::$actionId;
|
|
|
+ $deliverId = $actionIdList['deliver'];
|
|
|
+ $currentId = OrderSendClass::toDoActionId($id);
|
|
|
+ if ($deliverId != $currentId) {
|
|
|
+ util::fail('当前流程无法操作');
|
|
|
+ }
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ $sendType = isset($data['sendType']) ? $data['sendType'] : OrderClass::SEND_TYPE_UNKNOWN;
|
|
|
+
|
|
|
+ $sendInfo = [];
|
|
|
+ if ($sendType == OrderClass::SEND_TYPE_OTHER) {
|
|
|
+
|
|
|
+ util::fail('即将开通...');
|
|
|
+
|
|
|
+ $side = $data['sendSide'];
|
|
|
+ $sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
|
|
|
+ if ($sendTime < ($time + 20 * 60)) {
|
|
|
+ util::fail('请选择20分钟之后的时间');
|
|
|
+ }
|
|
|
+ $sendInfo = [
|
|
|
+ 'sideId' => $side,
|
|
|
+ 'sendTime' => $sendTime,
|
|
|
+ 'addTime' => $time,
|
|
|
+ 'sendTip' => 0,
|
|
|
+ 'merchantId' => $data['merchantId'],
|
|
|
+ 'orderId' => $id,
|
|
|
+ 'cost' => 6,
|
|
|
+ 'tip' => 0,
|
|
|
+ 'distance' => 7,
|
|
|
+ 'sendTime' => $sendTime,
|
|
|
+ 'side' => $side,
|
|
|
+ ];
|
|
|
+ OrderExpressClass::add($sendInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $deliverId], ['option' => $option, 'finishTime' => $time]);
|
|
|
+ OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_SENDING, 'currentFlow' => 3, 'sendType' => $sendType]);
|
|
|
+
|
|
|
+ //待发货订单-1,配送中订单+1
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
+ $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
+ $asset->unSendOrder -= 1;
|
|
|
+ $asset->sendingOrder += 1;
|
|
|
+ $asset->save();
|
|
|
+
|
|
|
+ //进入送达流程
|
|
|
+ $reachId = $actionIdList['reach'];
|
|
|
+ $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId];
|
|
|
+ OrderSendClass::add($data);
|
|
|
+ $actionList = OrderSendClass::$action;
|
|
|
+ $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';
|
|
|
+ util::success(['nextAction' => $data, 'sendInfo' => $sendInfo]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //送达 shish 2019.12.17
|
|
|
+ public static function reach($order, $data)
|
|
|
+ {
|
|
|
+ $id = $order['id'];
|
|
|
+ $actionIdList = OrderSendClass::$actionId;
|
|
|
+ $reachId = $actionIdList['reach'];
|
|
|
+ $currentId = OrderSendClass::toDoActionId($id);
|
|
|
+ if ($reachId != $currentId) {
|
|
|
+ util::fail('当前流程无法操作');
|
|
|
+ }
|
|
|
+ OrderSendClass::reach($order);
|
|
|
+ OrderClass::complete($order, OrderClass::ORDER_TOTAL_FLOW);
|
|
|
+ //配送中订单-1,完成订单+1
|
|
|
+ $merchantId = $order['merchantId'];
|
|
|
+ $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
+ $asset->sendingOrder -= 1;
|
|
|
+ $asset->finishOrder += 1;
|
|
|
+ $asset->save();
|
|
|
+ util::complete();
|
|
|
+ }
|
|
|
+
|
|
|
+ //发货详情 shish 2019.12.15
|
|
|
+ public static function sendList($order)
|
|
|
+ {
|
|
|
+ $orderId = $order['id'];
|
|
|
+ $list = OrderSendClass::getAllByCondition(['orderId' => $orderId], 'inTurn DESC', '*');
|
|
|
+ if (empty($list)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $nameList = OrderSendClass::$action;
|
|
|
+ $idList = OrderSendClass::$actionId;
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $actionId = $val['actionId'];
|
|
|
+ $list[$key]['actionName'] = isset($nameList[$actionId]['name']) ? $nameList[$actionId]['name'] : '';
|
|
|
+ $list[$key]['actionSign'] = isset($nameList[$actionId]['sign']) ? $nameList[$actionId]['sign'] : '';
|
|
|
+ if ($actionId == $idList['printOrder']) {
|
|
|
+ $list[$key]['receive'] = [];
|
|
|
+ if (!empty($order['receiveUserName'])) {
|
|
|
+ $list[$key]['receive'] = [
|
|
|
+ 'receiveUserName' => $order['receiveUserName'],
|
|
|
+ 'receiveMobile' => $order['receiveMobile'],
|
|
|
+ 'address' => $order['address'],
|
|
|
+ 'floor' => $order['floor'],
|
|
|
+ 'fullAddress' => $order['fullAddress'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($actionId == $idList['deliver']) {
|
|
|
+ $list[$key]['sendInfo'] = $order['sendType'] == OrderClass::SEND_TYPE_OTHER ? OrderExpressClass::getExpress($orderId) : [];
|
|
|
+ }
|
|
|
+ if ($actionId == $idList['reach']) {
|
|
|
+ $list[$key]['classify'] = [];
|
|
|
+ if ($order['classify'] == 1) {
|
|
|
+ $category = CategoryClass::getById($order['categoryId']);
|
|
|
+ $categoryName = isset($category['categoryName']) ? $category['categoryName'] : '';
|
|
|
+ $usage = UsageClass::getById($order['usageId']);
|
|
|
+ $usageName = isset($usage['usageName']) ? $usage['usageName'] : '';
|
|
|
+ $list[$key]['classify'] = ['category' => $categoryName, 'usage' => $usageName];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
}
|