orderRepository = $orderRepository; $this->rentOrderRepository = $rentOrderRepository; $this->couponRepository = $couponRepository; } public function transform(User $user) { if (Carbon::today()->format('Y-m-d') == Carbon::parse($user->deposit_expire_time)->format('Y-m-d')) { $deposit_expire_time = '免押金资格' . Carbon::parse($user->deposit_expire_time)->diffForHumans(Carbon::now()) . '到期'; } else { $deposit_expire_time = '免押金资格有效期至' . Carbon::parse($user->deposit_expire_time)->format('Y-m-d'); } // $new_user_coupons = []; // if ($user->is_new_user_coupons == User::IS_NEW_USER_COUPONS_OK) { // $new_user_coupons = $this->couponRepository->getNewUserCoupons(request()->get('area_id', 0)); // } return [ 'is_card_certified' => $user->is_card_certified, 'is_deposit' => $user->is_deposit, 'is_coupon_deposit_free' => $user->is_coupon_deposit_free, 'deposit_type_name' => User::$depositTypeMaps[$user->deposit_type], 'deposit_type' => $user->deposit_type, 'deposit_expire_time' => $deposit_expire_time, 'is_match_ride_age' => $user->is_match_ride_age, 'is_bind_mobile' => $user->is_bind_mobile, 'status' => $user->status, 'is_register' => $user->is_register, 'is_ride_order' => $this->rideOrder($user), 'is_pay_order' => $this->noPayOrder($user), 'is_rent_order' => $this->rentOrder($user), 'is_pay_rent_order' => $this->rentPayOrder($user), 'is_punishment' => $this->checkPunishment($user->id), 'is_student' => $user->is_student, 'is_exist_auth_student' => $user->is_student ? true : $this->is_exist_auth_student($user->id), 'is_new_user_coupons' => $user->is_new_user_coupons, // 'new_user_coupons' => $new_user_coupons ]; } /** * 检查用户是否有罚单 * @param $user_id * @return mixed * Author: Mead */ protected function checkPunishment($user_id) { return PunishmentOrder::where('user_id', $user_id)->where('pay_status', PunishmentOrder::PAY_STATUS_NO)->exists(); } /** * 是否存在用户认证学生 * @param $user_id * Author: Mead */ protected function is_exist_auth_student($user_id) { $auth = Student::where('user_id', $user_id)->select(['auth_status', 'error_msg'])->first(); if (!$auth) return false; if ((int)$auth->auth_status === Student::AUTH_STATUS_OK) { return true; } return $auth->toArray(); } protected function rentOrder($user) { $no = $this->rentOrderRepository->byUserIdCheckIsExistRentOrderWithNo($user->id); if (is_null($no)) return false; return $no; } public function rentPayOrder($user) { $no = $this->rentOrderRepository->byUserIdCheckIsExistNoPayOrderWithNo($user->id); if (is_null($no)) return false; return $no; } protected function rideOrder($user) { $no = $this->orderRepository->byUserIdCheckIsExistRideOrderWithNo($user->id); if (is_null($no)) return false; return $no; } protected function noPayOrder($user) { $no = $this->orderRepository->byUserIdCheckIsExistNoPayOrderWithNo($user->id); if (is_null($no)) return false; return $no; } }