006 內測 情景之迷你財務記賬

2022-07-13 18:09:11 字數 4187 閱讀 7053

題圖:晉商票號賬本。晉商票號,縱橫明清500年的"華爾街",跨國的金融大鱷,創下諸多輝煌。

迷你版的財務記賬,包括了餘額,交易和明細三塊。

能夠滿足基本的記賬要求:對賬,紅訂正,做報表。

@史榮久 / 2015-03-01 / cc-by-sa-3.0

使用者1(u1),餘額0元,使用者1有三件物品**。

物品1,10元;物品2,20元;物品3,30元;

使用者2(u2),餘額500元,想買使用者1的物品。

餘額表,可更新,只關心使用者的餘額情況。

交易表,只插入,只關心每筆交易的金額和流向。

明細表,只插入,只關心每筆交易的金額對物品分配。

在過去在紙質帳本上,用黑筆記賬,稱為黑資料。

訂正時,用紅筆劃掉黑資料,填上新資料,稱為紅資料。

紅訂正,指上述過程,而此處指對一筆交易的完全取消。

即,插入和黑資料的'金額','記錄id'相反的資料。

`uid` int not null comment '使用者id',

primary key (`uid`))

engine = innodb;

create table if not exists `item` (

`iid` int not null comment '物品id',

`price` decimal(10,2) not null comment '**',

primary key (`iid`))

engine = innodb;

create table if not exists `cash_balance` (

`uid` int not null comment '使用者id',

`balance` decimal(10,2) not null comment '餘額',

`create_on` mediumtext not null comment '建立事件',

`update_on` mediumtext not null comment '更新事件',

primary key (`uid`))

engine = innodb;

create table if not exists `cash_transaction` (

`tid` bigint not null comment '交易id',

`record_id` int not null comment '記錄id',

`amount` decimal(10,2) not null comment '交易金額',

`buyer_id` int not null comment '買家uid',

`seller_id` int not null comment '賣家uid',

`create_on` mediumtext not null comment '建立事件',

`create_at` datetime not null comment '插入時間',

`extra_info` varchar(255) null comment '附加資訊',

primary key (`tid`, `record_id`))

engine = innodb

default character set = utf8

collate = utf8_bin;

create table if not exists `cash_txdetail` (

`tid` bigint not null comment '交易id',

`record_id` int not null comment '記錄id',

`detail_id` int not null comment '明細id',

`amount` decimal(10,2) not null comment '金額',

`item_id` int not null comment '物品id',

primary key (`tid`, `record_id`, `detail_id`))

engine = innodb;

-- 初始資料

insert into `item`(`iid`,`price`) values

(1,10),(2,20),(3,30);

insert into `cash_account`(`uid`) values

(1),(2);

insert into `cash_balance`

(`uid`,`balance`,`create_on`,`update_on`)

values

(1,0,1,'2015-01-01 0:0:0'),

(2,500,1,'2015-01-01 0:0:0');

【情景一】使用者2買了使用者1的物品各一件。資料變化如下:

假設購買事件id為2,當前時間為'2015-01-10 09:21:45'

-- 餘額變化

update `cash_balance` set

`balance` = `balance` + 60, `update_on` = 2

where `uid` = 1;

update `cash_balance` set

`balance` = `balance` - 60, `update_on` = 2

where `uid` = 2;

-- 交易記錄

insert into `cash_transaction` (`tid`,

`record_id`,`amount`,`buyer_id`,`seller_id`,

`create_on`,`create_at`,`extra_info`)

values (1,1,60,2,1,2,

'2015-01-10 09:21:45','樣本資料');

-- 明細記錄

insert into `cash_txdetail` (`tid`,

`record_id`,`detail_id`,`amount`,`item_id`)

values

(1,1,1,10,1),(1,1,2,20,2),(1,1,3,30,3);

【情景二】紅訂正,取消情景一的交易。資料變化如下:

假設訂正事件id為3,當前時間為'2015-01-10 10:21:45'

-- 餘額變化

update `cash_balance` set

`balance` = `balance` - 60, `update_on` = 3

where `uid` = 1;

update `cash_balance` set

`balance` = `balance` + 60, `update_on` = 3

where `uid` = 2;

-- 交易記錄

insert into `cash_transaction` (`tid`,

`record_id`,`amount`,`buyer_id`,`seller_id`,

`create_on`,`create_at`,`extra_info`)

select `tid`,

-`record_id`,-`amount`,`buyer_id`,`seller_id`,

3,'2015-01-10 10:21:45',`extra_info`

from `cash_transaction` where `tid` = 1

存在紅訂正的交易,sum(amount)=0。

(1)寫乙個交易服務,支援以上情景。

(2)做乙個報告(文字即可),顯示2023年,

賣的最多的10件物品(含取消的)

退貨最多的10件物品(交易取消的)

消費最多的10個使用者(不含取消)

(3)使用者1投訴:2015元旦,賬戶金額異常。

請問如何為其查賬?

對於查賬,本系統需要哪些改進。

SDUT 迷之好奇

include include int top struct node st 5001000 int creat void insertt int root,char s st root flag root st root next t int cmp char s,int root root st...

貪心之迷瘴

迷瘴 time limit 1000 ms memory limit 65536 kib submit statistic discuss problem description 通過懸崖的yifenfei,又面臨著幽谷的考驗 幽谷周圍瘴氣瀰漫,靜的可怕,隱約可見地上堆滿了骷髏。由於此處長年不見天日...

迷之階梯 ladder

問題描述 在經過地球防衛小隊的數學家連續多日的工作之後,外星人發的密碼終於得以破解。它 告訴我們在地球某一處的古老遺跡中,存在有對抗這次災難的秘密道具。防衛小隊立刻派出 了乙個 小分隊,迅速感到了這處遺跡。要進入遺跡,需要通過一段迷之階梯。登上階 梯必須要按照它要求的方法,否則就無法登上階梯。它要求...