Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/user_extra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

# 用户认证信息表
class UserExtra < ApplicationRecord
belongs_to :user
end
5 changes: 5 additions & 0 deletions app/services/races/order_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class OrderGenerator
include Serviceable
include Constants::Error::Common
include Constants::Error::Race
include Constants::Error::Account

TICKET_TYPES = %w(e_ticket entity_ticket).freeze
TICKET_STATUS_ERRORS = {
Expand All @@ -27,6 +28,8 @@ def call
return ApiResult.error_result(TICKET_STATUS_ERRORS[race.ticket_status.to_sym])
end

return ApiResult.error_result(NO_CERTIFICATION) unless user.user_extra

if Ticket.again_buy?(user.id, race.id)
return ApiResult.error_result(AGAIN_BUY)
end
Expand Down Expand Up @@ -58,6 +61,8 @@ def refresh_ticket_status
def ticket_params
{
user_id: user.id,
cert_type: user.user_extra.cert_type,
cert_no: user.user_extra.cert_no,
ticket_infos_id: race.ticket_info.id,
race_id: race.id,
ticket_type: params[:ticket_type],
Expand Down
4 changes: 4 additions & 0 deletions db/migrate/20170216043607_create_ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ def change
t.references :user
t.references :race
t.references :ticket_infos, foreign_key: true
t.string :cert_type, limit: 50,
default: 'chinese_id',
comment: '证件类型 chinese_id-中国身份证'
t.string :cert_no, comment: '证件号码'
t.string :ticket_type, limit: 30,
default: 'e_ticket',
comment: '票的类型 e_ticket-电子票, entity_ticket-实体票'
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20170221102817_extend_id_to_ticket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ExtendIdToTicket < ActiveRecord::Migration[5.0]
def change
add_column :tickets, :cert_type, :string,
limit: 50,
default: 'chinese_id',
comment: '证件类型 chinese_id-中国身份证'
add_column :tickets, :cert_no, :string,
comment: '证件号码'
end
end
2 changes: 1 addition & 1 deletion spec/factories/user_extras.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryGirl.define do
factory :user_extra do
user_id 'user_001'
association :user
real_name '王石'
cert_type 'chinese_id'
cert_no '611002199301146811'
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/v10/race/orders/v10_create_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let!(:race) { FactoryGirl.create(:race, ticket_status: 'selling') }
let!(:race_info) { FactoryGirl.create(:ticket_info, race: race) }
let!(:user) { FactoryGirl.create(:user) }
let!(:user_extra) { FactoryGirl.create(:user_extra, user: user, status: 'passed') }
let(:shipping_address) { FactoryGirl.create(:shipping_address, user: user) }
let(:access_token) do
AppAccessToken.jwt_create('18ca083547bb164b94a0f89a7959548b', user.user_uuid)
Expand Down Expand Up @@ -91,6 +92,17 @@
expect(json['code']).to eq(1100039)
end

it '用户没有实名信息' do
user.user_extra.destroy
post v10_race_orders_url(race.id),
headers: http_headers.merge(HTTP_X_DP_ACCESS_TOKEN: access_token),
params: e_ticket_params

expect(response).to have_http_status(200)
json = JSON.parse(response.body)
expect(json['code']).to eq(1100051)
end

it '售票状态不为selling' do
race.update(ticket_status: 'end')
post v10_race_orders_url(race.id),
Expand Down