| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace bizGhs\order\classes;
- use bizGhs\base\classes\BaseClass;
- use common\components\util;
- class OrderSendClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\order\models\OrderSend';
- //流程键名与ID关系
- const ACTION_RELATION = ['placeOrder' => 10, 'deliver' => 30, 'reach' => 40];
- const ACTION_LIST = [
- 10 => ['name' => '下单', 'sign' => 'placeOrder'],
- 30 => ['name' => '发货', 'sign' => 'deliver'],
- 40 => ['name' => '送达', 'sign' => 'reach']
- ];
- public static function thirdSend($order)
- {
- $orderSn = $order->orderSn;
- $relation = self::ACTION_RELATION;
- $currentId = $relation['deliver'] ?? 0;
- if (empty($currentId)) {
- util::fail('没有找到流程');
- }
- $send = self::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId], true);
- if (empty($send)) {
- return false;
- util::fail('配送信息错误');
- }
- //0没有选择 1本店送 2发快递
- $send->option = 2;
- $send->status = 0;
- $send->finishTime = date("Y-m-d H:i:s");
- $send->save();
- }
- //本店送 ssh 2021.3.4
- public static function selfSend($order)
- {
- $orderSn = $order->orderSn;
- $relation = self::ACTION_RELATION;
- $currentId = $relation['deliver'] ?? 0;
- if (empty($currentId)) {
- util::fail('没有找到流程');
- }
- $send = self::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId], true);
- if (empty($send)) {
- return false;
- util::fail('配送信息错误');
- }
- //0没有选择 1本店送 2发快递
- $send->option = 1;
- $send->status = 0;
- $send->finishTime = date("Y-m-d H:i:s");
- $send->save();
- }
- //下单操作完成 ssh 2019.12.13
- public static function placeOrder($data)
- {
- //下单完成
- $orderSn = $data['orderSn'];
- $payTime = $data['payTime'];
- $relation = self::ACTION_RELATION;
- $actionList = self::ACTION_LIST;
- $currentId = $relation['placeOrder'] ?? 0;
- if (empty($currentId)) {
- util::fail('没有找到流程');
- }
- $currentName = $actionList[$currentId]['name'] ?? '';
- $data = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $payTime, 'inTurn' => $currentId, 'status' => 1];
- self::add($data);
- OrderClass::updateByCondition(['orderSn' => $orderSn], ['currentFlow' => 1]);
- //配送未开始
- $nextId = $relation['deliver'] ?? 0;
- if (empty($nextId)) {
- util::fail('下单后没有找到下一步的流程ID');
- }
- $nextName = $actionList[$nextId]['name'] ?? '';
- $data = ['actionId' => $nextId, 'actionName' => $nextName, 'orderSn' => $orderSn, 'inTurn' => $nextId, 'status' => 0];
- self::add($data);
- }
- //当前待执行的动作 ssh 2019.12.16
- public static function toDoActionId($orderSn)
- {
- $action = self::getByCondition(['orderSn' => $orderSn], false, 'inTurn DESC');
- $actionId = 0;
- if (empty($action['finishTime'])) {
- $actionId = $action['actionId'];
- }
- return $actionId;
- }
- //送达 ssh 2020.6.1
- public static function reach($order)
- {
- $orderSn = $order['orderSn'];
- $time = date("Y-m-d H:i:s");
- $relation = self::ACTION_RELATION;
- $actionList = self::ACTION_LIST;
- $currentId = $relation['reach'] ?? 0;
- if (empty($currentId)) {
- util::fail('没有找到流程');
- }
- $currentName = $actionList[$currentId]['name'] ?? '';
- $has = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId]);
- if ($has) {
- util::fail('已经确认送达');
- }
- $preActionId = $relation['deliver'] ?? 0;
- $preInfo = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $preActionId], true);
- if (empty($preInfo)) {
- return false;
- util::fail('配送信息错误,没有找到前面个流程');
- }
- $preInfo->status = 1;
- $preInfo->save();
- $sendData = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $time, 'inTurn' => $currentId, 'status' => 1];
- OrderSendClass::add($sendData);
- }
- //免发货和自取流程处理 ssh 2021.1.24
- public static function withoutSend($info)
- {
- $orderSn = $info->orderSn ?? '';
- if (empty($orderSn)) {
- util::faill('没有找到订单编号');
- }
- self::deleteByCondition(['orderSn' => $orderSn]);
- }
- }
|