|
|
@@ -15,346 +15,353 @@ use bizGhs\base\classes\BaseClass;
|
|
|
|
|
|
class OrderClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
- public static $baseFile = '\bizGhs\order\models\Order';
|
|
|
-
|
|
|
- //已完成
|
|
|
- const ORDER_STATUS_COMPLETE = 6;
|
|
|
- //已取消
|
|
|
- const ORDER_STATUS_CANCEL = 5;
|
|
|
- //待通知
|
|
|
- const ORDER_STATUS_UN_NOTICE = 4;
|
|
|
- //配送中
|
|
|
- const ORDER_STATUS_SENDING = 3;
|
|
|
- //待配送
|
|
|
- const ORDER_STATUS_UN_SEND = 2;
|
|
|
- //待付款,待确认
|
|
|
- const ORDER_STATUS_UN_PAY = 1;
|
|
|
-
|
|
|
- //未确认
|
|
|
- const SEND_TYPE_UNKNOWN = 1;
|
|
|
- //自取
|
|
|
- const SEND_TYPE_NO = 2;
|
|
|
- //自己送
|
|
|
- const SEND_TYPE_MYSELF = 3;
|
|
|
- //快递送,第三方配送
|
|
|
- const SEND_TYPE_THIRD = 4;
|
|
|
-
|
|
|
- //待付款,待确认
|
|
|
- const PAY_STATUS_UN_PAY = 1;
|
|
|
- //已付款
|
|
|
- const PAY_STATUS_HAS_PAY = 2;
|
|
|
-
|
|
|
- //待配送
|
|
|
- const SEND_STATUS_UN_SEND = 1;
|
|
|
- //配送中
|
|
|
- const SEND_STATUS_SENDING = 2;
|
|
|
- //配送完成
|
|
|
- const SEND_STATUS_COMPLETE = 3;
|
|
|
-
|
|
|
-
|
|
|
- //订单总流程数
|
|
|
- const TOTAL_FLOW = 3;
|
|
|
-
|
|
|
- //添加订单 shish 2019.12.5
|
|
|
- public static function addOrder($data)
|
|
|
- {
|
|
|
- $merchantId = $data['merchantId'] ?? 0;
|
|
|
- $month = date("Ym");
|
|
|
- $orderSn = orderSn::getGhsOrderSn();
|
|
|
- $data['orderSn'] = $orderSn;
|
|
|
- $data['payStatus'] = self::PAY_STATUS_UN_PAY;
|
|
|
-
|
|
|
- //花材列表
|
|
|
- $product = $data['product'];
|
|
|
- OrderItemClass::replace($orderSn, $product);
|
|
|
-
|
|
|
- //将花店每月的总订单数作为编号
|
|
|
- $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
|
|
|
- $data['sendNum'] = $riseNum;
|
|
|
- $data['num'] = 1;
|
|
|
- $data['smallNum'] = 1;
|
|
|
- $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
|
|
|
- //订单30分钟后过期
|
|
|
- $data['deadline'] = date("Y-m-d H:i:s", (time() + 1800));
|
|
|
- $data['sendCost'] = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
|
|
|
- $return = self::add($data);
|
|
|
- $orderId = $return['id'];
|
|
|
-
|
|
|
- //全部订单+1,待付款订单+1
|
|
|
- $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
- $merchantAsset->unPayOrder += 1;
|
|
|
- $merchantAsset->totalOrder += 1;
|
|
|
- $merchantAsset->save();
|
|
|
-
|
|
|
- //增加下单流程
|
|
|
- $payTime = date("Y-m-d H:i:s");
|
|
|
- $sendData = ['orderId' => $orderId, 'orderSn' => $orderSn, 'payTime' => $payTime];
|
|
|
- OrderSendClass::placeOrder($sendData);
|
|
|
-
|
|
|
- //扣库存 2021.2.23 linqh
|
|
|
- foreach ($product as $key => $val) {
|
|
|
- ProductClass::decreaseStock($val['productId'], $val['num'], $val['smallNum']);
|
|
|
- }
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- //根据订单编号查询 shish 2021.19
|
|
|
- public static function getByOrderSn($orderSn)
|
|
|
- {
|
|
|
- return self::getByCondition(['orderSn' => $orderSn]);
|
|
|
- }
|
|
|
-
|
|
|
- //订单列表 shish 2021.1.19
|
|
|
- public static function getOrderList($where)
|
|
|
- {
|
|
|
- $data = self::getList('*', $where, 'addTime DESC');
|
|
|
- $data['list'] = self::groupOrder($data['list'], true, false, false, false, true);
|
|
|
- $data['allNum'] = 0;
|
|
|
- $data['unPayNum'] = 0;
|
|
|
- $data['unSendNum'] = 0;
|
|
|
- $data['sendingNum'] = 0;
|
|
|
- $data['finishNum'] = 0;
|
|
|
- return $data;
|
|
|
- }
|
|
|
-
|
|
|
- //显示操作按钮
|
|
|
- public static function getShowButton($showButton, $isList, $order)
|
|
|
- {
|
|
|
- if ($showButton == false) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- //列表页显示的按钮
|
|
|
- if ($isList) {
|
|
|
- $item = ['type' => 'item', 'show' => 1, 'disable' => 1];
|
|
|
- $send = ['type' => 'send', 'show' => 1, 'disable' => 0];
|
|
|
- $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
|
|
|
- if (in_array($order['status'], [self::ORDER_STATUS_UN_PAY, self::ORDER_STATUS_UN_SEND])) {
|
|
|
- //待付款和待配送订单,改花材按钮才能点击
|
|
|
- $item['disable'] = 0;
|
|
|
- }
|
|
|
- if ($order['sendType'] == self::SEND_TYPE_NO) {
|
|
|
- //自取订单,发货按钮不可点
|
|
|
- $send['disable'] = 1;
|
|
|
- }
|
|
|
- if ($order['sendType'] == self::SEND_TYPE_UNKNOWN) {
|
|
|
- //只有未确认配送方式的订单才可点击自取
|
|
|
- $selfGet['disable'] = 0;
|
|
|
- }
|
|
|
- return [$item, $send, $selfGet];
|
|
|
- }
|
|
|
-
|
|
|
- //待确认订单显示延期付和已付款
|
|
|
- if ($order['status'] == OrderClass::ORDER_STATUS_UN_PAY) {
|
|
|
- $debtPay = ['type' => 'debtPay', 'show' => 1, 'disable' => 0];
|
|
|
- $hasPay = ['type' => 'hasPay', 'show' => 1, 'disable' => 0];
|
|
|
- return [$debtPay, $hasPay];
|
|
|
- }
|
|
|
-
|
|
|
- //待配送订单显示打印、发货和自取
|
|
|
- if ($order['status'] == OrderClass::ORDER_STATUS_UN_SEND) {
|
|
|
- //没有花材的订单按钮全部置灰色不可点
|
|
|
- $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
|
|
|
- $item = ['type' => 'item', 'show' => 1, 'disable' => 1];
|
|
|
- $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
|
|
|
- $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
|
|
|
- if ($order['hasItem'] == 2) {
|
|
|
- return [$print, $item, $selfGet, $send];
|
|
|
- }
|
|
|
- $print['disable'] = 0;
|
|
|
- $selfGet['disable'] = 0;
|
|
|
- $send['disable'] = 0;
|
|
|
- $item['disable'] = 0;
|
|
|
- return [$print, $item, $selfGet, $send];
|
|
|
- }
|
|
|
- //配送中显示按钮
|
|
|
- if ($order['status'] == OrderClass::ORDER_STATUS_SENDING) {
|
|
|
- $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
|
|
|
- $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
|
|
|
- return [$print, $send];
|
|
|
- }
|
|
|
- if ($order['status'] == OrderClass::ORDER_STATUS_COMPLETE) {
|
|
|
- $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
|
|
|
- $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
|
|
|
- //自取订单不显示发货按钮
|
|
|
- if ($order['sendType'] == self::SEND_TYPE_NO) {
|
|
|
- $send['show'] = 0;
|
|
|
- }
|
|
|
- return [$print, $send];
|
|
|
- }
|
|
|
- return [];
|
|
|
- }
|
|
|
-
|
|
|
- //显示进度 shish 2021.3.1
|
|
|
- public static function getShowProgress($showProgress, $order)
|
|
|
- {
|
|
|
- if ($showProgress == false) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- $create = ['name' => '创建', 'complete' => 1];
|
|
|
- $unConfirm = ['name' => '待确认', 'complete' => 0];
|
|
|
- if ($order['status'] > 0) {
|
|
|
- $unConfirm['complete'] = 1;
|
|
|
- }
|
|
|
- $out = ['name' => '出库', 'complete' => 0];
|
|
|
- if ($order['status'] > 1) {
|
|
|
- $out['complete'] = 1;
|
|
|
- }
|
|
|
- return [$create, $unConfirm, $out];
|
|
|
- }
|
|
|
-
|
|
|
- public static function getShowItem($showItem, $order)
|
|
|
- {
|
|
|
- if ($showItem == false) {
|
|
|
- return ['list' => [], 'itemStat' => []];
|
|
|
- }
|
|
|
- $orderSn = $order['orderSn'];
|
|
|
- $list = OrderItemClass::getOrderItem($orderSn);
|
|
|
- $totalPrice = 0;
|
|
|
- $totalBigNum = 0;
|
|
|
- $totalSmallNum = 0;
|
|
|
- $kind = 0;
|
|
|
- $itemStat = [];
|
|
|
- if (!empty($list)) {
|
|
|
- foreach ($list as $key => $val) {
|
|
|
- $list[$key]['property'] = $val['rank'] . '级';
|
|
|
- $price = $val['price'];
|
|
|
- $totalPrice = stringUtil::calcAdd($totalPrice, $price);
|
|
|
- $kind++;
|
|
|
- $currentBigNum = $val['bigNum'];
|
|
|
- $currentSmallNum = $val['smallNum'];
|
|
|
- $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
|
|
|
- $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
|
|
|
- }
|
|
|
- $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
|
|
|
- }
|
|
|
- return ['list' => $list, 'itemStat' => $itemStat];
|
|
|
- }
|
|
|
-
|
|
|
- //整合订单员工和供货商等信息 shish 2021.1.19
|
|
|
- //$isList 是否列表页
|
|
|
- public static function groupOrder($list, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
|
|
|
- {
|
|
|
- if (empty($list)) {
|
|
|
- return $list;
|
|
|
- }
|
|
|
-
|
|
|
- $customIds = array_unique(array_filter(array_column($list, 'customId')));
|
|
|
- $customInfo = CustomClass::getCustomByIds($customIds);
|
|
|
-
|
|
|
- $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
|
|
|
- $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
|
|
|
-
|
|
|
- foreach ($list as $key => $val) {
|
|
|
- $adminId = $val['adminId'] ?? 0;
|
|
|
- $list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
|
|
|
- $customId = $val['customId'] ?? 0;
|
|
|
- $list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
|
|
|
- $list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
|
|
|
- $list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
|
|
|
- $list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
|
|
|
- //显示列表页的操作按钮
|
|
|
- $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
|
|
|
- //显示进度条
|
|
|
- $list[$key]['progress'] = self::getShowProgress($showProgress, $val);
|
|
|
- //显示产品
|
|
|
- $showItem = self::getShowItem($showItem, $val);
|
|
|
- $list[$key]['product'] = $showItem['list'];
|
|
|
- $list[$key]['productStat'] = $showItem['itemStat'];
|
|
|
-
|
|
|
- //显示重选花材按钮
|
|
|
- $showResetItem = 1;
|
|
|
- //配送中和已完成的不显示重选花材按钮
|
|
|
- if (in_array($val['sendStatus'], [self::SEND_STATUS_SENDING, self::SEND_STATUS_COMPLETE])) {
|
|
|
- $showResetItem = 0;
|
|
|
- }
|
|
|
- $list[$key]['showResetItem'] = $showResetItem;
|
|
|
- //获取配送进展
|
|
|
- $list[$key]['expressProgress'] = OrderExpressClass::getProgress($showExpress, $val);
|
|
|
- }
|
|
|
- return $list;
|
|
|
- }
|
|
|
-
|
|
|
- //订单的验证 shish 2021.3.2
|
|
|
- public static function valid($info, $shopId)
|
|
|
- {
|
|
|
- if (empty($info)) {
|
|
|
- util::fail('没有找到订单');
|
|
|
- }
|
|
|
- if (isset($info['shopId']) && $info['shopId'] == $shopId) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- util::fail('没有权限操作的订单');
|
|
|
- }
|
|
|
-
|
|
|
- //获取订单详情 shish 2021.1.21
|
|
|
- public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
|
|
|
- {
|
|
|
- $info = self::getById($id);
|
|
|
- if (empty($info)) {
|
|
|
- util::fail('没有找到订单');
|
|
|
- }
|
|
|
- $respond = self::groupOrder([$info], $showButton, $showProgress, $showItem, $showExpress, $isList);
|
|
|
- return current($respond);
|
|
|
- }
|
|
|
-
|
|
|
- //订单到期未付款未确认的订单置成取消状态 shish 2021.1.23
|
|
|
- public static function setExpire($order)
|
|
|
- {
|
|
|
- $now = time();
|
|
|
- if (isset($order['deadline']) && $now > $order['deadline']) {
|
|
|
- if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
|
|
|
- $id = $order['id'];
|
|
|
- self::updateById($id, ['status' => self::ORDER_STATUS_CANCEL]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //本店送 shish 2021.1.24
|
|
|
- public static function selfSend($info)
|
|
|
- {
|
|
|
- if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_PAY) {
|
|
|
- util::fail('订单不是待配送状态!');
|
|
|
- }
|
|
|
- if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_SEND) {
|
|
|
- util::fail('订单不是待配送状态');
|
|
|
- }
|
|
|
- $id = $info['id'];
|
|
|
- self::updateById($id, [
|
|
|
- 'status' => self::ORDER_STATUS_SENDING,
|
|
|
- 'sendType' => self::SEND_TYPE_MYSELF,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- //自取和免发货流程的处理 shish 2021.1.24
|
|
|
- public static function withoutSend($order)
|
|
|
- {
|
|
|
- $id = $order['id'];
|
|
|
- if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
|
|
|
- util::fail('订单已完成');
|
|
|
- }
|
|
|
-
|
|
|
- //订单状态变更
|
|
|
- self::updateById($id, ['sendType' => self::SEND_TYPE_NO, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
|
|
|
- self::complete($order, self::TOTAL_FLOW);
|
|
|
-
|
|
|
- OrderSendClass::withoutSend($order);
|
|
|
-
|
|
|
- //待发货订单-1,完成订单+1
|
|
|
- $merchantId = $order['merchantId'];
|
|
|
- $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
- $asset->finishOrder += 1;
|
|
|
- $asset->unSendOrder -= 1;
|
|
|
- $asset->save();
|
|
|
-
|
|
|
- return self::TOTAL_FLOW;
|
|
|
- }
|
|
|
-
|
|
|
- //订单完成 shish 2020.3.12
|
|
|
- public static function complete($order, $currentFlow)
|
|
|
- {
|
|
|
- $id = $order['id'];
|
|
|
- self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ public static $baseFile = '\bizGhs\order\models\Order';
|
|
|
+
|
|
|
+ //已退款
|
|
|
+ const ORDER_STATUS_REFUND = 6;
|
|
|
+ //已取消
|
|
|
+ const ORDER_STATUS_CANCEL = 5;
|
|
|
+ //已完成
|
|
|
+ const ORDER_STATUS_COMPLETE = 4;
|
|
|
+ //配送中
|
|
|
+ const ORDER_STATUS_SENDING = 3;
|
|
|
+ //待配送
|
|
|
+ const ORDER_STATUS_UN_SEND = 2;
|
|
|
+ //待付款,待确认
|
|
|
+ const ORDER_STATUS_UN_PAY = 1;
|
|
|
+
|
|
|
+ //未确认
|
|
|
+ const SEND_TYPE_UNKNOWN = 1;
|
|
|
+ //自取
|
|
|
+ const SEND_TYPE_NO = 2;
|
|
|
+ //自己送
|
|
|
+ const SEND_TYPE_MYSELF = 3;
|
|
|
+ //快递送
|
|
|
+ const SEND_TYPE_THIRD = 4;
|
|
|
+
|
|
|
+ //待付款,待确认
|
|
|
+ const PAY_STATUS_UN_PAY = 1;
|
|
|
+ //已付款
|
|
|
+ const PAY_STATUS_HAS_PAY = 2;
|
|
|
+
|
|
|
+ //待配送
|
|
|
+ const SEND_STATUS_UN_SEND = 1;
|
|
|
+ //配送中
|
|
|
+ const SEND_STATUS_SENDING = 2;
|
|
|
+ //配送完成
|
|
|
+ const SEND_STATUS_COMPLETE = 3;
|
|
|
+
|
|
|
+ //订单总流程数
|
|
|
+ const TOTAL_FLOW = 3;
|
|
|
+
|
|
|
+ //添加订单 shish 2019.12.5
|
|
|
+ public static function addOrder($data)
|
|
|
+ {
|
|
|
+ $merchantId = $data['merchantId'] ?? 0;
|
|
|
+ $month = date("Ym");
|
|
|
+ $orderSn = orderSn::getGhsOrderSn();
|
|
|
+ $data['orderSn'] = $orderSn;
|
|
|
+ $data['payStatus'] = self::PAY_STATUS_UN_PAY;
|
|
|
+
|
|
|
+ //花材列表
|
|
|
+ $product = $data['product'];
|
|
|
+ OrderItemClass::replace($orderSn, $product);
|
|
|
+
|
|
|
+ //将花店每月的总订单数作为编号
|
|
|
+ $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
|
|
|
+ $data['sendNum'] = $riseNum;
|
|
|
+ $data['num'] = 1;
|
|
|
+ $data['smallNum'] = 1;
|
|
|
+ $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
|
|
|
+ //订单30分钟后过期
|
|
|
+ $data['deadline'] = date("Y-m-d H:i:s", (time() + 1800));
|
|
|
+ $data['sendCost'] = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
|
|
|
+ $return = self::add($data);
|
|
|
+ $orderId = $return['id'];
|
|
|
+
|
|
|
+ //全部订单+1,待付款订单+1
|
|
|
+ $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
+ $merchantAsset->unPayOrder += 1;
|
|
|
+ $merchantAsset->totalOrder += 1;
|
|
|
+ $merchantAsset->save();
|
|
|
+
|
|
|
+ //增加下单流程
|
|
|
+ $payTime = date("Y-m-d H:i:s");
|
|
|
+ $sendData = ['orderId' => $orderId, 'orderSn' => $orderSn, 'payTime' => $payTime];
|
|
|
+ OrderSendClass::placeOrder($sendData);
|
|
|
+
|
|
|
+ //扣库存 2021.2.23 linqh
|
|
|
+ foreach ($product as $key => $val) {
|
|
|
+ ProductClass::decreaseStock($val['productId'], $val['num'], $val['smallNum']);
|
|
|
+ }
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据订单编号查询 shish 2021.19
|
|
|
+ public static function getByOrderSn($orderSn)
|
|
|
+ {
|
|
|
+ return self::getByCondition(['orderSn' => $orderSn]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单列表 shish 2021.1.19
|
|
|
+ public static function getOrderList($where)
|
|
|
+ {
|
|
|
+ $data = self::getList('*', $where, 'addTime DESC');
|
|
|
+ $data['list'] = self::groupOrder($data['list'], true, false, false, false, true);
|
|
|
+ $data['allNum'] = 0;
|
|
|
+ $data['unPayNum'] = 0;
|
|
|
+ $data['unSendNum'] = 0;
|
|
|
+ $data['sendingNum'] = 0;
|
|
|
+ $data['finishNum'] = 0;
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ //显示操作按钮
|
|
|
+ public static function getShowButton($showButton, $isList, $order)
|
|
|
+ {
|
|
|
+ if ($showButton == false) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ //列表页显示的按钮
|
|
|
+ if ($isList) {
|
|
|
+ $item = ['type' => 'item', 'show' => 1, 'disable' => 1];
|
|
|
+ $send = ['type' => 'send', 'show' => 1, 'disable' => 0];
|
|
|
+ $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
|
|
|
+ if (in_array($order['status'], [self::ORDER_STATUS_UN_PAY, self::ORDER_STATUS_UN_SEND])) {
|
|
|
+ //待付款和待配送订单,改花材按钮才能点击
|
|
|
+ $item['disable'] = 0;
|
|
|
+ }
|
|
|
+ if ($order['sendType'] == self::SEND_TYPE_NO) {
|
|
|
+ //自取订单,发货按钮不可点
|
|
|
+ $send['disable'] = 1;
|
|
|
+ }
|
|
|
+ if ($order['sendType'] == self::SEND_TYPE_UNKNOWN) {
|
|
|
+ //只有未确认配送方式的订单才可点击自取
|
|
|
+ $selfGet['disable'] = 0;
|
|
|
+ }
|
|
|
+ return [$item, $send, $selfGet];
|
|
|
+ }
|
|
|
+
|
|
|
+ //待确认订单显示延期付和已付款
|
|
|
+ if ($order['status'] == OrderClass::ORDER_STATUS_UN_PAY) {
|
|
|
+ $debtPay = ['type' => 'debtPay', 'show' => 1, 'disable' => 0];
|
|
|
+ $hasPay = ['type' => 'hasPay', 'show' => 1, 'disable' => 0];
|
|
|
+ return [$debtPay, $hasPay];
|
|
|
+ }
|
|
|
+
|
|
|
+ //待配送订单显示打印、发货和自取
|
|
|
+ if ($order['status'] == OrderClass::ORDER_STATUS_UN_SEND) {
|
|
|
+ //没有花材的订单按钮全部置灰色不可点
|
|
|
+ $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
|
|
|
+ $item = ['type' => 'item', 'show' => 1, 'disable' => 1];
|
|
|
+ $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
|
|
|
+ $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
|
|
|
+ if ($order['hasItem'] == 2) {
|
|
|
+ return [$print, $item, $selfGet, $send];
|
|
|
+ }
|
|
|
+ $print['disable'] = 0;
|
|
|
+ $selfGet['disable'] = 0;
|
|
|
+ $send['disable'] = 0;
|
|
|
+ $item['disable'] = 0;
|
|
|
+ return [$print, $item, $selfGet, $send];
|
|
|
+ }
|
|
|
+ //配送中显示按钮
|
|
|
+ if ($order['status'] == OrderClass::ORDER_STATUS_SENDING) {
|
|
|
+ $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
|
|
|
+ $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
|
|
|
+ return [$print, $send];
|
|
|
+ }
|
|
|
+ if ($order['status'] == OrderClass::ORDER_STATUS_COMPLETE) {
|
|
|
+ $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
|
|
|
+ $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
|
|
|
+ //自取订单不显示发货按钮
|
|
|
+ if ($order['sendType'] == self::SEND_TYPE_NO) {
|
|
|
+ $send['show'] = 0;
|
|
|
+ }
|
|
|
+ return [$print, $send];
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //显示进度 shish 2021.3.1
|
|
|
+ public static function getShowProgress($showProgress, $order)
|
|
|
+ {
|
|
|
+ if ($showProgress == false) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $create = ['name' => '创建', 'complete' => 1];
|
|
|
+ $unConfirm = ['name' => '待确认', 'complete' => 0];
|
|
|
+ if ($order['status'] > 0) {
|
|
|
+ $unConfirm['complete'] = 1;
|
|
|
+ }
|
|
|
+ $out = ['name' => '出库', 'complete' => 0];
|
|
|
+ if ($order['status'] > 1) {
|
|
|
+ $out['complete'] = 1;
|
|
|
+ }
|
|
|
+ return [$create, $unConfirm, $out];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getShowItem($showItem, $order)
|
|
|
+ {
|
|
|
+ if ($showItem == false) {
|
|
|
+ return ['list' => [], 'itemStat' => []];
|
|
|
+ }
|
|
|
+ $orderSn = $order['orderSn'];
|
|
|
+ $list = OrderItemClass::getOrderItem($orderSn);
|
|
|
+ $totalPrice = 0;
|
|
|
+ $totalBigNum = 0;
|
|
|
+ $totalSmallNum = 0;
|
|
|
+ $kind = 0;
|
|
|
+ $itemStat = [];
|
|
|
+ if (!empty($list)) {
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $list[$key]['property'] = $val['rank'] . '级';
|
|
|
+ $price = $val['price'];
|
|
|
+ $totalPrice = stringUtil::calcAdd($totalPrice, $price);
|
|
|
+ $kind++;
|
|
|
+ $currentBigNum = $val['bigNum'];
|
|
|
+ $currentSmallNum = $val['smallNum'];
|
|
|
+ $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
|
|
|
+ $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
|
|
|
+ }
|
|
|
+ $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
|
|
|
+ }
|
|
|
+ return ['list' => $list, 'itemStat' => $itemStat];
|
|
|
+ }
|
|
|
+
|
|
|
+ //整合订单员工和供货商等信息 shish 2021.1.19
|
|
|
+ //$isList 是否列表页
|
|
|
+ public static function groupOrder($list, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
|
|
|
+ {
|
|
|
+ if (empty($list)) {
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ $customIds = array_unique(array_filter(array_column($list, 'customId')));
|
|
|
+ $customInfo = CustomClass::getCustomByIds($customIds);
|
|
|
+
|
|
|
+ $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
|
|
|
+ $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
|
|
|
+
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $adminId = $val['adminId'] ?? 0;
|
|
|
+ $list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
|
|
|
+ $customId = $val['customId'] ?? 0;
|
|
|
+ $list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
|
|
|
+ $list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
|
|
|
+ $list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
|
|
|
+ $list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
|
|
|
+ //显示列表页的操作按钮
|
|
|
+ $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
|
|
|
+ //显示进度条
|
|
|
+ $list[$key]['progress'] = self::getShowProgress($showProgress, $val);
|
|
|
+ //显示产品
|
|
|
+ $showItem = self::getShowItem($showItem, $val);
|
|
|
+ $list[$key]['product'] = $showItem['list'];
|
|
|
+ $list[$key]['productStat'] = $showItem['itemStat'];
|
|
|
+
|
|
|
+ //显示重选花材按钮
|
|
|
+ $showResetItem = 1;
|
|
|
+ //配送中和已完成的不显示重选花材按钮
|
|
|
+ if (in_array($val['sendStatus'], [self::SEND_STATUS_SENDING, self::SEND_STATUS_COMPLETE])) {
|
|
|
+ $showResetItem = 0;
|
|
|
+ }
|
|
|
+ $list[$key]['showResetItem'] = $showResetItem;
|
|
|
+ //获取配送进展
|
|
|
+ $list[$key]['expressProgress'] = OrderExpressClass::getProgress($showExpress, $val);
|
|
|
+ }
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单的验证 shish 2021.3.2
|
|
|
+ public static function valid($info, $shopId)
|
|
|
+ {
|
|
|
+ if (empty($info)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if (isset($info['shopId']) && $info['shopId'] == $shopId) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ util::fail('没有权限操作的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取订单详情 shish 2021.1.21
|
|
|
+ public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
|
|
|
+ {
|
|
|
+ $info = self::getById($id);
|
|
|
+ if (empty($info)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ $respond = self::groupOrder([$info], $showButton, $showProgress, $showItem, $showExpress, $isList);
|
|
|
+ return current($respond);
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单到期未付款未确认的订单置成取消状态 shish 2021.1.23
|
|
|
+ public static function setExpire($order)
|
|
|
+ {
|
|
|
+ $now = time();
|
|
|
+ if (isset($order['deadline']) && $now > $order['deadline']) {
|
|
|
+ if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
|
|
|
+ $id = $order['id'];
|
|
|
+ self::updateById($id, ['status' => self::ORDER_STATUS_CANCEL]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //确认送达 shish 2021.3.4
|
|
|
+ public static function reach($order)
|
|
|
+ {
|
|
|
+ if ($order['status'] != OrderClass::ORDER_STATUS_SENDING) {
|
|
|
+ util::fail('订单没有在配送状态');
|
|
|
+ }
|
|
|
+ self::updateById($id, ['status' => self::ORDER_STATUS_COMPLETE, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
|
|
|
+ OrderSendClass::reach($order);
|
|
|
+ }
|
|
|
+
|
|
|
+ //本店送 shish 2021.1.24
|
|
|
+ public static function selfSend($info)
|
|
|
+ {
|
|
|
+ if ($info['status'] == self::ORDER_STATUS_UN_PAY) {
|
|
|
+ util::fail('订单未付款');
|
|
|
+ }
|
|
|
+ if ($info['status'] != self::ORDER_STATUS_UN_SEND) {
|
|
|
+ util::fail('不是待配送订单');
|
|
|
+ }
|
|
|
+ $id = $info['id'];
|
|
|
+ self::updateById($id, ['status' => self::ORDER_STATUS_SENDING, 'sendType' => self::SEND_TYPE_MYSELF,]);
|
|
|
+ OrderSendClass::selfSend($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //自取和免发货流程的处理 shish 2021.1.24
|
|
|
+ public static function withoutSend($order)
|
|
|
+ {
|
|
|
+ $id = $order['id'];
|
|
|
+ if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
|
|
|
+ util::fail('订单已完成');
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单状态变更
|
|
|
+ self::updateById($id, ['sendType' => self::SEND_TYPE_NO, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
|
|
|
+ self::complete($order, self::TOTAL_FLOW);
|
|
|
+
|
|
|
+ OrderSendClass::withoutSend($order);
|
|
|
+
|
|
|
+ //待发货订单-1,完成订单+1
|
|
|
+ $merchantId = $order['merchantId'];
|
|
|
+ $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
+ $asset->finishOrder += 1;
|
|
|
+ $asset->unSendOrder -= 1;
|
|
|
+ $asset->save();
|
|
|
+
|
|
|
+ return self::TOTAL_FLOW;
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单完成 shish 2020.3.12
|
|
|
+ public static function complete($order, $currentFlow)
|
|
|
+ {
|
|
|
+ $id = $order['id'];
|
|
|
+ self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|