delete('user_order_' . $uid . $unique); return true; } /** * 设置默认地址、更新自提人信息 * @return bool */ public function updateUser($orderInfo, $group) { try { /** @var StoreOrderCreateServices $orderCreate */ $orderCreate = app()->make(StoreOrderCreateServices::class); $orderCreate->updateUserAddress($orderInfo, $group); } catch (\Throwable $e) { response_log_write([ 'message' => '设置用户默认地址信息失败,失败原因:' . $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine() ]); } try { $uid = (int)($orderInfo['uid'] ?? 0); if ($uid) { /** @var UserServices $userService */ $userService = app()->make(UserServices::class); $userInfo = $userService->getUserCacheInfo($uid); //记录自提人电话和姓名 if ($userInfo['real_name'] != $orderInfo['real_name'] || $userInfo['record_phone'] != $orderInfo['user_phone']) { $userService->update(['uid' => $uid], ['real_name' => $orderInfo['real_name'], 'record_phone' => $orderInfo['user_phone']]); $userService->cacheTag()->clear(); } } } catch (\Throwable $e) { response_log_write([ 'message' => '更新用户自提人信息失败,失败原因:' . $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine() ]); } return true; } /** * 删除购物车 * @return bool */ public function delCart($group) { try { /** @var StoreOrderCreateServices $orderCreate */ $orderCreate = app()->make(StoreOrderCreateServices::class); $orderCreate->delCart($group); } catch (\Throwable $e) { response_log_write([ 'message' => '删除购物车失败,失败原因:' . $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine() ]); } return true; } /** * 删除购物车和更新用户收货地址 * @return bool */ public function delCartAndUpdateAddres($orderInfo, $group) { try { /** @var StoreOrderCreateServices $orderCreate */ $orderCreate = app()->make(StoreOrderCreateServices::class); $orderCreate->orderCreateAfter($orderInfo, $group); } catch (\Throwable $e) { Log::error('更新用户信息和删除购物车失败,失败原因:' . $e->getMessage()); } return true; } /** * 订单后置处理 * @param $userInfo * @param $orderInfo * @param $data * @param $activity * @return bool */ public function compute($orderInfo, $data, $activity) { if (!$orderInfo) { return true; } try { $uid = (int)$orderInfo['uid']; $userInfo = []; if ($uid) { /** @var UserServices $userService */ $userService = app()->make(UserServices::class); $userInfo = $userService->getUserCacheInfo($uid); } $orderId = (int)$orderInfo['id']; $spread_uid = $spread_two_uid = 0; $cartInfo = $data['cartInfo'] ?? []; $priceData = $data['priceData'] ?? []; $addressId = $data['addressId'] ?? 0; /** @var StoreOrderCreateServices $createService */ $createService = app()->make(StoreOrderCreateServices::class); $spread_ids = []; if ($cartInfo && $priceData) { /** @var StoreOrderCartInfoServices $cartServices */ $cartServices = app()->make(StoreOrderCartInfoServices::class); [$cartInfo, $spread_ids] = $createService->computeOrderProductTruePrice($orderInfo, $cartInfo, $priceData, $addressId, $uid, $userInfo); $cartServices->updateCartInfo($orderId, $cartInfo); } $orderData = []; /** @var UserServices $userServices */ $userServices = app()->make(UserServices::class); if ($spread_ids) { [$spread_uid, $spread_two_uid] = $spread_ids; } else { $spread_uid = $userServices->getSpreadUid($uid); if ($spread_uid > 0 && sys_config('brokerage_level', 2) == 2) { $spread_two_uid = $userServices->getSpreadUid($spread_uid, [], false); } } if ($spread_uid > 0) { $orderData['spread_uid'] = $spread_uid; } if ($spread_two_uid > 0) { $orderData['spread_two_uid'] = $spread_two_uid; } if ($cartInfo && (isset($activity['type']) && !in_array($activity['type'], [1, 2, 3, 5, 8]))) { /** @var StoreOrderComputedServices $orderComputed */ $orderComputed = app()->make(StoreOrderComputedServices::class); if ($userServices->checkUserPromoter($spread_uid)) $orderData['one_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'one_brokerage', false); if ($userServices->checkUserPromoter($spread_two_uid)) $orderData['two_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'two_brokerage', false); } if ($orderData) $createService->update(['id' => $orderId], $orderData); } catch (\Throwable $e) { Log::error('计算订单实际优惠、积分、邮费、佣金失败,原因:' . $e->getMessage()); } return true; } }