'上午', 1 => '下午', 2 => '晚上']; //优惠金额 public static $randDiscount = [ 50 => [1, 3], 100 => [5, 9], 300 => [10, 15], 500 => [16, 18], 1000 => [18, 30], 20000 => [90, 100], ]; //所有的欠款采购单 ssh 2021.1.26 public static function getDebtList($where) { $list = self::getAllList('*', $where, 'addTime DESC'); if (!empty($list)) { foreach ($list as $key => $value) { $debtPrice = $value['debtPrice'] ?? 0; $remainDebtPrice = $value['remainDebtPrice'] ?? 0; $hasPayDebt = 0; if ($debtPrice > $remainDebtPrice) { $hasPayDebt = bcsub($debtPrice, $remainDebtPrice, 2); } $list[$key]['hasPayDebt'] = floatval($hasPayDebt); } } $count = self::getCount($where); return ['list' => $list, 'debtNum' => $count]; } //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014 public static function getDistanceFee($userLat, $userLong, $shopLat, $shopLong, $weight) { //基础配送费8元,0-5公里,每公里+1元,5-100公里,6元起,每公里+2元 //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元 //00:00 - 06:00 +6元,22:00-24:00 +4元 //恶劣天气,下单高峰期会临时调整价格 //起步价 $baseFee = 10; $distance = mapUtil::calculateDistance($userLong, $userLat, $shopLong, $shopLat); //0-5公里,每公里+1元,5-100公里,6元起,每公里+2元 $formatDistance = ceil($distance / 1000); $startKiloFee = 6; if ($formatDistance < 5) { $addDistanceFee = bcmul($formatDistance, 2); } elseif ($formatDistance == 5) { $addDistanceFee = $startKiloFee; } else { $overKilo = bcsub($formatDistance, 5); $overFee = bcmul($overKilo, 3); $addDistanceFee = bcadd($startKiloFee, $overFee); } //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元 $formatWeight = ceil($weight); if ($formatWeight > 15) { $addWeightFee = 20; } elseif ($formatWeight >= 10 && $formatWeight <= 15) { $addWeightFee = 12; } elseif ($formatWeight >= 5 && $formatWeight < 10) { $overWeight = bcsub($formatWeight, 4); $addWeightFee = bcmul($overWeight, 2); } else { $addWeightFee = 0; } $addFee = bcadd($addDistanceFee, $addWeightFee, 2); $totalFee = bcadd($baseFee, $addFee, 2); //特殊时段费 $timeFee = 0; $hour = date("G"); //22:00 - 24:00 +4元 if (in_array($hour, [22, 23])) { $timeFee = 4; } //00:00 - 06:00 +6元 if (in_array($hour, [0, 1, 2, 3, 4, 5])) { $timeFee = 6; } $totalFee = bcadd($totalFee, $timeFee, 2); //恶劣天气和下单高峰费用 $weatherFee = 0; $totalFee = bcadd($totalFee, $weatherFee, 2); $showDistance = sprintf("%.1f", ($distance / 1000)); //noticeUtil::push("零售商城 距离:{$distance} {$showDistance} 重量:{$weight} 费用:{$totalFee}", '15280215347'); //return ['distance' => 0, 'showDistance' => 0, 'fee' => 0]; return ['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $totalFee]; } //添加订单 ssh 2019.12.5 public static function addOrder($data) { $data['orderSn'] = isset($data['orderSn']) ? $data['orderSn'] : orderSn::getOrderSn(); $data['payStatus'] = 0; $shopId = $data['shopId'] ?? 0; $shop = ShopClass::getLockById($shopId); if (empty($shop)) { util::fail('没有找到门店85'); } $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息呢!'); } $riseNum = StatOrderCountClass::addOrder($shop, $main); $address = $data['address'] ?? ''; $floor = $data['floor'] ?? ''; $fullAddress = $address . $floor; $data['fullAddress'] = $fullAddress; //将花店每月的总订单数作为编号 $data['sendNum'] = date('j') . $riseNum; $return = self::add($data, true); $main->unPayOrder += 1; $main->totalOrder += 1; $main->save(); return $return; } public static function getByOrderSn($orderSn) { return self::getByCondition(['orderSn' => $orderSn]); } //评价 ssh 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 []; } $orderSn = $order['orderSn'] ?? ''; if (empty($orderSn)) { return []; } $goodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*'); if (!empty($goodsList)) { foreach ($goodsList as $key => $val) { $shortCover = $val['cover'] ?? ''; $cover = imgUtil::groupImg($shortCover); $goodsList[$key]['cover'] = $cover; $goodsList[$key]['shortCover'] = $shortCover; } } $order['goodsInfoList'] = $goodsList; $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*'); if (!empty($itemList)) { foreach ($itemList as $key => $item) { $shortCover = $item['cover'] ?? ''; $cover = imgUtil::groupImg($shortCover); $itemList[$key]['cover'] = $cover; $itemList[$key]['shortCover'] = $shortCover; } } $order['itemList'] = $itemList; return $order; } //根据订单查询 ssh 2020.1.4 public static function getOrderBySn($orderSn) { $order = self::getByCondition(['orderSn' => $orderSn]); if (empty($order)) { return []; } $goodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*'); if (!empty($goodsList)) { foreach ($goodsList as $key => $val) { $shortCover = $val['cover'] ?? ''; $cover = imgUtil::groupImg($shortCover); $goodsList[$key]['cover'] = $cover; } } $order['goodsInfoList'] = $goodsList; $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*'); if (!empty($itemList)) { foreach ($itemList as $key => $item) { $shortCover = $item['cover'] ?? ''; $cover = imgUtil::groupImg($shortCover); $itemList[$key]['cover'] = $cover; } } $order['itemList'] = $itemList; return $order; } //返回随机优惠金额 ssh 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; } //订单完成 ssh 2020.3.12 public static function complete($order, $currentFlow) { $id = $order['id']; self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]); } //转化出送到时间 ssh 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 ssh 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); } } } } //订单到期未付款的订单置成取消状态 ssh 2020.5.25 public static function setExpire($order) { $now = time(); if (!empty($order['deadline']) && $now > $order['deadline']) { if ($order['status'] == 0) { $id = $order['id']; OrderClass::updateById($id, ['status' => 4]); } } } //支付成功需要处理的流程 ssh 2020.5.25 public static function payAfter($order, $updateData) { $orderId = $order['id']; $orderSn = $order['orderSn']; $now = time(); self::updateById($orderId, $updateData); //发货流程的完成下单 OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now, 'orderSn' => $orderSn]); $sjId = $order['sjId']; $asset = MerchantAssetClass::getBySjId($sjId); //增加订单数 StatOrderClass::addOrder($sjId, $asset); //如果门店和朋友圈订单并且没有填写收花人的直接将订单置为自取并且是完成状态 if (isset($order['fromType']) && in_array($order['fromType'], [0, 2])) { if (isset($order['receiveMobile']) && isset($order['address'])) { if (empty($order['receiveMobile']) && empty($order['address'])) { OrderSendClass::withoutSend($order); } } } } }