--评级表
DROP TABLE IF EXISTS "grade_order";
CREATE TABLE "grade_order" (
      "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
      "type" varchar(32),
      "order_no" varchar(32),
      "user_id" int4 NOT NULL,
      "merchant_id" int4 ,
      "parent_id" int4 DEFAULT 0,
      "grade_type" varchar(32),--评级类型,送评(Grading),重评(Review),换壳(Reholder),换评(Crossover)
      "auth_type_id" int4,--认证类型
      "service_type_id" int4,--服务类型
      "card_size" varchar(64),--评级尺寸
      "grade_num" int4 DEFAULT 0,--实际评级数量
      "user_consign_num" int4 NOT NULL,--用户寄送数
      "refund_num" int4 DEFAULT 0,--退回总数
      "status" int4 DEFAULT 0,
      "pay_status" int4 DEFAULT 0,
      "service_amount" numeric(9,2),--平台服务费
      "earnest_amount" numeric(9,2),--保证金
      "evaluate_amount" numeric(9,2),--评估价
      "insure_amount" numeric(9,2),--保管费
      "grade_amount" numeric(9,2),--送评费用
      "accounts_payable" numeric(9,2),--应付金额
      "actual_amount" numeric(9,2),--实付金额
      "coupon_id" int4,
      "discount_amount" numeric(9,2),--优惠劵金额
      "user_img_front" text,
      "user_img_back_" text,
      "pre_grade_report" text,--预评估报告
      "grade_report" text,--评级报告
      "cat" varchar(32),
      "year" varchar(32),
      "sport" varchar(32),
      "manufacturer" varchar(64),
      "list_set" varchar(256),
      "card_set" varchar(256),
      "seq_num" varchar(32),
      "player_name" varchar(64),
      "send_courier_num" varchar(64),
      "send_courier_company" varchar(64),
      "send_courier_img" text,
      "grade_courier_num" varchar(64),
      "grade_courier_company" varchar(64),
      "grade_courier_img" text,
      "back_courier_num" varchar(64),
      "back_courier_company" varchar(64),
      "back_courier_img" text,
      "refund_courier_num" varchar(64),
      "refund_courier_company" varchar(64),
      "refund_courier_img" text,
      "address_id" int4,
      "link_name" varchar(128),
      "link_phone" varchar(32),
      "address" varchar(1024),
      "grade_prop" text,
      "remark" text,
      "del_flg" int2 DEFAULT 0,
      "create_time" timestamp,
      "update_by" varchar(128),
      "update_time" timestamp,
      "prop1" text,
      "prop2" text,
      "prop3" text,
      PRIMARY KEY ("id")
);

COMMENT ON COLUMN "grade_order"."user_consign_num" IS '用户寄送数';

COMMENT ON COLUMN "grade_order"."grade_type" IS '评级类型,送评(Grading),重评(Review),换壳(Reholder),换评(Crossover)';

COMMENT ON COLUMN "grade_order"."pay_status" IS '支付状态,同订单 100:待支付, 101:已支付,204,205,206:退款';

COMMENT ON COLUMN "grade_order"."status"
    IS '评级状态 0:新建, 10:已支付,待寄送,20:已寄送,待签收,30:已签收,待评估,40:已评估,待用户支付,50:待送评级,60:已出报告,未回寄,70:评级已回寄,待回寄用户,80:用户签收,90:完结:201:取消';

CREATE INDEX "g-o-uid" ON "grade_order" USING btree (
    "user_id"
);

CREATE INDEX "g-o-p-id" ON "grade_order" USING btree (
    "parent_id"
);

DROP TABLE IF EXISTS "grade_change_record";
--评级信息记录
CREATE TABLE "grade_change_record" (
     "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
     "type" varchar(32),--新建,寄送,签收1(hb),评估估价,用户支付,送去评级,补差价,出报告,签收2(评级公司),寄回用户
     "order_id" int4 NOT NULL,
     "title" varchar(255),--标题
     "describe" text,--用户显示
     "remark" text,--内部说明
     "status" int4 DEFAULT 0,
     "pay_status" int4 DEFAULT 0,
     "accounts_payable" numeric(9,2),
     "actual_payment" numeric(9,2),
     "trade_amount" numeric(9,2),
     "coupon_id" int4,
     "discount_amount" numeric(9,2),--优惠劵金额
     "payment_type" varchar(64),
     "payment_sub_type" varchar(64),
     "trade_no" varchar(128),
     "payment_num" varchar(128),
     "payment_time" timestamp,
     "payment_success_time" timestamp,
     "payment_bank_type" varchar(64),
     "payment_status" varchar(64),
     "refund_fee" numeric(9,2) DEFAULT 0,
     "refund_trade_no" varchar(128),
     "refund_id" varchar(255),
     "refund_time" timestamp,
     "refund_success_time" timestamp,
     "show_status" int4 DEFAULT 0,
     "create_time" timestamp,
     "update_time" timestamp,
     "prop1" text,
     "prop2" text,
     "prop3" text,
     PRIMARY KEY ("id")
);

CREATE INDEX "g-r-o-id" ON "grade_change_record" USING btree (
    "order_id"
);

CREATE INDEX "g-r-p-no" ON "grade_change_record" USING btree (
    "trade_no"
);

DROP TABLE IF EXISTS "grade_type_manage";
--评级类型表
CREATE TABLE "grade_type_manage" (
    "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" varchar(32),
    "parent_id" int4 DEFAULT 0,
    "name" varchar(256),
    "title" varchar(256),
    "amount" numeric(9,2),
    "rate_type" int2 DEFAULT 0,
    "service_rate" numeric(9,2),
    "describe" text,
    "config_prop" text,
    "img" text,
    "status" int4 DEFAULT 0,
    "sort_num" int4 DEFAULT 0,
    "create_time" timestamp,
    "update_time" timestamp,
    PRIMARY KEY ("id")
);