Add owner_email_rule.

This commit is contained in:
邱博亞 2024-08-24 11:00:08 +08:00
parent eb8b951253
commit 703c5322ca
7 changed files with 35 additions and 5 deletions

View File

@ -80,7 +80,7 @@ class Admin::PropertyHiresController < OrbitAdminController
def destroy
property = Property.find(params[:id]) rescue nil
email = MemberProfile.where(:id.in=>property.owners.to_a).collect{|v| v.email}
email = property.get_owner_emails
Admin::PropertyHiresHelper::HireMethod.send_mail('delete',email,property.id,nil,nil,current_user.id)
property.destroy if !property.nil?
if params[:page]
@ -115,7 +115,7 @@ class Admin::PropertyHiresController < OrbitAdminController
property.p_hire_fields.each{|t| t.destroy if t["to_delete"] == true}
else
property.update_attributes(@property_params)
email = MemberProfile.where(:id.in=>property.owners.to_a).collect{|v| v.email}
email = property.get_owner_emails
Admin::PropertyHiresHelper::HireMethod.send_mail('edit',email,property.id,nil,nil,current_user.id)
end
redirect_to params[:referer_url]

View File

@ -285,7 +285,7 @@ class PropertyHiresController < ApplicationController
hire.passed = true if PropertyHireSetting.auto_approve_enabled?
hire.save
if !property.nil? && !is_admin_page
email = MemberProfile.where(:id.in=>property.owners).collect{|v| v.email}
email = property.get_owner_emails
email << hire.hiring_person_email
email = email.select{|e| e.present?}
Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,property.id,nil,hire.id,(current_user.id rescue nil))

View File

@ -134,6 +134,7 @@ module Admin::PropertyHiresHelper
a.html_safe
end
def self.send_mail(field_name,email,property_id,send_date=nil,hire_id=nil,user_id=nil)
return if email.blank?
property = Property.where(id: property_id).first
if !property.nil?
email_set = property.hire_email_sets.select{|v| v.field_name == field_name}

View File

@ -23,6 +23,7 @@ class Property
field :owners, type: Array, :default => []
field :other_owner
field :owner_email
field :owner_email_rule, type: Integer, default: 0 # 0 => owners, 1 => owner_email, 2 => owners + owner_email
field :owner_phone
field :price
field :other_location
@ -835,4 +836,16 @@ class Property
return new_object, clone_target
end
end
def get_owner_emails
emails = []
case self.owner_email_rule
when 0
emails = MemberProfile.where(:id.in=> self.owners.to_a).pluck(:email)
when 1
emails = [self.owner_email]
when 2
emails = MemberProfile.where(:id.in=> self.owners.to_a).pluck(:email) + [self.owner_email]
end
emails.select{|email| email.present?}
end
end

View File

@ -187,6 +187,12 @@
<%= f.text_field :owner_email %>
</div>
</div>
<div class="control-group">
<%= f.label :owner_email_rule, t("property_hire.owner_email_rule"), :class => "control-label muted" %>
<div class="controls">
<%= f.select :owner_email_rule, options_for_select([0,1,2].map{|i| [t("property_hire.owner_email_rules.#{i}"), i]}, f.object.owner_email_rule) %>
</div>
</div>
<div class="control-group">
<%= f.label :owner_phone, t("property_hire.owner_phone"), :class => "control-label muted" %>
<div class="controls">

View File

@ -132,6 +132,7 @@ en:
owners: Owners
other_owner: Other Owner
owner_email: Owner Email
owner_email_rule: Owner Email Rule
owner_phone: Owner Phone
price: Price
set_unavailibility: Set Unavailability
@ -181,4 +182,8 @@ en:
contact_person_department: Contact person department
special_unavailable_date: Special Unavailable Date
manage_booking: Manage Bookings
recurring_enable: Enable Recurring
recurring_enable: Enable Recurring
owner_email_rules:
'0': 'Only Owners'
'1': 'Only Owner Email'
'2': 'Owners and Owner Email'

View File

@ -158,6 +158,7 @@ zh_tw:
owners: 管理人
other_owner: 其他管理人
owner_email: 管理人Email
owner_email_rule: 管理人Email規則
owner_phone: 管理人聯絡電話
price: Price
set_unavailibility: 設定不開放時段
@ -203,4 +204,8 @@ zh_tw:
contact_person_department: 聯絡人服務單位
special_unavailable_date: 特定不開放預約⽇
manage_booking: 管理我的預約
recurring_enable: 啟用週期性預約
recurring_enable: 啟用週期性預約
owner_email_rules:
'0': '僅管理人'
'1': '僅管理人Email'
'2': '管理人+管理人Email'