Day28 订单 -- 定期定额

在好几年前串接金流的时候,还有没定期定额的选项,
记得那时接触的是团体的捐款网站要串接定期定额的功能,
当初第一次碰到的时候还想说自创名词咧,分期就分期,
搞啥定期定额,现在想起来倒是有些趣味,
分期是一个金额分成好几份,定期定额是一个金额指定好几次,
看起来很像,但在实做上就不太一样了,
一样看一下table有什麽变化

Schema::create('order', function (Blueprint $table) {
    $table->string('id', 30)->comment('订单id');
    $table->string('name', 30)->comment('购买人姓名');
    $table->integer('amount')->default(0)->comment('总金额');
    $table->integer('origin_order_id')->default(0)->comment('原始订单id');
    $table->string('status', 20)->default('pending')->comment('订单状态');
    $table->primary(['id']);
});
        
Schema::create('payment', function (Blueprint $table) {
    $table->string('id', 30)->comment('同订单id');
    $table->string('payment_id', 30)->comment('金流单id');
    $table->string('type', 20)->comment('付款类型'); //credit, atm
    $table->integer('period')->default(0)->comment('分期期数');
    $table->integer('current_period')->default(1)->comment('当前期数');
    $table->string('status', 30)->default('unpaid')->comment('付款状态');
    $table->dateTime('expired_at')->nullable()->comment('付款截止时间');
    $table->dateTime('paid_at')->nullable()->comment('付款时间');
    $table->text('info')->nullable(); // 付款资讯物件(ATM帐号/超商代码/超商条码)
    $table->float('amount')->default(0); // 金额
    $table->float('fee')->default(0); // 手续费
    $table->primary(['id']);
});

在order新增origin_order_id栏位去纪录哪一笔是初始订单,
再来因为定期定额,顾名思义每次金额都一样,
所以把payment的first_period_price跟each_period_price移除,
结构上异动不算太大,但是作法就很不一样了,
分期付款如果可以接收到金流的通知的话,我们会修改payment的资料,
去纪录最新的期数、期数资讯等等,
但在定期定额这边,接收到新的一期资料时,我们需要建立一组新的订单,
包含order_item、payment、payment_log等等,
最後用order.origin_order_id判断第一笔以及分类查询,
以上就是定期定额大致的作法,倒数几天了gogogo。


<<:  用React刻自己的投资Dashboard Day19 - 2.0版首页内容设计

>>:  TailwindCSS 从零开始 - dark 深色模式

Day 14: DockerFile实作Node前後端 (下)

Node前端 今天来讲Vue前端的与postgres包入进docker,和後端编译後直接放入相比,前...

【程序】我要加薪 转生成恶役菜鸟工程师避免 Bad End 的 30 件事 - 18

我要加薪 稳健的专业技术 对任务有充分的分析与计划能力 具有更全面的眼光及角度来制定任务计画 优化...

Kotlin Android 第13天,从 0 到 ML - Activity 和 Activity 生命周期

前言: ConstraintLayout讲完了,画面画好了那是用在那呢? 那就是要放在 Activi...

用React刻自己的投资Dashboard Day15 - 投资Dashboard 2.0版 Wireframe

有了总体经济的图表之後,接下来就要来制作各国股市的资讯站,笔者最常看的就是台股的资讯,其次则是美股、...

[Day14] 补充说明 – Cookie、Session和Token之Part1

哈罗大家好,我们今天来简单补充一下cookie、Session和Token,这里我会分成两天来介绍,...