/** * 算快递费 * * @param $user_id string * @return float */ public static function getExpressFee($user_id = null) { if ($user_id) { $user = User::find($user_id); } else { $user = Sentry::getUser(); } $fee_type = FeeType::where('user_type', $user->user_type)->where('category', FeeType::get_express_code())->where('item', FeeType::get_express_subitem($user->user_type))->first(); $user_fee = UserFee::where('fee_type_id', $fee_type->id)->first(); // 有特殊费用情况 if (isset($user_fee) && $user_fee->fee_no != null) { return $user_fee->fee_no; } // 否则返回默认值 return $fee_type->number; }
public function changeServiceUnivalence() { $userId = Input::get("userId"); try { DB::beginTransaction(); if (Input::has("expressUnivalence")) { $expressUnivalence = Input::get("expressUnivalence"); $feetype = DB::table("fee_types")->select("id")->where("category", "20")->where("item", "1")->first(); $query = DB::table("user_fee")->where("user_id", $userId)->where("fee_type_id", $feetype->id); if (count($query->first()) == 0) { $userFee = new UserFee(); $userFee->user_id = $userId; $userFee->fee_type_id = $feetype->id; $userFee->fee_no = $expressUnivalence; $userFee->save(); } else { $query->update(["fee_no" => $expressUnivalence]); } } if (Input::has("agencyUnivalence")) { $agencyUnivalence = Input::get("agencyUnivalence"); $feetype = DB::table("fee_types")->select("id")->where("category", "30")->where("item", "1")->first(); $query = DB::table("user_fee")->where("user_id", $userId)->where("fee_type_id", $feetype->id); if (count($query->first()) == 0) { $userFee = new UserFee(); $userFee->user_id = $userId; $userFee->fee_type_id = $feetype->id; $userFee->fee_no = $agencyUnivalence; $userFee->save(); } else { $query->update(["fee_no" => $agencyUnivalence]); } } DB::commit(); } catch (Exception $e) { DB::rollback(); return Response::json(array('errCode' => 1, "errMsg" => "[数据库错误]修改失败")); } return Response::json(array('errCode' => 0)); }