教你如何很认真的将一个项目写崩溃
如题,这个就以商城为例吧。
首先呢,会比较 乱,当个玩笑看完就好了 :smirk: 。
其次呢,可能会看不下去,那就看这句话就好了。 一定要先把整个项目需求理清楚,再进行开发。
完结!
那就不多说了,直接哔哔吧
环境:Laravel: 5.5
,MySql: 5.7.22
,PHP: 7.1.21
,laravel-admin: 1.6
订单表
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->string('order_sn')->comment('订单编号');
$table->unsignedInteger('user_id')->comment('用户ID');
$table->unsignedInteger('business_id')->comment('店铺ID');
$table->tinyInteger('order_status')->comment('订单状态');
$table->tinyInteger('shipping_status')->comment('发货状态');
$table->decimal('goods_price',10, 2)->comment('商品总价');
$table->decimal('goods_point',10,2)->comment('商品总积分');
$table->decimal('shipping_price',10, 2)->comment('邮费');
$table->decimal('order_amount',10, 2)->comment('应付款金额');
$table->string('pay_name')->nullable(true)->default('')->comment('支付方式名称');
$table->string('transaction_sn')->nullable(true)->default('')->comment('第三方平台交易流水号');
$table->string('shipping_code')->nullable(true)->default('')->comment('物流单号');
$table->string('shipping_name')->nullable(true)->default('')->comment('物流名称');
$table->string('user_note')->nullable(true)->default('')->comment('用户备注');
$table->string('admin_note')->nullable(true)->default('')->comment('管理员备注');
$table->json('address')->comment('JSON格式的收货地址');
$table->boolean('is_comment')->nullable(true)->default('0')->comment('是否已评论,默认未评论,1->已评论');
$table->timestamp('pay_time')->nullable(true)->comment('支付时间');
$table->timestamp('confirm_time')->nullable(true)->comment('收货确认时间');
$table->integer('apply_refund_time')->nullable(true)->default('0')->comment('申请退款时间');
$table->integer('apply_return_goods_time')->nullable(true)->default('0')->comment('申请退货退款时间');
$table->timestamp('refresh_time')->nullable(true)->comment('刷新时间,在这个时间为基础可以申请退货退款');
$table->softDeletes()->comment('软删除时间');
$table->timestamps();
$table->unique('order_sn');
$table->index('user_id');
});
DB::statement("ALTER TABLE `orders` comment'订单表'");
Schema::create('order_goods', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('order_id')->comment('订单ID');
$table->unsignedInteger('goods_id')->comment('商品ID');
$table->unsignedInteger('goods_sku_id')->comment('商品SKUID');
$table->string('goods_name')->comment('商品名称');
$table->text('image')->comment('商品图片');
$table->string('key')->comment('商品sku_key');
$table->string('key_name')->comment('商品sku_key名称');
$table->decimal('market_price',10, 2)->comment('商品市场价');
$table->decimal('sku_price',10, 2)->comment('商品单价');
$table->decimal('point',10,2)->comment('商品积分');
$table->unsignedInteger('number')->comment('购买数量');
});
DB::statement("ALTER TABLE `order_goods` comment'订单商品表'");
申请退款时间
,申请退货退款时间
,刷新时间
,为什么会有这三个时间- 退款时间,商品在为发货前,进行申请退款的时间
- 退货退款时间,商品在确认收货后,进行申请退货退款的时间
- 刷新时间,在商家拒绝退货退款后,以此时间进行 7 天的时间计算
- 项目后期的想法:
- 退款时间和退货退款时间可以取消,直接一个时间是否就可以?在代码中判断当前的时间是属于退款还是退货退款
- 刷新时间,暂时没想法,就先放上去吧。
因为需要购买积分,结果就发现,这个订单商品表不知道该如何去区分,结果就是,这个两个表只是用来保存订单和订单商品。
商品
我认为电商,主要是订单,商品,这两个是最重要的(如有不同想法,希望能告知一二):smirk:
Schema::create('goodses', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('business_account_id')->comment('商家id');
$table->unsignedInteger('goods_category_id')->comment('商品分类id');
$table->unsignedInteger('type_id')->comment('商品类型id');
$table->string('goods_name')->comment('商品名称');
$table->string('goods_subtitle')->nullable(true)->default('')->comment('商品简介');
$table->text('goods_description')->comment('商品详细');
$table->text('image')->comment('商品图片');
$table->decimal('price', 10, 2)->comment('最低价格');
$table->decimal('market', 10, 2)->comment('市场价格');
$table->decimal('min_point',10,2)->default('50')->comment('商品积分');
$table->integer('sort')->default(50)->comment('商品排序,降序排');
$table->float('rating')->default(5)->comment('商品平均评分');
$table->unsignedInteger('sold_count')->default(0)->comment('销量');
$table->unsignedInteger('review_count')->default(0)->comment('评价数量');
$table->boolean('is_hot')->default(false)->comment('是否热销商品,默认否');
$table->boolean('is_recommend')->default(false)->comment('是否推荐商品,默认否');
$table->boolean('business_recommend')->default(false)->comment('店铺推荐商品,是否推荐商品,默认否');
$table->boolean('is_show')->default(true)->comment('商品是否上架,默认上架');
$table->timestamps();
});
DB::statement("ALTER TABLE `goodses` comment'商品表'");
Schema::create('goods_skus', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('goods_id');
$table->string('key')->comment('规格键');
$table->string('key_name')->comment('规格名称');
$table->decimal('market_price', 10, 2)->comment('市场价格');
$table->decimal('sku_price', 10, 2)->comment('SKU 价格');
$table->decimal('point',10,2)->default('50')->comment('商品积分');
$table->unsignedInteger('stock')->comment('库存');
$table->string('sku')->default('')->comment('sku');
$table->foreign('goods_id')->references('id')->on('goodses')->onDelete('cascade');
$table->timestamps();
});
DB::statement("ALTER TABLE `goods_skus` comment'商品 SKU 表'");
集百家之短,成一组之苦
以上所有表结构,请勿 copy,后果很严重。
- 不知道有没有谁发现,商品居然没有运费 :joy:
- 每件商品由商家填入单位重量,生成订单时,按照商品数量进行计算运费。
TPSHOP
的运费模板 (个人感觉还是不错的)- 这里希望有大佬能给点其他的意见,谢谢 :pray:
- 商品图片
MySql 版本是 5.7 以上的,建议尝试一下json
代替text
来保存json
格式的数据 - 商品平均评分
由于这个电商就没有用到平均评分,所以此字段是多余的没有搞清楚情况就开始 copy
- 商品类型 id 是什么?SKU 表
- 我认为整个
SKU
表都是有问题的。商品类型 id 我是仿照TPSHOP
的商品类型,所以到目前为止都还是无法理解,SKU 希望有大佬能够给点想法,谢谢 :pray:
- 我认为整个
一定要先把整个项目需求理清楚,再进行开发。
未完,待续!
小白,希望有大佬会来看看,顺便给点想法:smirk:
本作品采用《CC 协议》,转载必须注明作者和本文链接
这有啥,写着写着能写出多重人格才好玩
超过20个字段的时候,就应该考虑分表了
粗体
你的leader 没有把你怼死么?
@XiaohuiLam 多重人格?用生命在维护代码 :joy:
@saurfang 目前为止 leader 还没有来看我的代码和数据库,我感觉要被骂死了
@DianWang 好的,感谢 :pray:
写崩溃~ 不存在的...
我写的项目就没跑起来过~
@PretendTrue 删库跑路 还来得及
让我们继续把业务复杂化吧
退款退货的新建退货退款表,然后退款退货可以部分退款退货,订单商品表可以新增部分关联退货退款字段,商品主表可以新增锁定字段和退款状态字段(表示部分退款,全部退款等状态)
接下来继续把业务复杂化吧
涉及到使用积分,那么积分转化为金额时平摊掉部分商品金额,这个时候退款就不是退原有商品的金额了,只是退部分金额了,这时候就需要按比例计算订单商品的金额比例,算出每个商品实际使用了多少积分,这才可以算出实际要退多少钱。
好了,我们的业务还不够复杂呢
市场那边又说了“那如果我商品退货了怎么办”,这时候又涉及退积分了,那退多少积分呢,又来算平摊问题了,但是有时候平摊有小数点啊,实际使用0.1个积分怎么算,是按1个积分算,还是按0个积分算,积分是有小数点还是没有小数点,这就尴尬了,可以退0.1个积分的情况那我们去改改会员表吧,把积分字段改成浮点型,小数后2位吧,问题好像已经解决了。
那么,我们还是完善复杂度吧
有一天平摊积分是0.001,这就尴尬了,到底是要算0.01呢,还是舍弃呢,舍弃那财务那边算账的时候就不对了
.....
....
我是谁,我在哪,我在写什么.....
一个没有写过电商的初级 PHPer 表示一脸懵逼。
业务还可以再继续复杂一点呢 :wink:
我们来加个优惠券怎么样~
@JasonG
优惠券
新增优惠券表,如何?
优惠券的使用条件:
补充
@PretendTrue 在订单表中还要增加优惠券或者优惠金额的字段
两个月过去了,那么请问小组有没有把你打死?
@wanghan 两个月过去了,目前项目暂时未通过 IOS 的审核,我在想,是不是我的错 :joy:
@PretendTrue 十个月又过去了, 那么你还活着嘛