import { Rule, RuleType } from '@midwayjs/validate'; import { ApiProperty } from '@midwayjs/swagger'; import _ = require('lodash'); import * as computedUtil from '../util/computed'; import { FrameworkErrorEnum, SearchBase, ServiceError } from 'free-midway-component'; import { getDataFromTarget } from '../util/util'; const getTotalDetail = (data, price) => { const num = _.get(data, 'num', 0); const freight = _.get(data, 'config.freight', 0); const total_detail = []; const goods_total = computedUtil.multiply(num, price); total_detail.push({ key: 'goods_total', zh: '商品总价', money: goods_total }); const freight_total = computedUtil.multiply(num, freight); total_detail.push({ key: 'freight_total', zh: '运费总价', money: freight_total }); return total_detail; }; export class FetchVO_groupOrder { constructor(data: object) { let price = 0; // const is_leader = _.get(data, 'customer.is_leader', '1'); // if (is_leader === '0') price = _.get(data, 'config.leader_price'); // else price = _.get(data, 'config.price'); for (const key of Object.keys(this)) { if (key === 'goodsSpec') { const kd = _.get(data, key); kd.price = price; this[key] = kd; } else if (key === 'total_detail') { this.total_detail = getTotalDetail(data, price); } else this[key] = _.get(data, key); } } @ApiProperty({ description: '数据id' }) _id: string = undefined; @ApiProperty({ description: 'customer' }) 'customer': string = undefined; @ApiProperty({ description: 'address' }) 'address': object = undefined; @ApiProperty({ description: 'goods' }) 'goods': object = undefined; @ApiProperty({ description: 'goodsSpec' }) 'goodsSpec': object = undefined; @ApiProperty({ description: 'buy_time' }) 'buy_time': string = undefined; @ApiProperty({ description: 'no' }) 'no': string = undefined; @ApiProperty({ description: 'status' }) 'status': string = undefined; @ApiProperty({ description: 'pay' }) 'pay': object = undefined; @ApiProperty({ description: 'group' }) 'group': string = undefined; @ApiProperty({ description: 'config' }) 'config': object = undefined; @ApiProperty({ description: '备注' }) 'remarks': string = undefined; @ApiProperty({ description: '快递类型' }) 'transport_type': string = undefined; @ApiProperty({ description: '快递信息' }) 'transport': Array = undefined; @ApiProperty({ description: '是否有售后' }) 'is_afterSale' = false; @ApiProperty({ description: '购买数量' }) 'num': number; @ApiProperty({ description: '明细' }) 'total_detail': Array; } export class QueryDTO_groupOrder extends SearchBase { constructor() { const like_prop = ['goods', 'customer', 'customer_name']; const props = ['_id', 'customer', 'address', 'goods', 'goodsSpec', 'buy_time', 'no', 'status', 'group', 'customer_name']; const mapping = { goods: 'goods.name', customer: 'customer_id', customer_name: 'customer.name', group: 'group' }; super({ like_prop, props, mapping }); } @ApiProperty({ description: '数据id' }) _id: string = undefined; @ApiProperty({ description: '顾客id' }) 'customer': string = undefined; @ApiProperty({ description: '顾客姓名' }) customer_name: string = undefined; @ApiProperty({ description: 'address' }) 'address': object = undefined; @ApiProperty({ description: 'goods' }) 'goods': string = undefined; @ApiProperty({ description: 'goodsSpec' }) 'goodsSpec': object = undefined; @ApiProperty({ description: 'buy_time' }) 'buy_time': string = undefined; @ApiProperty({ description: 'no' }) 'no': string = undefined; @ApiProperty({ description: 'status' }) 'status': string = undefined; @ApiProperty({ description: 'group' }) 'group': string = undefined; } export class QueryVO_groupOrder extends FetchVO_groupOrder {} export class CreateDTO_groupOrder { // @ApiProperty({ description: 'customer' }) // @Rule(RuleType['string']().empty('')) // 'customer': string = undefined; @ApiProperty({ description: 'address' }) @Rule(RuleType['object']().required().error(new ServiceError('缺少配送地址', FrameworkErrorEnum.NEED_BODY))) 'address': object = undefined; @ApiProperty({ description: '店铺' }) @Rule(RuleType['string']().required().error(new ServiceError('缺少店铺信息', FrameworkErrorEnum.NEED_BODY))) 'shop': string = undefined; @ApiProperty({ description: 'goods' }) @Rule(RuleType['string']().required().error(new ServiceError('缺少商品信息', FrameworkErrorEnum.NEED_BODY))) 'goods': string = undefined; @ApiProperty({ description: 'goodsSpec' }) @Rule(RuleType['string']().required().error(new ServiceError('缺少规格信息', FrameworkErrorEnum.NEED_BODY))) 'goodsSpec': string = undefined; @ApiProperty({ description: '购买数量' }) @Rule(RuleType['number']().required().error(new ServiceError('缺少购买数量', FrameworkErrorEnum.NEED_BODY))) 'num': number = undefined; @ApiProperty({ description: 'group' }) @Rule(RuleType['string']().required().error(new ServiceError('缺少团信息', FrameworkErrorEnum.NEED_BODY))) 'group': string = undefined; @ApiProperty({ description: '备注' }) @Rule(RuleType['string']().empty('')) 'remarks': string = undefined; // @ApiProperty({ description: 'buy_time' }) // @Rule(RuleType['string']().empty('')) // 'buy_time': string = undefined; // @ApiProperty({ description: 'no' }) // @Rule(RuleType['string']().empty('')) // 'no': string = undefined; // @ApiProperty({ description: 'status' }) // @Rule(RuleType['string']().empty('')) // 'status': string = undefined; // @ApiProperty({ description: 'pay' }) // @Rule(RuleType['object']().empty('')) // 'pay': object = undefined; // @ApiProperty({ description: 'config' }) // @Rule(RuleType['object']().empty('')) // 'config': object = undefined; } export class CreateVO_groupOrder extends FetchVO_groupOrder {} export class UpdateDTO_groupOrder extends CreateDTO_groupOrder { @ApiProperty({ description: '状态', example: '2' }) @Rule(RuleType.string().empty('')) status: string; @Rule(RuleType['string']().empty('')) 'transport_type': string = undefined; @ApiProperty({ description: '快递信息' }) @Rule(RuleType['array']().empty('')) 'transport': Array = undefined; } export class UpdateVO_groupOrder extends FetchVO_groupOrder { @ApiProperty({ description: '数据id' }) @Rule(RuleType['string']().empty('')) '_id': string = undefined; } export class toOrderPageDTO { @ApiProperty({ description: '店铺id', example: '6333d71d32c5f69745f9bd32' }) @Rule(RuleType.string().required().error(new ServiceError('缺少店铺信息', FrameworkErrorEnum.NEED_BODY))) shop: string; @ApiProperty({ description: '商品id', example: '635b89c042e87c7a2880b484' }) @Rule(RuleType.string().required().error(new ServiceError('缺少商品信息', FrameworkErrorEnum.NEED_BODY))) goods: string; @ApiProperty({ description: '规格id', example: '635b89d742e87c7a2880b4bb' }) @Rule(RuleType.string().required().error(new ServiceError('缺少规格信息', FrameworkErrorEnum.NEED_BODY))) goodsSpec: string; @ApiProperty({ description: '购买数量', example: 1 }) @Rule(RuleType.number().required().error(new ServiceError('缺少购买数量', FrameworkErrorEnum.NEED_BODY))) num: number; @ApiProperty({ description: '团id', example: '638574d85df0386470559163' }) @Rule(RuleType.string().required().error(new ServiceError('缺少团信息', FrameworkErrorEnum.NEED_BODY))) group: string; } export class AdminListView { constructor(data) { this._id = _.get(data, '_id'); this.no = _.get(data, 'no'); this.customer = _.get(data, 'customer.name'); this.goods = _.get(data, 'goods.name'); this.spec = _.get(data, 'goodsSpec.name'); this.pay = _.get(data, 'pay.pay_money'); this.num = _.get(data, 'num', 0); this.is_afterSale = _.get(data, 'is_afterSale', false); this.buy_time = _.get(data, 'buy_time'); this.address = getDataFromTarget(data, 'address', ['name', 'phone', 'province', 'city', 'area', 'address', '_id']); this.status = _.get(data, 'status'); this.group_status = _.get(data, 'group.status'); } _id: string; no: string; customer: string; goods: string; spec: string; pay: number; num: number; buy_time: string; is_afterSale: boolean; address: string; status: string; group_status: string; } export class AdminView { constructor(data) { const dl = ['_id', 'is_afterSale', 'buy_time', 'remarks', 'transport_type', 'transport', 'status']; for (const i of dl) this[i] = _.get(data, i); this.address = _.pick(_.get(data, 'address', {}), ['name', 'phone', 'province', 'city', 'area', 'address']); this.shop = _.pick(_.get(data, 'shop', {}), ['_id', 'name']); this.goods = _.pick(_.get(data, 'goods', {}), ['_id', 'name', 'file']); let price = 0; // const is_leader = _.get(data, 'customer.is_leader', '1'); // if (is_leader === '0') price = _.get(data, 'config.leader_price'); // else price = _.get(data, 'config.price'); const goodsSpec = _.pick(_.get(data, 'goodsSpec', {}), ['_id', 'name', 'file']); goodsSpec.price = price; goodsSpec.num = _.get(data, 'num', 0); this.goodsSpec = goodsSpec; this.pay = _.pick(_.get(data, 'pay', {}), ['pay_money']); this.group_status = _.get(data, 'group.status'); this.total_detail = getTotalDetail(data, price); } _id: string; address: { name: string; phone: string; province: string; city: string; area: string; address: string; }; shop: { _id: string; name: string; }; goods: { _id: string; name: string; file: Array; }; goodsSpec: { _id: string; name: string; price: string; num: number; file: Array; }; is_afterSale = false; total_detail: Array; buy_time: string; remarks: string; transport_type: string; transport: Array; pay: { pay_money: number; }; status: string; group_status: string; } export class UserListView { constructor(data) { this._id = _.get(data, '_id'); const shop = _.get(data, 'shop', {}); const shopData = _.pick(shop, ['_id', 'name']); this.shop = shopData; const goods = _.get(data, 'goods', {}); const goodsData = _.pick(goods, ['_id', 'name', 'file']); this.goods = goodsData; const spec = _.get(data, 'goodsSpec', {}); const specData = _.pick(spec, ['_id', 'name', 'file']); // const is_leader = _.get(data, 'customer.is_leader', '1'); // if (is_leader === '0') specData.price = _.get(data, 'config.leader_price'); // else specData.price = _.get(data, 'config.price'); this.spec = specData; this.pay = _.get(data, 'pay.pay_money', 0); const customer = _.get(data, 'customer', {}); const customerData = _.pick(customer, ['_id', 'name']); this.customer = customerData; this.buy_time = _.get(data, 'buy_time', 0); this.num = _.get(data, 'num'); this.status = _.get(data, 'status'); this.is_afterSale = _.get(data, 'is_afterSale', false); this.is_rate = _.get(data, 'is_rate', false); } _id: string; shop: { _id: string; name: string; }; goods: { _id: string; name: string; file: Array; }; spec: { _id: string; name: string; price: number; file: Array; }; pay: number; customer: { _id: string; name: string; }; buy_time: string; num: number; status: string; is_afterSale: boolean; is_rate: boolean; } export class UserView { constructor(data) { this._id = _.get(data, '_id'); this.address = _.get(data, 'address'); this.status = _.get(data, 'status'); const shop = _.get(data, 'shop', {}); const shopData = _.pick(shop, ['_id', 'name']); this.shop = shopData; const goods = _.get(data, 'goods', {}); const goodsData = _.pick(goods, ['_id', 'name', 'file']); this.goods = goodsData; const spec = _.get(data, 'goodsSpec', {}); const specData = _.pick(spec, ['_id', 'name', 'file']); let price = 0; // const is_leader = _.get(data, 'customer.is_leader', '1'); // if (is_leader === '0') price = _.get(data, 'config.leader_price'); // else price = _.get(data, 'config.price'); specData.price = price; this.spec = specData; this.num = _.get(data, 'num', 0); this.pay = _.get(data, 'pay.pay_money', 0); this.no = _.get(data, 'no'); this.buy_time = _.get(data, 'buy_time'); this.remarks = _.get(data, 'remarks'); this.total_detail = getTotalDetail(data, price); } _id: string; address: object; status: string; shop: { _id: string; name: string; }; goods: { _id: string; name: string; file: Array; }; spec: { _id: string; name: string; price: number; file: Array; }; num: number; pay: number; no: string; buy_time: string; remarks: string; total_detail: Array; }