'datetime', 'pay_time' => 'datetime', 'start_time' => 'datetime', 'end_time' => 'datetime' ]; protected function serializeDate(DateTimeInterface $date): string { return $date->format($this->dateFormat ?: 'Y-m-d H:i:s'); } public function buildPayInfo($user_id, $project_id, $use_balance = 0, $coach_id = null, $car_type = 0, $coupon_id = 0, $order_id = 0, $distance = 0): array { if ($order_id) { $order = Order::query()->find($order_id); $project_id = $order['project_id']; $use_balance = +$order['balance_price'] > 0 ? 1 : 0; } $data['project_id'] = $project_id; // 通过定位获取代理 // 获取代理项目 $project = Project::query()->find($data['project_id']); // 项目价格 $data['service_price'] = number_format($project['price'], 2, '.', ''); // $coupon_model= new Coupon(); $coach_model = new User(); // $car_config_model = new CarPrice(); $coach = $coach_model->info($coach_id); // 优惠卷 $data['coupon_id'] = $coupon_id ?: 0; // 优惠金额 $data['coupon_price'] = number_format(0, 2, '.', ''); // 折扣金额 $data['discount_price'] = number_format(0, 2, '.', ''); // 物料费 $data['material_price'] = number_format(0, 2, '.', ''); // $project['material_price'] // 车费默认值 $data['car_price'] = number_format(0, 2, '.', ''); // 选择技师 if ($coach) { $data['coach_id'] = $coach_id; // if ($lat && $lng) { // 订单距离 // $data['distance'] = getDriveDistance($coach['lng'], $coach['lat'], $lng, $lat, $coach['uniacid']); // $data['distance'] += $data['car_config']['invented_distance'] * $data['distance'] / 100; //车费 // $data['car_price'] = 0; // $data['car_price'] = $this->getCarPrice($data['distance'], $data['car_config'], $car_type); // } } // 距离 if ($distance) { // 获取技师信息 // 获取车费配置 $baseCarPrice = 900;// 起步 $baseDistance = 3; // 公里 $carPrice = 300; // 每公里 $freeDistance = 3; // 免费公里 $distanceLen = $distance / 1000; $distancePrice = $distanceLen <= $freeDistance ? 0 : ($distanceLen > $baseDistance ? ($distanceLen - $baseDistance) * $carPrice + $baseCarPrice : $baseCarPrice); $data['car_price'] = number_format(+$distancePrice / 100, 2, '.', ''); } // 订单支付价 // 订单总价格 $pay_total_price = round(+$project['price'], 2) + round(+$data['car_price'], 2) + round(+$data['material_price'], 2); // 订单总优惠 $coupon_total_price = intval($data['coupon_price']) + intval($data['discount_price']); // 支付金额 $pay_price = $pay_total_price - $coupon_total_price; $pay_price <= 0 && ($pay_price = 0); $data['pay_price'] = number_format($pay_price, 2, '.', ''); // 余额支付 $data['balance_price'] = number_format(0, 2, '.', ''); if ($use_balance) { // 用户余额 $memberQuery = \App\Models\Member\User::query(); $user = $memberQuery->find($user_id); // 余额抵扣金额 $balance_price = round(+$user['balance'], 2) - round($pay_price, 2); if ($balance_price >= 0) { $data['balance_price'] = number_format($pay_price, 2, '.', ''); $data['pay_price'] = number_format(0, 2, '.', ''); } else { $data['balance_price'] = $user['balance']; $data['pay_price'] = number_format(abs($balance_price), 2, '.', ''); } } // 店铺 // $data['store_id'] = $coach['store_id']; // 服务时长 $data['time_long'] = $project['time_long']; return $data; } public function coach(): \Illuminate\Database\Eloquent\Relations\HasOne { return $this->hasOne(User::class, 'id', 'coach_id'); } public function grab() { return $this->hasOne(OrderGrab::class, 'order_id')->where('status', 1); } public function getServicePriceAttribute($value): string { return number_format($value / 100, 2, '.', ''); } public function getPayPriceAttribute($value): string { return number_format($value / 100, 2, '.', ''); } public function getMaterialPriceAttribute($value): string { return number_format($value / 100, 2, '.', ''); } public function getCouponPriceAttribute($value): string { return number_format($value / 100, 2, '.', ''); } public function getDiscountPriceAttribute($value): string { return number_format($value / 100, 2, '.', ''); } public function getBalancePriceAttribute($value): string { return number_format($value / 100, 2, '.', ''); } public function getCarPriceAttribute($value): string { return number_format($value / 100, 2, '.', ''); } }