|
|
@@ -14,228 +14,228 @@ 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));
|
|
|
- $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);
|
|
|
-
|
|
|
- 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);
|
|
|
- $data['allNum'] = 0;
|
|
|
- $data['unPayNum'] = 0;
|
|
|
- $data['unSendNum'] = 0;
|
|
|
- $data['sendingNum'] = 0;
|
|
|
- $data['finishNum'] = 0;
|
|
|
- return $data;
|
|
|
- }
|
|
|
-
|
|
|
- //整合订单员工和供货商等信息 shish 2021.1.19
|
|
|
- public static function groupOrder($list, $showButton = false, $showProgress = false, $showProduct = 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'] ?? '';
|
|
|
- if ($showButton) {
|
|
|
- $list[$key]['buttonList'] = [
|
|
|
- ['type' => 'item', 'show' => 1, 'disable' => 1],
|
|
|
- ['type' => 'send', 'show' => 1, 'disable' => 0],
|
|
|
- ['type' => 'selfGet', 'show' => 1, 'disable' => 0],
|
|
|
- ];
|
|
|
- }
|
|
|
- if ($showProgress) {
|
|
|
- $list[$key]['progress'] = [
|
|
|
- ['name' => '创建', 'complete' => 1],
|
|
|
- ['name' => '待确认', 'complete' => 0],
|
|
|
- ['name' => '出库', 'complete' => 0],
|
|
|
- ];
|
|
|
- }
|
|
|
- if ($showProduct) {
|
|
|
- $list[$key]['product'] = [
|
|
|
- [
|
|
|
- 'cover' => 'https://img.huahb.com/uploads/12358/202101/13/0e713d46064ca89b1fb11095b710f244_small.jpeg',
|
|
|
- 'name' => '昆明B级红玫瑰卡罗拉', 'property' => 'B级', 'price' => '8.45', 'bigNum' => 2, 'smallNum' => 10
|
|
|
- ],
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- return $list;
|
|
|
- }
|
|
|
-
|
|
|
- public static function valid($info, $shopId)
|
|
|
- {
|
|
|
- if (isset($info['shopId']) && $info['shopId'] == $shopId) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- util::fail('没有权限操作的订单');
|
|
|
- }
|
|
|
-
|
|
|
- //获取订单详情 shish 2021.1.21
|
|
|
- public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showProduct = false)
|
|
|
- {
|
|
|
- $info = self::getById($id);
|
|
|
- $respond = self::groupOrder([$info], $showButton, $showProgress, $showProduct);
|
|
|
- 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_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));
|
|
|
+ $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);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ $data['allNum'] = 0;
|
|
|
+ $data['unPayNum'] = 0;
|
|
|
+ $data['unSendNum'] = 0;
|
|
|
+ $data['sendingNum'] = 0;
|
|
|
+ $data['finishNum'] = 0;
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ //整合订单员工和供货商等信息 shish 2021.1.19
|
|
|
+ public static function groupOrder($list, $showButton = false, $showProgress = false, $showProduct = 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'] ?? '';
|
|
|
+ if ($showButton) {
|
|
|
+ $list[$key]['buttonList'] = [
|
|
|
+ ['type' => 'item', 'show' => 1, 'disable' => 1],
|
|
|
+ ['type' => 'send', 'show' => 1, 'disable' => 0],
|
|
|
+ ['type' => 'selfGet', 'show' => 1, 'disable' => 0],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($showProgress) {
|
|
|
+ $list[$key]['progress'] = [
|
|
|
+ ['name' => '创建', 'complete' => 1],
|
|
|
+ ['name' => '待确认', 'complete' => 0],
|
|
|
+ ['name' => '出库', 'complete' => 0],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($showProduct) {
|
|
|
+ $list[$key]['product'] = [
|
|
|
+ [
|
|
|
+ 'cover' => 'https://img.huahb.com/uploads/12358/202101/13/0e713d46064ca89b1fb11095b710f244_small.jpeg',
|
|
|
+ 'name' => '昆明B级红玫瑰卡罗拉', 'property' => 'B级', 'price' => '8.45', 'bigNum' => 2, 'smallNum' => 10, 'id' => 16,
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function valid($info, $shopId)
|
|
|
+ {
|
|
|
+ if (isset($info['shopId']) && $info['shopId'] == $shopId) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ util::fail('没有权限操作的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取订单详情 shish 2021.1.21
|
|
|
+ public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showProduct = false)
|
|
|
+ {
|
|
|
+ $info = self::getById($id);
|
|
|
+ $respond = self::groupOrder([$info], $showButton, $showProgress, $showProduct);
|
|
|
+ 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]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|