groupOrder.interface.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. import { Rule, RuleType } from '@midwayjs/validate';
  2. import { ApiProperty } from '@midwayjs/swagger';
  3. import _ = require('lodash');
  4. import * as computedUtil from '../util/computed';
  5. import { FrameworkErrorEnum, SearchBase, ServiceError } from 'free-midway-component';
  6. import { getDataFromTarget } from '../util/util';
  7. const getTotalDetail = (data, price) => {
  8. const num = _.get(data, 'num', 0);
  9. const freight = _.get(data, 'config.freight', 0);
  10. const total_detail = [];
  11. const goods_total = computedUtil.multiply(num, price);
  12. total_detail.push({ key: 'goods_total', zh: '商品总价', money: goods_total });
  13. const freight_total = computedUtil.multiply(num, freight);
  14. total_detail.push({ key: 'freight_total', zh: '运费总价', money: freight_total });
  15. return total_detail;
  16. };
  17. export class FetchVO_groupOrder {
  18. constructor(data: object) {
  19. let price = 0;
  20. // const is_leader = _.get(data, 'customer.is_leader', '1');
  21. // if (is_leader === '0') price = _.get(data, 'config.leader_price');
  22. // else
  23. price = _.get(data, 'config.price');
  24. for (const key of Object.keys(this)) {
  25. if (key === 'goodsSpec') {
  26. const kd = _.get(data, key);
  27. kd.price = price;
  28. this[key] = kd;
  29. } else if (key === 'total_detail') {
  30. this.total_detail = getTotalDetail(data, price);
  31. } else this[key] = _.get(data, key);
  32. }
  33. }
  34. @ApiProperty({ description: '数据id' })
  35. _id: string = undefined;
  36. @ApiProperty({ description: 'customer' })
  37. 'customer': string = undefined;
  38. @ApiProperty({ description: 'address' })
  39. 'address': object = undefined;
  40. @ApiProperty({ description: 'goods' })
  41. 'goods': object = undefined;
  42. @ApiProperty({ description: 'goodsSpec' })
  43. 'goodsSpec': object = undefined;
  44. @ApiProperty({ description: 'buy_time' })
  45. 'buy_time': string = undefined;
  46. @ApiProperty({ description: 'no' })
  47. 'no': string = undefined;
  48. @ApiProperty({ description: 'status' })
  49. 'status': string = undefined;
  50. @ApiProperty({ description: 'pay' })
  51. 'pay': object = undefined;
  52. @ApiProperty({ description: 'group' })
  53. 'group': string = undefined;
  54. @ApiProperty({ description: 'config' })
  55. 'config': object = undefined;
  56. @ApiProperty({ description: '备注' })
  57. 'remarks': string = undefined;
  58. @ApiProperty({ description: '快递类型' })
  59. 'transport_type': string = undefined;
  60. @ApiProperty({ description: '快递信息' })
  61. 'transport': Array<any> = undefined;
  62. @ApiProperty({ description: '是否有售后' })
  63. 'is_afterSale' = false;
  64. @ApiProperty({ description: '购买数量' })
  65. 'num': number;
  66. @ApiProperty({ description: '明细' })
  67. 'total_detail': Array<any>;
  68. }
  69. export class QueryDTO_groupOrder extends SearchBase {
  70. constructor() {
  71. const like_prop = ['goods', 'customer', 'customer_name'];
  72. const props = ['_id', 'customer', 'address', 'goods', 'goodsSpec', 'buy_time', 'no', 'status', 'group', 'customer_name'];
  73. const mapping = { goods: 'goods.name', customer: 'customer_id', customer_name: 'customer.name', group: 'group' };
  74. super({ like_prop, props, mapping });
  75. }
  76. @ApiProperty({ description: '数据id' })
  77. _id: string = undefined;
  78. @ApiProperty({ description: '顾客id' })
  79. 'customer': string = undefined;
  80. @ApiProperty({ description: '顾客姓名' })
  81. customer_name: string = undefined;
  82. @ApiProperty({ description: 'address' })
  83. 'address': object = undefined;
  84. @ApiProperty({ description: 'goods' })
  85. 'goods': string = undefined;
  86. @ApiProperty({ description: 'goodsSpec' })
  87. 'goodsSpec': object = undefined;
  88. @ApiProperty({ description: 'buy_time' })
  89. 'buy_time': string = undefined;
  90. @ApiProperty({ description: 'no' })
  91. 'no': string = undefined;
  92. @ApiProperty({ description: 'status' })
  93. 'status': string = undefined;
  94. @ApiProperty({ description: 'group' })
  95. 'group': string = undefined;
  96. }
  97. export class QueryVO_groupOrder extends FetchVO_groupOrder {}
  98. export class CreateDTO_groupOrder {
  99. // @ApiProperty({ description: 'customer' })
  100. // @Rule(RuleType['string']().empty(''))
  101. // 'customer': string = undefined;
  102. @ApiProperty({ description: 'address' })
  103. @Rule(RuleType['object']().required().error(new ServiceError('缺少配送地址', FrameworkErrorEnum.NEED_BODY)))
  104. 'address': object = undefined;
  105. @ApiProperty({ description: '店铺' })
  106. @Rule(RuleType['string']().required().error(new ServiceError('缺少店铺信息', FrameworkErrorEnum.NEED_BODY)))
  107. 'shop': string = undefined;
  108. @ApiProperty({ description: 'goods' })
  109. @Rule(RuleType['string']().required().error(new ServiceError('缺少商品信息', FrameworkErrorEnum.NEED_BODY)))
  110. 'goods': string = undefined;
  111. @ApiProperty({ description: 'goodsSpec' })
  112. @Rule(RuleType['string']().required().error(new ServiceError('缺少规格信息', FrameworkErrorEnum.NEED_BODY)))
  113. 'goodsSpec': string = undefined;
  114. @ApiProperty({ description: '购买数量' })
  115. @Rule(RuleType['number']().required().error(new ServiceError('缺少购买数量', FrameworkErrorEnum.NEED_BODY)))
  116. 'num': number = undefined;
  117. @ApiProperty({ description: 'group' })
  118. @Rule(RuleType['string']().required().error(new ServiceError('缺少团信息', FrameworkErrorEnum.NEED_BODY)))
  119. 'group': string = undefined;
  120. @ApiProperty({ description: '备注' })
  121. @Rule(RuleType['string']().empty(''))
  122. 'remarks': string = undefined;
  123. // @ApiProperty({ description: 'buy_time' })
  124. // @Rule(RuleType['string']().empty(''))
  125. // 'buy_time': string = undefined;
  126. // @ApiProperty({ description: 'no' })
  127. // @Rule(RuleType['string']().empty(''))
  128. // 'no': string = undefined;
  129. // @ApiProperty({ description: 'status' })
  130. // @Rule(RuleType['string']().empty(''))
  131. // 'status': string = undefined;
  132. // @ApiProperty({ description: 'pay' })
  133. // @Rule(RuleType['object']().empty(''))
  134. // 'pay': object = undefined;
  135. // @ApiProperty({ description: 'config' })
  136. // @Rule(RuleType['object']().empty(''))
  137. // 'config': object = undefined;
  138. }
  139. export class CreateVO_groupOrder extends FetchVO_groupOrder {}
  140. export class UpdateDTO_groupOrder extends CreateDTO_groupOrder {
  141. @ApiProperty({ description: '状态', example: '2' })
  142. @Rule(RuleType.string().empty(''))
  143. status: string;
  144. @Rule(RuleType['string']().empty(''))
  145. 'transport_type': string = undefined;
  146. @ApiProperty({ description: '快递信息' })
  147. @Rule(RuleType['array']().empty(''))
  148. 'transport': Array<any> = undefined;
  149. }
  150. export class UpdateVO_groupOrder extends FetchVO_groupOrder {
  151. @ApiProperty({ description: '数据id' })
  152. @Rule(RuleType['string']().empty(''))
  153. '_id': string = undefined;
  154. }
  155. export class toOrderPageDTO {
  156. @ApiProperty({ description: '店铺id', example: '6333d71d32c5f69745f9bd32' })
  157. @Rule(RuleType.string().required().error(new ServiceError('缺少店铺信息', FrameworkErrorEnum.NEED_BODY)))
  158. shop: string;
  159. @ApiProperty({ description: '商品id', example: '635b89c042e87c7a2880b484' })
  160. @Rule(RuleType.string().required().error(new ServiceError('缺少商品信息', FrameworkErrorEnum.NEED_BODY)))
  161. goods: string;
  162. @ApiProperty({ description: '规格id', example: '635b89d742e87c7a2880b4bb' })
  163. @Rule(RuleType.string().required().error(new ServiceError('缺少规格信息', FrameworkErrorEnum.NEED_BODY)))
  164. goodsSpec: string;
  165. @ApiProperty({ description: '购买数量', example: 1 })
  166. @Rule(RuleType.number().required().error(new ServiceError('缺少购买数量', FrameworkErrorEnum.NEED_BODY)))
  167. num: number;
  168. @ApiProperty({ description: '团id', example: '638574d85df0386470559163' })
  169. @Rule(RuleType.string().required().error(new ServiceError('缺少团信息', FrameworkErrorEnum.NEED_BODY)))
  170. group: string;
  171. }
  172. export class AdminListView {
  173. constructor(data) {
  174. this._id = _.get(data, '_id');
  175. this.no = _.get(data, 'no');
  176. this.customer = _.get(data, 'customer.name');
  177. this.goods = _.get(data, 'goods.name');
  178. this.spec = _.get(data, 'goodsSpec.name');
  179. this.pay = _.get(data, 'pay.pay_money');
  180. this.num = _.get(data, 'num', 0);
  181. this.is_afterSale = _.get(data, 'is_afterSale', false);
  182. this.buy_time = _.get(data, 'buy_time');
  183. this.address = getDataFromTarget(data, 'address', ['name', 'phone', 'province', 'city', 'area', 'address', '_id']);
  184. this.status = _.get(data, 'status');
  185. this.group_status = _.get(data, 'group.status');
  186. }
  187. _id: string;
  188. no: string;
  189. customer: string;
  190. goods: string;
  191. spec: string;
  192. pay: number;
  193. num: number;
  194. buy_time: string;
  195. is_afterSale: boolean;
  196. address: string;
  197. status: string;
  198. group_status: string;
  199. }
  200. export class AdminView {
  201. constructor(data) {
  202. const dl = ['_id', 'is_afterSale', 'buy_time', 'remarks', 'transport_type', 'transport', 'status'];
  203. for (const i of dl) this[i] = _.get(data, i);
  204. this.address = _.pick(_.get(data, 'address', {}), ['name', 'phone', 'province', 'city', 'area', 'address']);
  205. this.shop = _.pick(_.get(data, 'shop', {}), ['_id', 'name']);
  206. this.goods = _.pick(_.get(data, 'goods', {}), ['_id', 'name', 'file']);
  207. let price = 0;
  208. // const is_leader = _.get(data, 'customer.is_leader', '1');
  209. // if (is_leader === '0') price = _.get(data, 'config.leader_price');
  210. // else
  211. price = _.get(data, 'config.price');
  212. const goodsSpec = _.pick(_.get(data, 'goodsSpec', {}), ['_id', 'name', 'file']);
  213. goodsSpec.price = price;
  214. goodsSpec.num = _.get(data, 'num', 0);
  215. this.goodsSpec = goodsSpec;
  216. this.pay = _.pick(_.get(data, 'pay', {}), ['pay_money']);
  217. this.group_status = _.get(data, 'group.status');
  218. this.total_detail = getTotalDetail(data, price);
  219. }
  220. _id: string;
  221. address: {
  222. name: string;
  223. phone: string;
  224. province: string;
  225. city: string;
  226. area: string;
  227. address: string;
  228. };
  229. shop: {
  230. _id: string;
  231. name: string;
  232. };
  233. goods: {
  234. _id: string;
  235. name: string;
  236. file: Array<any>;
  237. };
  238. goodsSpec: {
  239. _id: string;
  240. name: string;
  241. price: string;
  242. num: number;
  243. file: Array<any>;
  244. };
  245. is_afterSale = false;
  246. total_detail: Array<any>;
  247. buy_time: string;
  248. remarks: string;
  249. transport_type: string;
  250. transport: Array<any>;
  251. pay: {
  252. pay_money: number;
  253. };
  254. status: string;
  255. group_status: string;
  256. }
  257. export class UserListView {
  258. constructor(data) {
  259. this._id = _.get(data, '_id');
  260. const shop = _.get(data, 'shop', {});
  261. const shopData = _.pick(shop, ['_id', 'name']);
  262. this.shop = shopData;
  263. const goods = _.get(data, 'goods', {});
  264. const goodsData = _.pick(goods, ['_id', 'name', 'file']);
  265. this.goods = goodsData;
  266. const spec = _.get(data, 'goodsSpec', {});
  267. const specData = _.pick(spec, ['_id', 'name', 'file']);
  268. // const is_leader = _.get(data, 'customer.is_leader', '1');
  269. // if (is_leader === '0') specData.price = _.get(data, 'config.leader_price');
  270. // else
  271. specData.price = _.get(data, 'config.price');
  272. this.spec = specData;
  273. this.pay = _.get(data, 'pay.pay_money', 0);
  274. const customer = _.get(data, 'customer', {});
  275. const customerData = _.pick(customer, ['_id', 'name']);
  276. this.customer = customerData;
  277. this.buy_time = _.get(data, 'buy_time', 0);
  278. this.num = _.get(data, 'num');
  279. this.status = _.get(data, 'status');
  280. this.is_afterSale = _.get(data, 'is_afterSale', false);
  281. this.is_rate = _.get(data, 'is_rate', false);
  282. }
  283. _id: string;
  284. shop: {
  285. _id: string;
  286. name: string;
  287. };
  288. goods: {
  289. _id: string;
  290. name: string;
  291. file: Array<any>;
  292. };
  293. spec: {
  294. _id: string;
  295. name: string;
  296. price: number;
  297. file: Array<any>;
  298. };
  299. pay: number;
  300. customer: {
  301. _id: string;
  302. name: string;
  303. };
  304. buy_time: string;
  305. num: number;
  306. status: string;
  307. is_afterSale: boolean;
  308. is_rate: boolean;
  309. }
  310. export class UserView {
  311. constructor(data) {
  312. this._id = _.get(data, '_id');
  313. this.address = _.get(data, 'address');
  314. this.status = _.get(data, 'status');
  315. const shop = _.get(data, 'shop', {});
  316. const shopData = _.pick(shop, ['_id', 'name']);
  317. this.shop = shopData;
  318. const goods = _.get(data, 'goods', {});
  319. const goodsData = _.pick(goods, ['_id', 'name', 'file']);
  320. this.goods = goodsData;
  321. const spec = _.get(data, 'goodsSpec', {});
  322. const specData = _.pick(spec, ['_id', 'name', 'file']);
  323. let price = 0;
  324. // const is_leader = _.get(data, 'customer.is_leader', '1');
  325. // if (is_leader === '0') price = _.get(data, 'config.leader_price');
  326. // else
  327. price = _.get(data, 'config.price');
  328. specData.price = price;
  329. this.spec = specData;
  330. this.num = _.get(data, 'num', 0);
  331. this.pay = _.get(data, 'pay.pay_money', 0);
  332. this.no = _.get(data, 'no');
  333. this.buy_time = _.get(data, 'buy_time');
  334. this.remarks = _.get(data, 'remarks');
  335. this.total_detail = getTotalDetail(data, price);
  336. }
  337. _id: string;
  338. address: object;
  339. status: string;
  340. shop: {
  341. _id: string;
  342. name: string;
  343. };
  344. goods: {
  345. _id: string;
  346. name: string;
  347. file: Array<any>;
  348. };
  349. spec: {
  350. _id: string;
  351. name: string;
  352. price: number;
  353. file: Array<any>;
  354. };
  355. num: number;
  356. pay: number;
  357. no: string;
  358. buy_time: string;
  359. remarks: string;
  360. total_detail: Array<any>;
  361. }