正在显示
10 个修改的文件
包含
158 行增加
和
1 行删除
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/validation" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type ExportExchangeCashListCommand struct { | ||
| 9 | + IDs []int `json:"iDs"` | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +func (exportExchangeCashListCommand *ExportExchangeCashListCommand) ValidateCommand() error { | ||
| 13 | + valid := validation.Validation{} | ||
| 14 | + b, err := valid.Valid(exportExchangeCashListCommand) | ||
| 15 | + if err != nil { | ||
| 16 | + return err | ||
| 17 | + } | ||
| 18 | + if !b { | ||
| 19 | + for _, validErr := range valid.Errors { | ||
| 20 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + return nil | ||
| 24 | +} | ||
| 25 | + |
| @@ -1502,6 +1502,45 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC | @@ -1502,6 +1502,45 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC | ||
| 1502 | } | 1502 | } |
| 1503 | } | 1503 | } |
| 1504 | 1504 | ||
| 1505 | +// 根据id获取兑换清单 | ||
| 1506 | +func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchangeCashListCommand *command.ExportExchangeCashListCommand) ([]*domain.ExchangeCashPersonList, error) { | ||
| 1507 | + if err := exportExchangeCashListCommand.ValidateCommand(); err != nil { | ||
| 1508 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 1509 | + } | ||
| 1510 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 1511 | + if err != nil { | ||
| 1512 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 1513 | + } | ||
| 1514 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 1515 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 1516 | + } | ||
| 1517 | + defer func() { | ||
| 1518 | + transactionContext.RollbackTransaction() | ||
| 1519 | + }() | ||
| 1520 | + | ||
| 1521 | + var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository | ||
| 1522 | + if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ | ||
| 1523 | + "transactionContext": transactionContext, | ||
| 1524 | + }); err != nil { | ||
| 1525 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 1526 | + } else { | ||
| 1527 | + exchangeCashPersonListRepository = value | ||
| 1528 | + } | ||
| 1529 | + | ||
| 1530 | + if _, people, err := exchangeCashPersonListRepository.FindById(tool_funs.SimpleStructToMap(exportExchangeCashListCommand)); err != nil { | ||
| 1531 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 1532 | + } else { | ||
| 1533 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 1534 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 1535 | + } | ||
| 1536 | + //return map[string]interface{}{ | ||
| 1537 | + // "count": count, | ||
| 1538 | + // "people": people, | ||
| 1539 | + //}, nil | ||
| 1540 | + return people, nil | ||
| 1541 | + } | ||
| 1542 | +} | ||
| 1543 | + | ||
| 1505 | func NewCashPoolService(options map[string]interface{}) *CashPoolService { | 1544 | func NewCashPoolService(options map[string]interface{}) *CashPoolService { |
| 1506 | newCashPoolService := &CashPoolService{} | 1545 | newCashPoolService := &CashPoolService{} |
| 1507 | return newCashPoolService | 1546 | return newCashPoolService |
| @@ -15,6 +15,7 @@ type ExchangeCashPersonListRepository interface { | @@ -15,6 +15,7 @@ type ExchangeCashPersonListRepository interface { | ||
| 15 | FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error) | 15 | FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error) |
| 16 | Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) | 16 | Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) |
| 17 | FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) | 17 | FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) |
| 18 | + FindById(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) | ||
| 18 | } | 19 | } |
| 19 | 20 | ||
| 20 | func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} { | 21 | func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} { |
| @@ -54,6 +54,29 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str | @@ -54,6 +54,29 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str | ||
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | +// 根据id获取兑换活动清单 | ||
| 58 | +func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { | ||
| 59 | + tx := repository.transactionContext.PgTx | ||
| 60 | + var exchangeCashListModels []*models.ExchangeCashPersonList | ||
| 61 | + exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0) | ||
| 62 | + query := tx.Model(&exchangeCashListModels) | ||
| 63 | + if iDs, ok := queryOptions["iDs"]; ok && len(iDs.([]int)) != 0 { | ||
| 64 | + query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(iDs.([]int)) ) | ||
| 65 | + } | ||
| 66 | + if count, err := query.Order("id DESC").SelectAndCount(); err != nil { | ||
| 67 | + return 0, exchangeCashPeople, err | ||
| 68 | + } else { | ||
| 69 | + for _, exchangeCashListModel := range exchangeCashListModels { | ||
| 70 | + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil { | ||
| 71 | + return 0, exchangeCashPeople, err | ||
| 72 | + } else { | ||
| 73 | + exchangeCashPeople = append(exchangeCashPeople, taskNature) | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + return int64(count), exchangeCashPeople, nil | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | + | ||
| 57 | // 获取平台所有兑换活动清单(兑换现金活动总清单) | 80 | // 获取平台所有兑换活动清单(兑换现金活动总清单) |
| 58 | func (repository *ExchangeCashPersonListRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { | 81 | func (repository *ExchangeCashPersonListRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { |
| 59 | tx := repository.transactionContext.PgTx | 82 | tx := repository.transactionContext.PgTx |
| @@ -399,7 +399,71 @@ func (controller *SuMoneyController) ListDeadline() { | @@ -399,7 +399,71 @@ func (controller *SuMoneyController) ListDeadline() { | ||
| 399 | 399 | ||
| 400 | // TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息 | 400 | // TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息 |
| 401 | func (controller *SuMoneyController) ExportExchangeList() { | 401 | func (controller *SuMoneyController) ExportExchangeList() { |
| 402 | - | 402 | + cashPoolService := service.NewCashPoolService(nil) |
| 403 | + exportExchangeCashListCommand := &command.ExportExchangeCashListCommand{} | ||
| 404 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportExchangeCashListCommand) | ||
| 405 | + fmt.Print(exportExchangeCashListCommand, "\n") | ||
| 406 | + // 列标题 | ||
| 407 | + titles := []string{ | ||
| 408 | + "姓名","手机账号","已兑换现金","已兑换素币", | ||
| 409 | + } | ||
| 410 | + // 列单元 | ||
| 411 | + cells := []string{ | ||
| 412 | + "A","B","C","D", | ||
| 413 | + } | ||
| 414 | + // 数据源 | ||
| 415 | + var data []map[string]interface{} | ||
| 416 | + people, err := cashPoolService.ListExchangeCashPersonById(exportExchangeCashListCommand) | ||
| 417 | + for _, person := range people { | ||
| 418 | + p := map[string]interface{} { | ||
| 419 | + "name": person.EmployeeInfo.EmployeeName, | ||
| 420 | + "account": person.EmployeeInfo.EmployeeAccount, | ||
| 421 | + "exchanged_cash": person.ExchangedCash, | ||
| 422 | + "exchanged_su_money": person.ExchangedSuMoney, | ||
| 423 | + } | ||
| 424 | + data = append(data, p) | ||
| 425 | + } | ||
| 426 | + fmt.Print(data, "\n") | ||
| 427 | + var response utils.JsonResponse | ||
| 428 | + if err != nil { | ||
| 429 | + response = utils.ResponseError(controller.Ctx, err) | ||
| 430 | + controller.Data["json"] = response | ||
| 431 | + controller.ServeJSON() | ||
| 432 | + } else { | ||
| 433 | + // 新建文件 | ||
| 434 | + f := excelize.NewFile() | ||
| 435 | + // 新建工作簿 | ||
| 436 | + index := f.NewSheet("Sheet1") | ||
| 437 | + //列标题赋值 | ||
| 438 | + for column, v := range titles { | ||
| 439 | + f.SetCellValue("Sheet1", cells[column]+"1", v) | ||
| 440 | + } | ||
| 441 | + for lineNum, v := range data { //行数 lineNum 行内容 v | ||
| 442 | + columnNum := 0 //列数 | ||
| 443 | + for _, vv := range v { | ||
| 444 | + sheetPosition := cells[columnNum] + strconv.Itoa(lineNum+2) | ||
| 445 | + switch vv.(type) { | ||
| 446 | + case string: | ||
| 447 | + f.SetCellValue("Sheet1", sheetPosition, vv.(string)) | ||
| 448 | + break | ||
| 449 | + case int: | ||
| 450 | + f.SetCellValue("Sheet1", sheetPosition, vv.(int)) | ||
| 451 | + break | ||
| 452 | + case float64: | ||
| 453 | + f.SetCellValue("Sheet1", sheetPosition, vv.(float64)) | ||
| 454 | + break | ||
| 455 | + } | ||
| 456 | + columnNum++ | ||
| 457 | + } | ||
| 458 | + } | ||
| 459 | + f.SetActiveSheet(index) | ||
| 460 | + //保存为文件 | ||
| 461 | + f.Path="public/file/素币兑换清单.xlsx" | ||
| 462 | + if err := f.Save(); err != nil { | ||
| 463 | + fmt.Println(err) | ||
| 464 | + } | ||
| 465 | + controller.Ctx.Output.Download(f.Path,"素币兑换清单.xlsx") | ||
| 466 | + } | ||
| 403 | } | 467 | } |
| 404 | 468 | ||
| 405 | // TODO 导出素币流水记录,选择导出(ids),增加导出失败信息 | 469 | // TODO 导出素币流水记录,选择导出(ids),增加导出失败信息 |
public/README.md
0 → 100644
| 1 | +#mmm-worth 1 |
public/file/素币兑换清单.xlsx
0 → 100644
不能预览此文件类型
public/file/订单表.xlsx
0 → 100644
不能预览此文件类型
public/兑换素币清单-导入模板.xlsx
0 → 100644
不能预览此文件类型
-
请 注册 或 登录 后发表评论