@@ -25,6 +25,7 @@ type SubscribeLowBatteryAlertReq struct {
2525 Threshold int `json:"threshold"`
2626}
2727
28+ // GetBalance 获取电费余额
2829func GetBalance (c * gin.Context ) {
2930 var postForm CampusForm
3031 err := c .ShouldBindQuery (& postForm )
@@ -41,15 +42,10 @@ func GetBalance(c *gin.Context) {
4142 apiException .AbortWithException (c , apiException .NotBindYxy , nil )
4243 return
4344 }
44- token , err := yxyServices .GetElecAuthToken (user .YxyUid )
45- if err != nil {
46- apiException .AbortWithException (c , apiException .ServerError , err )
47- return
48- }
4945 if postForm .Campus != "mgs" {
5046 postForm .Campus = "zhpf"
5147 }
52- balance , err := yxyServices .ElectricityBalance (* token , postForm .Campus )
48+ balance , err := yxyServices .ElectricityBalance (user . YxyUid , postForm .Campus )
5349 if errors .Is (err , apiException .NotBindCard ) {
5450 _ = yxyServices .Unbind (user .ID , user .YxyUid , true )
5551 apiException .AbortWithError (c , err )
@@ -64,6 +60,7 @@ func GetBalance(c *gin.Context) {
6460 utils .JsonSuccessResponse (c , balance )
6561}
6662
63+ // GetRechargeRecords 获取充值记录
6764func GetRechargeRecords (c * gin.Context ) {
6865 var postForm recordForm
6966 err := c .ShouldBindJSON (& postForm )
@@ -80,15 +77,10 @@ func GetRechargeRecords(c *gin.Context) {
8077 apiException .AbortWithException (c , apiException .NotBindYxy , nil )
8178 return
8279 }
83- token , err := yxyServices .GetElecAuthToken (user .YxyUid )
84- if err != nil {
85- apiException .AbortWithException (c , apiException .ServerError , err )
86- return
87- }
8880 if postForm .Campus != "mgs" {
8981 postForm .Campus = "zhpf"
9082 }
91- roomStrConcat , err := yxyServices .GetElecRoomStrConcat (* token , postForm .Campus , user . YxyUid )
83+ roomStrConcat , err := yxyServices .GetElecRoomStrConcat (user . YxyUid , postForm .Campus )
9284 if errors .Is (err , apiException .NotBindCard ) {
9385 _ = yxyServices .Unbind (user .ID , user .YxyUid , true )
9486 apiException .AbortWithError (c , err )
@@ -100,7 +92,7 @@ func GetRechargeRecords(c *gin.Context) {
10092 apiException .AbortWithException (c , apiException .ServerError , err )
10193 return
10294 }
103- records , err := yxyServices .ElectricityRechargeRecords (* token , postForm .Campus , postForm .Page , * roomStrConcat )
95+ records , err := yxyServices .ElectricityRechargeRecords (user . YxyUid , postForm .Campus , postForm .Page , * roomStrConcat )
10496 if errors .Is (err , apiException .CampusMismatch ) {
10597 apiException .AbortWithError (c , err )
10698 return
@@ -111,10 +103,10 @@ func GetRechargeRecords(c *gin.Context) {
111103 utils .JsonSuccessResponse (c , records .List )
112104}
113105
106+ // GetConsumptionRecords 获取电费使用记录
114107func GetConsumptionRecords (c * gin.Context ) {
115108 var postForm CampusForm
116- err := c .ShouldBindQuery (& postForm )
117- if err != nil {
109+ if err := c .ShouldBindQuery (& postForm ); err != nil {
118110 apiException .AbortWithException (c , apiException .ParamError , err )
119111 return
120112 }
@@ -127,15 +119,10 @@ func GetConsumptionRecords(c *gin.Context) {
127119 apiException .AbortWithException (c , apiException .NotBindYxy , nil )
128120 return
129121 }
130- token , err := yxyServices .GetElecAuthToken (user .YxyUid )
131- if err != nil {
132- apiException .AbortWithException (c , apiException .ServerError , err )
133- return
134- }
135122 if postForm .Campus != "mgs" {
136123 postForm .Campus = "zhpf"
137124 }
138- roomStrConcat , err := yxyServices .GetElecRoomStrConcat (* token , postForm .Campus , user . YxyUid )
125+ roomStrConcat , err := yxyServices .GetElecRoomStrConcat (user . YxyUid , postForm .Campus )
139126 if errors .Is (err , apiException .NotBindCard ) {
140127 _ = yxyServices .Unbind (user .ID , user .YxyUid , true )
141128 apiException .AbortWithError (c , err )
@@ -147,7 +134,7 @@ func GetConsumptionRecords(c *gin.Context) {
147134 apiException .AbortWithException (c , apiException .ServerError , err )
148135 return
149136 }
150- records , err := yxyServices .GetElecConsumptionRecords (* token , postForm .Campus , * roomStrConcat )
137+ records , err := yxyServices .GetElecConsumptionRecords (user . YxyUid , postForm .Campus , * roomStrConcat )
151138 if errors .Is (err , apiException .CampusMismatch ) {
152139 apiException .AbortWithError (c , err )
153140 return
0 commit comments