APP社交类项目二设计之八钱包功能设计

           本项目涉及到用户的钱包功能,需要实现以下基本功能:

          1.用户之间发生金额转移,类似红包功能

          2.余额查询和余额明细查询

          3.银行卡绑定解绑,钱包余额提取和充值功能

           资金流转需要在后台实现,且每次资金流转都会触发用户的账户余额变化,参考了网上多篇文章,按照如下思路设计数据库表

            (1)账户基本信息表cust_accountbase-----包含用户ID, 账户ID,  余额amount, 冻结金额frozen,  账户状态custstatus 

              

             (2)账户银行卡信息表cust_accountbank------包含用户ID,银行卡号,银行卡类型,手机号,银行ID,所属省,所属市,银行名称等----用户银行卡绑定,解绑,充值,提取

              (3)账户信息安全表cust_accountpwd-----包含账户ID,密码类型,账户密码,锁定状态,锁定日期,锁定失效期等

               (4)交易流水表 trade_info----包含交易双方ID,交易金额, 交易码,交易时间---该表的记录插入主要由前台移动端发来的信息完成

                

                (5)交易账户详情表cust_accountdetail---该表记录和交易流水表相比,内容更详细包含了支付模式和支付说明,交易账户详细表不仅仅涉及到用户账户之间的交易流水,还涉及到系统与用户之间的交易流水,包括系统奖励,系统冻结。    

                   由于cust_accountdetail记录包含了trade_info的记录,所以利用trade_info表生成了触发器,当trade_info中插入记录之后,也向cust_accountdetail插入记录

                  (6)交易账户出金表和入金表,为了方便用户查询余额的基础上还能分别查询出金和入金情况

入金表cust_accountdetail_in

                 

出金表cust_accountdetail_out

                

                    上述两个表的记录是在cust_accountdetail表中使用了触发器,一旦交易账户详细表中有记录,出金和入金表分别插入相关的记录

begin
insert into cust_accountdetail_in(userid, objectid,amount, tradecode,tradetime,paymode,remark) values (new.tuserid, new.fuserid, new.amount, new.tradecode, new.tradetime,new.paymode,new.remark);
insert into cust_accountdetail_out(userid, objectid,amount, tradecode,tradetime,paymode,remark) values (new.fuserid, new.tuserid, new.amount, new.tradecode, new.tradetime,new.paymode,new.remark);
update cust_accountbase set amount = amount + new.amount where userid = new.fuserid;
update cust_accountbase set amount = amount - new.amount where userid = new.tuserid;
end

           总结:表设计考虑了如下几点

           一、除了账户详情表,结合会计考核科目,还要设计出金和入金表,方便资金流水检查

           二、利用表的触发器功能,一旦发生交易,触发插入关联表的资金流水变动记录

           另外,还需要考虑的,后面需要优化设计:

           一、交易记录安全性和真实性核对,涉及到trade_info中每条记录有前后台校验码,以保证交易真实可靠

           二、交易量高并发过程对数据表的处理

          

猜你喜欢

转载自blog.csdn.net/supperling/article/details/87686882