作者 陈志颖

fix:格式化导出订单销售日期

@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
6 "strconv" 6 "strconv"
  7 + "time"
7 8
8 "github.com/astaxie/beego/logs" 9 "github.com/astaxie/beego/logs"
9 10
@@ -961,6 +962,8 @@ func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrder @@ -961,6 +962,8 @@ func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrder
961 } 962 }
962 var resultMaps []map[string]string 963 var resultMaps []map[string]string
963 for i := range ordersData { 964 for i := range ordersData {
  965 + t, _ := time.ParseInLocation("2006-01-02 15:04:05", ordersData[i].SaleDate, time.Local)
  966 + fmt.Print(t, "\n")
964 m := map[string]string{ 967 m := map[string]string{
965 //"num": fmt.Sprint(i + 1), 968 //"num": fmt.Sprint(i + 1),
966 //"order_code": ordersData[i].OrderCode, 969 //"order_code": ordersData[i].OrderCode,
@@ -982,7 +985,7 @@ func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrder @@ -982,7 +985,7 @@ func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrder
982 "partner": ordersData[i].PartnerName, 985 "partner": ordersData[i].PartnerName,
983 "update_time": ordersData[i].UpdateTime, 986 "update_time": ordersData[i].UpdateTime,
984 "create_time": ordersData[i].CreateTime, 987 "create_time": ordersData[i].CreateTime,
985 - "saleDate": ordersData[i].SaleDate, 988 + "saleDate": t.Format("2006-01-02"),
986 "orderNum": fmt.Sprint(ordersData[i].PlanOrderCount), 989 "orderNum": fmt.Sprint(ordersData[i].PlanOrderCount),
987 "quantityControl": "", 990 "quantityControl": "",
988 "orderDist": fmt.Sprint(ordersData[i].RegionName), 991 "orderDist": fmt.Sprint(ordersData[i].RegionName),
1 -/**  
2 - @author: stevechan  
3 - @date: 2021/2/1  
4 - @note:  
5 -**/  
6 -  
7 -package main  
8 -  
9 -import (  
10 - "fmt"  
11 - "time"  
12 -  
13 - "github.com/go-pg/pg/v10"  
14 - "github.com/go-pg/pg/v10/orm"  
15 -)  
16 -  
17 -// 默认选中栏目  
18 -var DefaultColumns = []Column{  
19 - {  
20 - Id: "index",  
21 - ParamCn: "序号",  
22 - ParamFix: 1,  
23 - }, {  
24 - Id: "orderId",  
25 - ParamCn: "订单号",  
26 - ParamFix: 2,  
27 - }, {  
28 - Id: "shipmentsId",  
29 - ParamCn: "发货单号",  
30 - ParamFix: 2,  
31 - }, {  
32 - Id: "saleDate",  
33 - ParamCn: "销售日期",  
34 - ParamFix: 2,  
35 - }, {  
36 - Id: "orderNum",  
37 - ParamCn: "订单数量",  
38 - ParamFix: 2,  
39 - }, {  
40 - Id: "quantityControl",  
41 - ParamCn: "数量调整",  
42 - ParamFix: 2,  
43 - }, {  
44 - Id: "orderPrice",  
45 - ParamCn: "订单金额",  
46 - ParamFix: 2,  
47 - }, {  
48 - Id: "priceControl",  
49 - ParamCn: "金额调整",  
50 - ParamFix: 2,  
51 - }, {  
52 - Id: "orderDist",  
53 - ParamCn: "订单区域",  
54 - ParamFix: 2,  
55 - }, {  
56 - Id: "partnerCategory",  
57 - ParamCn: "合伙人类型",  
58 - ParamFix: 2,  
59 - }, {  
60 - Id: "buyer",  
61 - ParamCn: "客户",  
62 - ParamFix: 2,  
63 - }, {  
64 - Id: "partner",  
65 - ParamCn: "合伙人",  
66 - ParamFix: 2,  
67 - },  
68 -}  
69 -  
70 -// 默认未选中栏目  
71 -var DefaultInvalidColumns = []Column{  
72 - {  
73 - Id: "updateTime",  
74 - ParamCn: "更新时间",  
75 - ParamFix: 2,  
76 - }, {  
77 - Id: "createTime",  
78 - ParamCn: "创建时间",  
79 - ParamFix: 2,  
80 - },  
81 -}  
82 -  
83 -// 栏目项值对象  
84 -type Column struct {  
85 - // 列标记  
86 - Id string `json:"id"`  
87 - // 列标记中文  
88 - ParamCn string `json:"paramCn"`  
89 - // 列标记是否固定,1:固定,2:不固定  
90 - ParamFix int `json:"paramFix"`  
91 -}  
92 -  
93 -type ColumnSetting struct {  
94 - // 栏目设置id  
95 - Id int64  
96 - // 栏目设置关联用户公司id  
97 - CompanyId int  
98 - // 栏目设置创建时间  
99 - CreatedAt time.Time  
100 - // 栏目设置描述  
101 - Description string  
102 - // 栏目设置模块名称  
103 - Key string  
104 - // 栏目设置关联用户uid  
105 - Uid int64  
106 - // 栏目设置更新时间  
107 - UpdatedAt time.Time  
108 - // 栏目设置关联用户名称  
109 - UserName string  
110 - // 栏目数组  
111 - Value []Column `pg:",array"`  
112 - // 无效栏目数组  
113 - InvalidValue []Column `pg:",array"`  
114 -}  
115 -  
116 -func (c ColumnSetting) String() string {  
117 - return fmt.Sprintf("Story<%d %v %v>", c.Id, c.CompanyId, c.Uid)  
118 -}  
119 -  
120 -type AdminPermissionBase struct {  
121 - Id int64 `json:"id"`  
122 - Code string `json:"code"`  
123 -}  
124 -  
125 -type Partner struct {  
126 - // 合伙人ID  
127 - Id int64 `json:"id"`  
128 - // 合伙人姓名  
129 - PartnerName string `json:"partnerName"`  
130 - // 登录账号  
131 - Account string `json:"account"`  
132 -}  
133 -  
134 -type Users struct {  
135 - tableName struct{} `pg:"users"`  
136 - Id int64 `pg:",pk"` //用户id  
137 - CompanyId int64 //公司id  
138 - OpenId int64 //统一用户中心  
139 - Name string //用户名称  
140 - Sex int8 //性别:【0:未知】【1:男】【2:女】  
141 - JobNum string //工号  
142 - Phone string //手机号,同账号  
143 - PrivatePhone string //私人手机号  
144 - Email string //邮件  
145 - ExtensionNum string //分机号  
146 - EntryTime time.Time //入职时间  
147 - Workspace string //工作地  
148 - Status int8 //状态:【1:正常】【 2:禁用】  
149 - Avatar string ///头像  
150 - Remarks string //备注  
151 - AdminType int8 //是否为当前公司负责人 【1:是】【2:否】  
152 - ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】  
153 - Permission []AdminPermissionBase //权限  
154 - AccessPartners []Partner //可查看的合伙人  
155 - IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人”  
156 - CreateAt time.Time  
157 - UpdateAt time.Time  
158 - DeleteAt time.Time  
159 -}  
160 -  
161 -func (u Users) String() string {  
162 - return fmt.Sprintf("User<%d %s %v>", u.Id, u.Name, u.CompanyId)  
163 -}  
164 -  
165 -func main() {  
166 - // 本地开发  
167 - //db := pg.Connect(&pg.Options{  
168 - // User: "postgres",  
169 - // Addr: ":5432",  
170 - // Password: "1993618jack",  
171 - // Database: "partner_test",  
172 - //})  
173 - // 测试环境  
174 - db := pg.Connect(&pg.Options{  
175 - User: "postgres",  
176 - Addr: "114.55.200.59:31543",  
177 - Password: "eagle1010",  
178 - Database: "partner_test",  
179 - })  
180 - defer db.Close()  
181 -  
182 - err := createSchema(db)  
183 - if err != nil {  
184 - panic(err)  
185 - }  
186 -  
187 - // Select all users.  
188 - var users []Users  
189 - err = db.Model(&users).Select()  
190 - if err != nil {  
191 - panic(err)  
192 - }  
193 -  
194 - var companyUidMap = map[int64]int64{}  
195 -  
196 - for _, user := range users {  
197 - companyUidMap[user.CompanyId] = user.Id  
198 - }  
199 -  
200 - for companyId, uid := range companyUidMap {  
201 - newColumnSetting := &ColumnSetting{  
202 - CompanyId: int(companyId),  
203 - CreatedAt: time.Now(),  
204 - Description: "订单栏目设置",  
205 - Key: "order_base",  
206 - Uid: uid,  
207 - UpdatedAt: time.Now(),  
208 - UserName: "",  
209 - Value: DefaultColumns,  
210 - InvalidValue: DefaultInvalidColumns,  
211 - }  
212 -  
213 - _, err = db.Model(newColumnSetting).Insert()  
214 - if err != nil {  
215 - panic(err)  
216 - }  
217 - }  
218 -}  
219 -  
220 -// createSchema creates database schema for User and Story models.  
221 -func createSchema(db *pg.DB) error {  
222 - models := []interface{}{  
223 - (*Users)(nil),  
224 - (*ColumnSetting)(nil),  
225 - }  
226 -  
227 - for _, model := range models {  
228 - err := db.Model(model).CreateTable(&orm.CreateTableOptions{  
229 - Temp: false,  
230 - IfNotExists: true,  
231 - FKConstraints: true,  
232 - })  
233 - if err != nil {  
234 - return err  
235 - }  
236 - }  
237 - return nil  
238 -}