|
|
@@ -17,174 +17,175 @@ use biz\base\classes\BaseClass;
|
|
|
|
|
|
class OrderClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
- public static $baseFile = '\biz\order\models\Order';
|
|
|
-
|
|
|
- //已退款
|
|
|
- const ORDER_STATUS_REFUND = 6;
|
|
|
- //完成
|
|
|
- const ORDER_STATUS_COMPLETE = 5;
|
|
|
- //已取消
|
|
|
- const ORDER_STATUS_CANCEL = 4;
|
|
|
- //待通知
|
|
|
- const ORDER_STATUS_UN_NOTICE = 3;
|
|
|
- //配送中
|
|
|
- const ORDER_STATUS_SENDING = 2;
|
|
|
- //待配送
|
|
|
- const ORDER_STATUS_UN_SEND = 1;
|
|
|
- //待付款
|
|
|
- const ORDER_STATUS_UN_PAY = 0;
|
|
|
- //订单总流程数
|
|
|
- const ORDER_TOTAL_FLOW = 5;
|
|
|
-
|
|
|
- //未确认配送方式
|
|
|
- const SEND_TYPE_UNKNOWN = 0;
|
|
|
- //自取
|
|
|
- const SEND_TYPE_NO = 1;
|
|
|
- //自己送
|
|
|
- const SEND_TYPE_MYSELF = 2;
|
|
|
- //代送
|
|
|
- const SEND_TYPE_OTHER = 3;
|
|
|
-
|
|
|
- //送达时间段
|
|
|
- public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
|
|
|
-
|
|
|
- //优惠金额
|
|
|
- public static $randDiscount = [
|
|
|
- 50 => [1, 3],
|
|
|
- 100 => [5, 9],
|
|
|
- 300 => [10, 15],
|
|
|
- 500 => [16, 18],
|
|
|
- 1000 => [18, 30],
|
|
|
- 20000 => [90, 100],
|
|
|
- ];
|
|
|
-
|
|
|
- //添加订单 shish 2019.12.5
|
|
|
- public static function addOrder($data)
|
|
|
- {
|
|
|
- $date = date("Y-m-d H:i:s");
|
|
|
- $merchantId = $data['merchantId'];
|
|
|
- $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
|
|
|
- $data['payStatus'] = 0;
|
|
|
- $data['createTime'] = $date;
|
|
|
- $data['addTime'] = time();
|
|
|
-
|
|
|
- $month = date("Ym");
|
|
|
- $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
|
|
|
- //将花店每月的总订单数作为编号
|
|
|
- $data['sendNum'] = $riseNum;
|
|
|
- $data['totalFlow'] = OrderSendClass::TOTAL_FLOW;
|
|
|
- $return = self::add($data);
|
|
|
-
|
|
|
- //全部订单+1,待付款订单+1
|
|
|
- $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
- $merchantAsset->unPayOrder += 1;
|
|
|
- $merchantAsset->totalOrder += 1;
|
|
|
- $merchantAsset->save();
|
|
|
-
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- public static function getByOrderSn($orderSn)
|
|
|
- {
|
|
|
- return self::getByCondition(['orderSn' => $orderSn]);
|
|
|
- }
|
|
|
-
|
|
|
- //评价 shish 2019.12.16
|
|
|
- public static function comment($data)
|
|
|
- {
|
|
|
- $id = $data['id'];
|
|
|
- unset($data['id']);
|
|
|
- return self::updateById($id, $data);
|
|
|
- }
|
|
|
-
|
|
|
- //订单
|
|
|
- public static function getOrderById($id)
|
|
|
- {
|
|
|
- $order = self::getById($id);
|
|
|
- if (empty($order)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
|
|
|
- return $order;
|
|
|
- }
|
|
|
-
|
|
|
- //根据订单查询 shish 2020.1.4
|
|
|
- public static function getOrderBySn($orderSn)
|
|
|
- {
|
|
|
- $order = self::getByCondition(['orderSn' => $orderSn]);
|
|
|
- if (empty($order)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- $id = $order['id'];
|
|
|
- $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
|
|
|
- return $order;
|
|
|
- }
|
|
|
-
|
|
|
- //返回随机优惠金额 shish 2019.9.12
|
|
|
- public static function getRandDiscount($amount)
|
|
|
- {
|
|
|
- if ($amount <= 0) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- krsort($randDiscount);
|
|
|
- $rand = 0;
|
|
|
- foreach ($randDiscount as $currentAmount => $val) {
|
|
|
- if ($amount >= $currentAmount) {
|
|
|
- $rand = rand($val[0], $val[1]);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return $rand / 10;
|
|
|
- }
|
|
|
-
|
|
|
- //订单完成 shish 2020.3.12
|
|
|
- public static function complete($order)
|
|
|
- {
|
|
|
- $id = $order['id'];
|
|
|
- self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => 4]);
|
|
|
- $userId = $order['userId'];
|
|
|
- $user = UserClass::getById($userId);
|
|
|
- $merchantId = $order['merchantId'];
|
|
|
- $merchant = MerchantClass::getById($merchantId);
|
|
|
- //完成通知客户
|
|
|
- InformUserClass::sendComplete($user, $order, $merchant);
|
|
|
- //完成通知管理员
|
|
|
- InformAdminClass::sendComplete($order, $merchant);
|
|
|
- }
|
|
|
-
|
|
|
- //转化出送到时间 shish 2020.3.15
|
|
|
- public static function getReachTime($order)
|
|
|
- {
|
|
|
- $reachTime = '';
|
|
|
- if (isset($order['reachDate']) && !empty($order['reachDate'])) {
|
|
|
- $prev = date("n-j", strtotime($order['reachDate']));
|
|
|
- $periodData = self::$reachPeriod;
|
|
|
- $periodKey = $order['reachPeriod'];
|
|
|
- $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
|
|
|
- $reachTime = $prev . ' ' . $period;
|
|
|
- }
|
|
|
- return $reachTime;
|
|
|
- }
|
|
|
-
|
|
|
- //支付成功获取unionId shish 2020.5.12
|
|
|
- public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
|
|
|
- {
|
|
|
- $mcId = $merchantExtend['wxPayMerchantId'];
|
|
|
- $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
|
|
|
- $unionId = isset($user['unionId']) ? $user['unionId'] : '';
|
|
|
- $userId = $user['id'];
|
|
|
- if (empty($unionId)) {
|
|
|
- $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
|
|
|
- if (!empty($unionId)) {
|
|
|
- $findUser = UserClass::getByUnionId($unionId);
|
|
|
- if (empty($findUser)) {
|
|
|
- UserClass::updateByCondition(['id' => $userId], ['unionId' => $unionId]);
|
|
|
- } else {
|
|
|
- UserClass::mergeUser($findUser, $user);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ public static $baseFile = '\biz\order\models\Order';
|
|
|
+
|
|
|
+ //已退款
|
|
|
+ const ORDER_STATUS_REFUND = 6;
|
|
|
+ //完成
|
|
|
+ const ORDER_STATUS_COMPLETE = 5;
|
|
|
+ //已取消
|
|
|
+ const ORDER_STATUS_CANCEL = 4;
|
|
|
+ //待通知
|
|
|
+ const ORDER_STATUS_UN_NOTICE = 3;
|
|
|
+ //配送中
|
|
|
+ const ORDER_STATUS_SENDING = 2;
|
|
|
+ //待配送
|
|
|
+ const ORDER_STATUS_UN_SEND = 1;
|
|
|
+ //待付款
|
|
|
+ const ORDER_STATUS_UN_PAY = 0;
|
|
|
+ //订单总流程数
|
|
|
+ const ORDER_TOTAL_FLOW = 5;
|
|
|
+
|
|
|
+ //未确认配送方式
|
|
|
+ const SEND_TYPE_UNKNOWN = 0;
|
|
|
+ //自取
|
|
|
+ const SEND_TYPE_NO = 1;
|
|
|
+ //自己送
|
|
|
+ const SEND_TYPE_MYSELF = 2;
|
|
|
+ //代送
|
|
|
+ const SEND_TYPE_OTHER = 3;
|
|
|
+
|
|
|
+ //送达时间段
|
|
|
+ public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
|
|
|
+
|
|
|
+ //优惠金额
|
|
|
+ public static $randDiscount = [
|
|
|
+ 50 => [1, 3],
|
|
|
+ 100 => [5, 9],
|
|
|
+ 300 => [10, 15],
|
|
|
+ 500 => [16, 18],
|
|
|
+ 1000 => [18, 30],
|
|
|
+ 20000 => [90, 100],
|
|
|
+ ];
|
|
|
+
|
|
|
+ //添加订单 shish 2019.12.5
|
|
|
+ public static function addOrder($data)
|
|
|
+ {
|
|
|
+ $date = date("Y-m-d H:i:s");
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
+ $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
|
|
|
+ $data['payStatus'] = 0;
|
|
|
+ $data['createTime'] = $date;
|
|
|
+ $data['addTime'] = time();
|
|
|
+
|
|
|
+ $month = date("Ym");
|
|
|
+ $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
|
|
|
+ //将花店每月的总订单数作为编号
|
|
|
+ $data['sendNum'] = $riseNum;
|
|
|
+ $data['totalFlow'] = OrderSendClass::TOTAL_FLOW;
|
|
|
+ $return = self::add($data);
|
|
|
+
|
|
|
+ //全部订单+1,待付款订单+1
|
|
|
+ $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
|
|
|
+ $merchantAsset->unPayOrder += 1;
|
|
|
+ $merchantAsset->totalOrder += 1;
|
|
|
+ $merchantAsset->save();
|
|
|
+
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getByOrderSn($orderSn)
|
|
|
+ {
|
|
|
+ return self::getByCondition(['orderSn' => $orderSn]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //评价 shish 2019.12.16
|
|
|
+ public static function comment($data)
|
|
|
+ {
|
|
|
+ $id = $data['id'];
|
|
|
+ unset($data['id']);
|
|
|
+ return self::updateById($id, $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单
|
|
|
+ public static function getOrderById($id)
|
|
|
+ {
|
|
|
+ $order = self::getById($id);
|
|
|
+ if (empty($order)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
|
|
|
+ return $order;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据订单查询 shish 2020.1.4
|
|
|
+ public static function getOrderBySn($orderSn)
|
|
|
+ {
|
|
|
+ $order = self::getByCondition(['orderSn' => $orderSn]);
|
|
|
+ if (empty($order)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $id = $order['id'];
|
|
|
+ $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
|
|
|
+ return $order;
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回随机优惠金额 shish 2019.9.12
|
|
|
+ public static function getRandDiscount($amount)
|
|
|
+ {
|
|
|
+ if ($amount <= 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ $randDiscount = self::$randDiscount;
|
|
|
+ krsort($randDiscount);
|
|
|
+ $rand = 0;
|
|
|
+ foreach ($randDiscount as $currentAmount => $val) {
|
|
|
+ if ($amount >= $currentAmount) {
|
|
|
+ $rand = rand($val[0], $val[1]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $rand / 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单完成 shish 2020.3.12
|
|
|
+ public static function complete($order)
|
|
|
+ {
|
|
|
+ $id = $order['id'];
|
|
|
+ self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => 4]);
|
|
|
+ $userId = $order['userId'];
|
|
|
+ $user = UserClass::getById($userId);
|
|
|
+ $merchantId = $order['merchantId'];
|
|
|
+ $merchant = MerchantClass::getById($merchantId);
|
|
|
+ //完成通知客户
|
|
|
+ InformUserClass::sendComplete($user, $order, $merchant);
|
|
|
+ //完成通知管理员
|
|
|
+ InformAdminClass::sendComplete($order, $merchant);
|
|
|
+ }
|
|
|
+
|
|
|
+ //转化出送到时间 shish 2020.3.15
|
|
|
+ public static function getReachTime($order)
|
|
|
+ {
|
|
|
+ $reachTime = '';
|
|
|
+ if (isset($order['reachDate']) && !empty($order['reachDate'])) {
|
|
|
+ $prev = date("n-j", strtotime($order['reachDate']));
|
|
|
+ $periodData = self::$reachPeriod;
|
|
|
+ $periodKey = $order['reachPeriod'];
|
|
|
+ $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
|
|
|
+ $reachTime = $prev . ' ' . $period;
|
|
|
+ }
|
|
|
+ return $reachTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ //支付成功获取unionId shish 2020.5.12
|
|
|
+ public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
|
|
|
+ {
|
|
|
+ $mcId = $merchantExtend['wxPayMerchantId'];
|
|
|
+ $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
|
|
|
+ $unionId = isset($user['unionId']) ? $user['unionId'] : '';
|
|
|
+ $userId = $user['id'];
|
|
|
+ if (empty($unionId)) {
|
|
|
+ $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
|
|
|
+ if (!empty($unionId)) {
|
|
|
+ $findUser = UserClass::getByUnionId($unionId);
|
|
|
+ if (empty($findUser)) {
|
|
|
+ UserClass::updateByCondition(['id' => $userId], ['unionId' => $unionId]);
|
|
|
+ } else {
|
|
|
+ UserClass::mergeUser($findUser, $user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|