|
|
@@ -1,15 +1,20 @@
|
|
|
/*
|
|
|
* @Author: YKH
|
|
|
* @Date: 2021-12-08 10:26:27
|
|
|
- * @LastEditTime: 2022-10-03 20:47:49
|
|
|
+ * @LastEditTime: 2022-10-08 14:44:52
|
|
|
* @Description:
|
|
|
* @FilePath: \cool-admin-3.x\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\rent_computer.ts
|
|
|
*/
|
|
|
import { ALL, Body, Inject, Post, Provide } from '@midwayjs/decorator';
|
|
|
-import { CoolController, BaseController } from 'midwayjs-cool-core';
|
|
|
+import {
|
|
|
+ CoolController,
|
|
|
+ BaseController,
|
|
|
+ CoolCommException,
|
|
|
+} from 'midwayjs-cool-core';
|
|
|
import { ShuyouRentComputerEntity } from '../../entity/rent_computer';
|
|
|
import { ShuyouRentComputerService } from '../../service/rent_computer';
|
|
|
import { ILogger } from '@midwayjs/logger';
|
|
|
+import { Utils } from '../../../../comm/utils';
|
|
|
// import xlsx from 'node-xlsx';
|
|
|
// import fs from 'fs';
|
|
|
|
|
|
@@ -64,6 +69,9 @@ export class ShuyouRentComputerController extends BaseController {
|
|
|
@Inject()
|
|
|
ShuyouRentComputerService: ShuyouRentComputerService;
|
|
|
|
|
|
+ @Inject()
|
|
|
+ utils: Utils;
|
|
|
+
|
|
|
// 换编
|
|
|
@Post('/replaceNum')
|
|
|
async replaceNum(@Body(ALL) queryObject) {
|
|
|
@@ -145,39 +153,129 @@ export class ShuyouRentComputerController extends BaseController {
|
|
|
if (order == 0) {
|
|
|
return;
|
|
|
}
|
|
|
- console.log(item[0]);
|
|
|
+ // console.log(item[0]);
|
|
|
+ const price_type_text = item[4];
|
|
|
+ let price_type;
|
|
|
+ let rent_price;
|
|
|
+ let rent_price_day = 0;
|
|
|
+ const array_price_type_text = price_type_text.split('元/');
|
|
|
+ if (
|
|
|
+ array_price_type_text.length < 2 &&
|
|
|
+ !isNaN(parseFloat(array_price_type_text[0])) &&
|
|
|
+ isFinite(array_price_type_text[0])
|
|
|
+ ) {
|
|
|
+ throw new CoolCommException('[收费标准]有错误项~');
|
|
|
+ }
|
|
|
+ if (array_price_type_text[1] == '月') {
|
|
|
+ price_type = 2;
|
|
|
+ rent_price = array_price_type_text[0];
|
|
|
+ rent_price_day = parseInt(rent_price) / 30;
|
|
|
+ } else if (array_price_type_text[1] == '周') {
|
|
|
+ price_type = 1;
|
|
|
+ rent_price = array_price_type_text[0];
|
|
|
+ rent_price_day = parseInt(rent_price) / 7;
|
|
|
+ } else {
|
|
|
+ price_type = 0;
|
|
|
+ rent_price = array_price_type_text[0];
|
|
|
+ rent_price_day = parseInt(rent_price);
|
|
|
+ }
|
|
|
const set_meal = name + item[1];
|
|
|
+ let pay_method = 0;
|
|
|
+ if (name == '逍遥') {
|
|
|
+ pay_method = 1;
|
|
|
+ }
|
|
|
+ // this.logger.info(item[2]);
|
|
|
+ // this.logger.info(this.utils.excelFormatDate(item[2], '/'));
|
|
|
+ // throw new CoolCommException(this.utils.excelFormatDate(item[2], '/'));
|
|
|
// pc_num,pc_name,rent_person_id,shop_id,set_meal,rent_start,rent_duration,rent_end,price_type,rent_price,rent_price_day,pay_method,is_expire
|
|
|
- info_text =
|
|
|
- `('` +
|
|
|
- item[0] +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- item[0] +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- rent_person_id +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- shop_id +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- set_meal +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- item[2] +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- item[5] +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- item[3] +
|
|
|
- `',` +
|
|
|
- `'` +
|
|
|
- item[0] +
|
|
|
- `')`;
|
|
|
+ if (index == 0 && order == 1) {
|
|
|
+ info_text =
|
|
|
+ `('` +
|
|
|
+ item[0] +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ item[0] +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ rent_person_id +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ shop_id +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ set_meal +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ this.utils.excelFormatDate(item[2], '/') +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ item[5] +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ this.utils.excelFormatDate(item[3], '/') +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ price_type +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ rent_price +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ rent_price_day +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ pay_method +
|
|
|
+ `',` +
|
|
|
+ `'0')`;
|
|
|
+ } else {
|
|
|
+ info_text +=
|
|
|
+ `,('` +
|
|
|
+ item[0] +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ item[0] +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ rent_person_id +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ shop_id +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ set_meal +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ this.utils.excelFormatDate(item[2], '/') +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ item[5] +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ this.utils.excelFormatDate(item[3], '/') +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ price_type +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ rent_price +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ rent_price_day +
|
|
|
+ `',` +
|
|
|
+ `'` +
|
|
|
+ pay_method +
|
|
|
+ `',` +
|
|
|
+ `'0')`;
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
+ // this.logger.warn(info_text);
|
|
|
+ let reqmsg = await this.ShuyouRentComputerService.batchAdd(info_text);
|
|
|
+ // this.logger.info('本次导入成功' + reqmsg.affectedRows + '条');
|
|
|
+ return this.ok({
|
|
|
+ code: 1,
|
|
|
+ message: '本次导入成功' + reqmsg.affectedRows + '条',
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
// foreach加上async/await
|