accounting.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package ctrl_v1
  4. import (
  5. "gd_management_gateway/errors"
  6. "gd_management_gateway/params/param_base"
  7. "gd_management_gateway/params/param_v1_0"
  8. "gd_management_gateway/rpc_apis"
  9. "gd_management_gateway/rpc_apis/gd_management"
  10. "fmt"
  11. "time"
  12. "gd_management_gateway/common.in/httper"
  13. "gd_management_gateway/common.in/task"
  14. "gd_management_gateway/common.in/utils"
  15. "github.com/astaxie/beego"
  16. "go.uber.org/zap"
  17. )
  18. // Operations about data api
  19. type AccountingController struct {
  20. metadata interface{} // 中继元数据
  21. beego.Controller
  22. LogID string
  23. }
  24. // @Title 获取账单列表
  25. // @Description 获取账单列表
  26. // @Param token header string true "token"
  27. // @Param uid header int64 true "admin id"
  28. // @Param page_number query int64 false "页号"
  29. // @Param merchant_id query int64 false "商户id"
  30. // @Param start_time query string false "开始时间"
  31. // @Param end_time query string false "结束时间"
  32. // @Success 200 {object} params.param_v1_0.BillListResp "响应信息"
  33. // @Failure 500 服务器错误
  34. // @router /bill_list [get]
  35. func (u *AccountingController) BillList() {
  36. u.LogID = fmt.Sprintf("BillList[%d]", time.Now().UnixNano())
  37. req := &param_v1_0.BillListReq{}
  38. getParamsTask := func() error {
  39. httper.FillRequireParams(u.Ctx, req, u.LogID)
  40. return nil
  41. }
  42. handleDataTask := func() error {
  43. mreq := gd_management.BillListReq{}
  44. mreq.MerchantId = req.MerchantId
  45. mreq.PageNumber = req.PageNumber
  46. mreq.StartTime = req.StartTime
  47. mreq.EndTime = req.EndTime
  48. reply, err := rpc_apis.Management.BillList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  49. if err != nil {
  50. l.Error("rpc",
  51. zap.String("call", "BillList"),
  52. zap.String("args", utils.MarshalJsonString(req)),
  53. zap.String("error", err.Error()))
  54. return errors.ErrorTransform(err)
  55. }
  56. resp := param_v1_0.BillListResp{
  57. SimpleResp: param_base.SimpleResp{
  58. Code: 0,
  59. Msg: "SUCCESS",
  60. },
  61. }
  62. resp.Data = reply
  63. httper.JSON(u.Ctx, resp, u.LogID)
  64. return nil
  65. }
  66. // 执行以上定义的任务
  67. task.Do(&task.PanicRecover{
  68. Ctx: u.Ctx,
  69. LogID: u.LogID}, u.Ctx,
  70. getParamsTask, handleDataTask,
  71. )
  72. }
  73. // @Title 获取充值列表
  74. // @Description 获取充值列表
  75. // @Param token header string true "token"
  76. // @Param uid header int64 true "admin id"
  77. // @Param page_number query int64 false "页号"
  78. // @Param merchant_id query int64 false "商户id"
  79. // @Param start_time query string false "开始时间"
  80. // @Param end_time query string false "结束时间"
  81. // @Success 200 {object} params.param_v1_0.ChargeListResp "响应信息"
  82. // @Failure 500 服务器错误
  83. // @router /charge_list [get]
  84. func (u *AccountingController) ChargeList() {
  85. u.LogID = fmt.Sprintf("ChargeList[%d]", time.Now().UnixNano())
  86. req := &param_v1_0.ChargeListReq{}
  87. getParamsTask := func() error {
  88. httper.FillRequireParams(u.Ctx, req, u.LogID)
  89. return nil
  90. }
  91. handleDataTask := func() error {
  92. mreq := gd_management.ChargeListReq{}
  93. mreq.MerchantId = req.MerchantId
  94. mreq.PageNumber = req.PageNumber
  95. mreq.StartTime = req.StartTime
  96. mreq.EndTime = req.EndTime
  97. reply, err := rpc_apis.Management.ChargeList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  98. if err != nil {
  99. l.Error("rpc",
  100. zap.String("call", "ChargeList"),
  101. zap.String("args", utils.MarshalJsonString(req)),
  102. zap.String("error", err.Error()))
  103. return errors.ErrorTransform(err)
  104. }
  105. resp := param_v1_0.ChargeListResp{
  106. SimpleResp: param_base.SimpleResp{
  107. Code: 0,
  108. Msg: "SUCCESS",
  109. },
  110. }
  111. resp.Data = reply
  112. httper.JSON(u.Ctx, resp, u.LogID)
  113. return nil
  114. }
  115. // 执行以上定义的任务
  116. task.Do(&task.PanicRecover{
  117. Ctx: u.Ctx,
  118. LogID: u.LogID}, u.Ctx,
  119. getParamsTask, handleDataTask,
  120. )
  121. }
  122. // @Title 获取消费列表
  123. // @Description 获取消费列表
  124. // @Param token header string true "token"
  125. // @Param uid header int64 true "admin id"
  126. // @Param page_number query int64 false "页号"
  127. // @Param merchant_id query int64 false "商户id"
  128. // @Param data_api_id query int64 false "数据api id"
  129. // @Param start_time query string false "开始时间"
  130. // @Param end_time query string false "结束时间"
  131. // @Param consume_order query int false "消费排序"
  132. // @Success 200 {object} params.param_v1_0.ConsumeListResp "响应信息"
  133. // @Failure 500 服务器错误
  134. // @router /consume_list [get]
  135. func (u *AccountingController) ConsumeList() {
  136. u.LogID = fmt.Sprintf("ConsumeList[%d]", time.Now().UnixNano())
  137. req := &param_v1_0.ConsumeListReq{}
  138. getParamsTask := func() error {
  139. httper.FillRequireParams(u.Ctx, req, u.LogID)
  140. return nil
  141. }
  142. handleDataTask := func() error {
  143. mreq := gd_management.ConsumeListReq{}
  144. mreq.MerchantId = req.MerchantId
  145. mreq.PageNumber = req.PageNumber
  146. mreq.StartTime = req.StartTime
  147. mreq.EndTime = req.EndTime
  148. mreq.DataApiId = req.DataApiId
  149. mreq.ConsumeOrder = req.ConsumeOrder
  150. reply, err := rpc_apis.Management.ConsumeList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  151. if err != nil {
  152. l.Error("rpc",
  153. zap.String("call", "ConsumeList"),
  154. zap.String("args", utils.MarshalJsonString(req)),
  155. zap.String("error", err.Error()))
  156. return errors.ErrorTransform(err)
  157. }
  158. resp := param_v1_0.ConsumeListResp{
  159. SimpleResp: param_base.SimpleResp{
  160. Code: 0,
  161. Msg: "SUCCESS",
  162. },
  163. }
  164. resp.Data = reply
  165. httper.JSON(u.Ctx, resp, u.LogID)
  166. return nil
  167. }
  168. // 执行以上定义的任务
  169. task.Do(&task.PanicRecover{
  170. Ctx: u.Ctx,
  171. LogID: u.LogID}, u.Ctx,
  172. getParamsTask, handleDataTask,
  173. )
  174. }
  175. // @Title 消费趋势
  176. // @Description 消费趋势
  177. // @Param token header string true "token"
  178. // @Param uid header int64 true "admin id"
  179. // @Param merchant_id query int64 false "商户id"
  180. // @Param data_api_id query int64 false "数据api id"
  181. // @Param start_time query string false "开始时间"
  182. // @Param end_time query string false "结束时间"
  183. // @Success 200 {object} params.param_v1_0.ConsumeTrendListResp "响应信息"
  184. // @Failure 500 服务器错误
  185. // @router /consume_trend_list [get]
  186. func (u *AccountingController) ConsumeTrendList() {
  187. u.LogID = fmt.Sprintf("ConsumeTrendList[%d]", time.Now().UnixNano())
  188. req := &param_v1_0.ConsumeTrendListReq{}
  189. getParamsTask := func() error {
  190. httper.FillRequireParams(u.Ctx, req, u.LogID)
  191. return nil
  192. }
  193. handleDataTask := func() error {
  194. mreq := gd_management.ConsumeTrendListReq{}
  195. mreq.MerchantId = req.MerchantId
  196. mreq.StartTime = req.StartTime
  197. mreq.EndTime = req.EndTime
  198. mreq.DataApiId = req.DataApiId
  199. reply, err := rpc_apis.Management.ConsumeTrendList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  200. if err != nil {
  201. l.Error("rpc",
  202. zap.String("call", "ConsumeTrendList"),
  203. zap.String("args", utils.MarshalJsonString(req)),
  204. zap.String("error", err.Error()))
  205. return errors.ErrorTransform(err)
  206. }
  207. resp := param_v1_0.ConsumeTrendListResp{
  208. SimpleResp: param_base.SimpleResp{
  209. Code: 0,
  210. Msg: "SUCCESS",
  211. },
  212. }
  213. resp.Data = reply
  214. httper.JSON(u.Ctx, resp, u.LogID)
  215. return nil
  216. }
  217. // 执行以上定义的任务
  218. task.Do(&task.PanicRecover{
  219. Ctx: u.Ctx,
  220. LogID: u.LogID}, u.Ctx,
  221. getParamsTask, handleDataTask,
  222. )
  223. }
  224. // @Title 商户数据api价格列表
  225. // @Description 商户数据api价格列表
  226. // @Param token header string true "token"
  227. // @Param uid header int64 true "admin id"
  228. // @Param merchant_id query int64 false "商户id"
  229. // @Success 200 {object} params.param_v1_0.MerchantDataApiPriceListResp "响应信息"
  230. // @Failure 500 服务器错误
  231. // @router /merchant_data_api_price_list [get]
  232. func (u *AccountingController) MerchantDataApiPriceList() {
  233. u.LogID = fmt.Sprintf("MerchantDataApiPriceList[%d]", time.Now().UnixNano())
  234. req := &param_v1_0.MerchantDataApiPriceListReq{}
  235. getParamsTask := func() error {
  236. httper.FillRequireParams(u.Ctx, req, u.LogID)
  237. return nil
  238. }
  239. handleDataTask := func() error {
  240. mreq := gd_management.MerchantDataApiPriceListReq{}
  241. mreq.MerchantId = req.MerchantId
  242. reply, err := rpc_apis.Management.MerchantDataApiPriceList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  243. if err != nil {
  244. l.Error("rpc",
  245. zap.String("call", "MerchantDataApiPriceList"),
  246. zap.String("args", utils.MarshalJsonString(req)),
  247. zap.String("error", err.Error()))
  248. return errors.ErrorTransform(err)
  249. }
  250. resp := param_v1_0.MerchantDataApiPriceListResp{
  251. SimpleResp: param_base.SimpleResp{
  252. Code: 0,
  253. Msg: "SUCCESS",
  254. },
  255. }
  256. resp.Data = reply
  257. httper.JSON(u.Ctx, resp, u.LogID)
  258. return nil
  259. }
  260. // 执行以上定义的任务
  261. task.Do(&task.PanicRecover{
  262. Ctx: u.Ctx,
  263. LogID: u.LogID}, u.Ctx,
  264. getParamsTask, handleDataTask,
  265. )
  266. }
  267. // @Title 商户充值
  268. // @Description 商户充值
  269. // @Param token header string true "token"
  270. // @Param uid header int64 true "admin id"
  271. // @Param body body rpc_apis.gd_management.MerchantChargeReq true "参数"
  272. // @Success 200 {object} params.param_v1_0.MerchantChargeResp "响应信息"
  273. // @Failure 500 服务器错误
  274. // @router /merchant_charge [post]
  275. func (u *AccountingController) MerchantCharge() {
  276. u.LogID = fmt.Sprintf("MerchantCharge[%d]", time.Now().UnixNano())
  277. req := &param_v1_0.MerchantChargeReq{}
  278. getParamsTask := func() error {
  279. httper.FillRequireParams(u.Ctx, req, u.LogID)
  280. return nil
  281. }
  282. // 加入行为日志
  283. /*AddActionLogTask := func() error {
  284. go func() {
  285. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  286. mreq.QueryTypeId = req.Body.QueryTypeId
  287. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  288. if err != nil {
  289. l.Error("rpc",
  290. zap.String("call", "DataApiGetQueryType"),
  291. zap.String("args", utils.MarshalJsonString(req)),
  292. zap.String("error", err.Error()))
  293. return
  294. }
  295. // 构建json
  296. contentBytes, _ := json.Marshal(req.Body)
  297. areq := gd_admin.AddActionLogReq{
  298. Uid: req.Uid,
  299. Name: reply.QueryTypeInfo.QueryTypeName,
  300. Modules: "数据API",
  301. Func: "数据api添加基础api",
  302. Content: string(contentBytes),
  303. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  304. }
  305. AddActionLog(areq)
  306. }()
  307. return nil
  308. }*/
  309. handleDataTask := func() error {
  310. userName := utils.GetUserNameFromToken(req.Token)
  311. req.Body.UserName = userName
  312. _, err := rpc_apis.Management.MerchantCharge(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  313. if err != nil {
  314. l.Error("rpc",
  315. zap.String("call", "MerchantCharge"),
  316. zap.String("args", utils.MarshalJsonString(req)),
  317. zap.String("error", err.Error()))
  318. return errors.ErrorTransform(err)
  319. }
  320. resp := param_v1_0.MerchantChargeResp{
  321. SimpleResp: param_base.SimpleResp{
  322. Code: 0,
  323. Msg: "SUCCESS",
  324. },
  325. }
  326. httper.JSON(u.Ctx, resp, u.LogID)
  327. return nil
  328. }
  329. // 执行以上定义的任务
  330. task.Do(&task.PanicRecover{
  331. Ctx: u.Ctx,
  332. LogID: u.LogID}, u.Ctx,
  333. getParamsTask, handleDataTask,
  334. )
  335. }
  336. // @Title 商户价格列表
  337. // @Description 商户价格()列表
  338. // @Param token header string true "token"
  339. // @Param uid header int64 true "admin id"
  340. // @Param merchant_id query int64 false "商户id"
  341. // @Param merchant_type_list query string false "商户类型列表"
  342. // @Param arrearage_order query int false "可欠费金额排序"
  343. // @Param page_number query int false "页号"
  344. // @Success 200 {object} params.param_v1_0.MerchantPriceListResp "响应信息"
  345. // @Failure 500 服务器错误
  346. // @router /merchant_price_list [get]
  347. func (u *AccountingController) MerchantPriceList() {
  348. u.LogID = fmt.Sprintf("MerchantPriceList[%d]", time.Now().UnixNano())
  349. req := &param_v1_0.MerchantPriceListReq{}
  350. getParamsTask := func() error {
  351. httper.FillRequireParams(u.Ctx, req, u.LogID)
  352. return nil
  353. }
  354. handleDataTask := func() error {
  355. mreq := gd_management.MerchantPriceListReq{}
  356. mreq.MerchantId = req.MerchantId
  357. mreq.PageNumber = req.PageNumber
  358. mreq.ArrearageOrder = req.ArrearageOrder
  359. mreq.MerchantTypeList = req.MerchantTypeList
  360. reply, err := rpc_apis.Management.MerchantPriceList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  361. if err != nil {
  362. l.Error("rpc",
  363. zap.String("call", "MerchantPriceList"),
  364. zap.String("args", utils.MarshalJsonString(req)),
  365. zap.String("error", err.Error()))
  366. return errors.ErrorTransform(err)
  367. }
  368. resp := param_v1_0.MerchantPriceListResp{
  369. SimpleResp: param_base.SimpleResp{
  370. Code: 0,
  371. Msg: "SUCCESS",
  372. },
  373. }
  374. resp.Data = reply
  375. httper.JSON(u.Ctx, resp, u.LogID)
  376. return nil
  377. }
  378. // 执行以上定义的任务
  379. task.Do(&task.PanicRecover{
  380. Ctx: u.Ctx,
  381. LogID: u.LogID}, u.Ctx,
  382. getParamsTask, handleDataTask,
  383. )
  384. }
  385. // @Title 设置商户数据api单价
  386. // @Description 设置商户数据api单价
  387. // @Param token header string true "token"
  388. // @Param uid header int64 true "admin id"
  389. // @Param body body rpc_apis.gd_management.SetMerchantDataApiPriceReqReq true "参数"
  390. // @Success 200 {object} params.param_v1_0.SetMerchantDataApiPriceReqResp "响应信息"
  391. // @Failure 500 服务器错误
  392. // @router /merchant_data_api_price [put]
  393. func (u *AccountingController) SetMerchantDataApiPriceReq() {
  394. u.LogID = fmt.Sprintf("SetMerchantDataApiPriceReq[%d]", time.Now().UnixNano())
  395. req := &param_v1_0.SetMerchantDataApiPriceReq{}
  396. getParamsTask := func() error {
  397. httper.FillRequireParams(u.Ctx, req, u.LogID)
  398. return nil
  399. }
  400. // 加入行为日志
  401. /*AddActionLogTask := func() error {
  402. go func() {
  403. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  404. mreq.QueryTypeId = req.Body.QueryTypeId
  405. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  406. if err != nil {
  407. l.Error("rpc",
  408. zap.String("call", "DataApiGetQueryType"),
  409. zap.String("args", utils.MarshalJsonString(req)),
  410. zap.String("error", err.Error()))
  411. return
  412. }
  413. // 构建json
  414. contentBytes, _ := json.Marshal(req.Body)
  415. areq := gd_admin.AddActionLogReq{
  416. Uid: req.Uid,
  417. Name: reply.QueryTypeInfo.QueryTypeName,
  418. Modules: "数据API",
  419. Func: "数据api添加基础api",
  420. Content: string(contentBytes),
  421. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  422. }
  423. AddActionLog(areq)
  424. }()
  425. return nil
  426. }*/
  427. handleDataTask := func() error {
  428. _, err := rpc_apis.Management.SetMerchantDataApiPrice(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  429. if err != nil {
  430. l.Error("rpc",
  431. zap.String("call", "SetMerchantDataApiPrice"),
  432. zap.String("args", utils.MarshalJsonString(req)),
  433. zap.String("error", err.Error()))
  434. return errors.ErrorTransform(err)
  435. }
  436. resp := param_v1_0.SetMerchantDataApiPriceResp{
  437. SimpleResp: param_base.SimpleResp{
  438. Code: 0,
  439. Msg: "SUCCESS",
  440. },
  441. }
  442. httper.JSON(u.Ctx, resp, u.LogID)
  443. return nil
  444. }
  445. // 执行以上定义的任务
  446. task.Do(&task.PanicRecover{
  447. Ctx: u.Ctx,
  448. LogID: u.LogID}, u.Ctx,
  449. getParamsTask, handleDataTask,
  450. )
  451. }
  452. // @Title 设置商户类型
  453. // @Description 设置商户类型
  454. // @Param token header string true "token"
  455. // @Param uid header int64 true "admin id"
  456. // @Param body body rpc_apis.gd_management.SetMerchantTypeReq true "参数"
  457. // @Success 200 {object} params.param_v1_0.SetMerchantTypeResp "响应信息"
  458. // @Failure 500 服务器错误
  459. // @router /merchant_type [put]
  460. func (u *AccountingController) SetMerchantType() {
  461. u.LogID = fmt.Sprintf("SetMerchantType[%d]", time.Now().UnixNano())
  462. req := &param_v1_0.SetMerchantTypeReq{}
  463. getParamsTask := func() error {
  464. httper.FillRequireParams(u.Ctx, req, u.LogID)
  465. return nil
  466. }
  467. // 加入行为日志
  468. /*AddActionLogTask := func() error {
  469. go func() {
  470. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  471. mreq.QueryTypeId = req.Body.QueryTypeId
  472. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  473. if err != nil {
  474. l.Error("rpc",
  475. zap.String("call", "DataApiGetQueryType"),
  476. zap.String("args", utils.MarshalJsonString(req)),
  477. zap.String("error", err.Error()))
  478. return
  479. }
  480. // 构建json
  481. contentBytes, _ := json.Marshal(req.Body)
  482. areq := gd_admin.AddActionLogReq{
  483. Uid: req.Uid,
  484. Name: reply.QueryTypeInfo.QueryTypeName,
  485. Modules: "数据API",
  486. Func: "数据api添加基础api",
  487. Content: string(contentBytes),
  488. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  489. }
  490. AddActionLog(areq)
  491. }()
  492. return nil
  493. }*/
  494. handleDataTask := func() error {
  495. _, err := rpc_apis.Management.SetMerchantType(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  496. if err != nil {
  497. l.Error("rpc",
  498. zap.String("call", "SetMerchantType"),
  499. zap.String("args", utils.MarshalJsonString(req)),
  500. zap.String("error", err.Error()))
  501. return errors.ErrorTransform(err)
  502. }
  503. resp := param_v1_0.SetMerchantTypeResp{
  504. SimpleResp: param_base.SimpleResp{
  505. Code: 0,
  506. Msg: "SUCCESS",
  507. },
  508. }
  509. httper.JSON(u.Ctx, resp, u.LogID)
  510. return nil
  511. }
  512. // 执行以上定义的任务
  513. task.Do(&task.PanicRecover{
  514. Ctx: u.Ctx,
  515. LogID: u.LogID}, u.Ctx,
  516. getParamsTask, handleDataTask,
  517. )
  518. }
  519. // @Title 账单详情列表
  520. // @Description 商户价格()列表
  521. // @Param token header string true "token"
  522. // @Param uid header int64 true "admin id"
  523. // @Param merchant_id query int64 true "商户id"
  524. // @Param bill_id query int64 true "账单id"
  525. // @Param month query string true "月份(2022-02)"
  526. // @Success 200 {object} params.param_v1_0.BillDetailListResp "响应信息"
  527. // @Failure 500 服务器错误
  528. // @router /bill_detail_list [get]
  529. func (u *AccountingController) BillDetailList() {
  530. u.LogID = fmt.Sprintf("BillDetailList[%d]", time.Now().UnixNano())
  531. req := &param_v1_0.BillDetailListReq{}
  532. getParamsTask := func() error {
  533. httper.FillRequireParams(u.Ctx, req, u.LogID)
  534. return nil
  535. }
  536. handleDataTask := func() error {
  537. mreq := gd_management.BillDetailListReq{}
  538. mreq.MerchantId = req.MerchantId
  539. mreq.Month = req.Month
  540. mreq.BillId = req.BillId
  541. reply, err := rpc_apis.Management.BillDetailList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  542. if err != nil {
  543. l.Error("rpc",
  544. zap.String("call", "BillDetailList"),
  545. zap.String("args", utils.MarshalJsonString(req)),
  546. zap.String("error", err.Error()))
  547. return errors.ErrorTransform(err)
  548. }
  549. resp := param_v1_0.BillDetailListResp{
  550. SimpleResp: param_base.SimpleResp{
  551. Code: 0,
  552. Msg: "SUCCESS",
  553. },
  554. }
  555. resp.Data = reply
  556. httper.JSON(u.Ctx, resp, u.LogID)
  557. return nil
  558. }
  559. // 执行以上定义的任务
  560. task.Do(&task.PanicRecover{
  561. Ctx: u.Ctx,
  562. LogID: u.LogID}, u.Ctx,
  563. getParamsTask, handleDataTask,
  564. )
  565. }
  566. // @Title 更新账单详情(设置计费量)
  567. // @Description 更新账单详情(设置计费量)
  568. // @Param token header string true "token"
  569. // @Param uid header int64 true "admin id"
  570. // @Param body body rpc_apis.gd_management.UpdateBillDetailReq true "参数"
  571. // @Success 200 {object} params.param_v1_0.UpdateBillDetailResp "响应信息"
  572. // @Failure 500 服务器错误
  573. // @router /bill_detail [put]
  574. func (u *AccountingController) UpdateBillDetail() {
  575. u.LogID = fmt.Sprintf("UpdateBillDetail[%d]", time.Now().UnixNano())
  576. req := &param_v1_0.UpdateBillDetailReq{}
  577. getParamsTask := func() error {
  578. httper.FillRequireParams(u.Ctx, req, u.LogID)
  579. return nil
  580. }
  581. // 加入行为日志
  582. /*AddActionLogTask := func() error {
  583. go func() {
  584. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  585. mreq.QueryTypeId = req.Body.QueryTypeId
  586. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  587. if err != nil {
  588. l.Error("rpc",
  589. zap.String("call", "DataApiGetQueryType"),
  590. zap.String("args", utils.MarshalJsonString(req)),
  591. zap.String("error", err.Error()))
  592. return
  593. }
  594. // 构建json
  595. contentBytes, _ := json.Marshal(req.Body)
  596. areq := gd_admin.AddActionLogReq{
  597. Uid: req.Uid,
  598. Name: reply.QueryTypeInfo.QueryTypeName,
  599. Modules: "数据API",
  600. Func: "数据api添加基础api",
  601. Content: string(contentBytes),
  602. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  603. }
  604. AddActionLog(areq)
  605. }()
  606. return nil
  607. }*/
  608. handleDataTask := func() error {
  609. userName := utils.GetUserNameFromToken(req.Token)
  610. req.Body.UserName = userName
  611. _, err := rpc_apis.Management.UpdateBillDetail(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  612. if err != nil {
  613. l.Error("rpc",
  614. zap.String("call", "UpdateBillDetail"),
  615. zap.String("args", utils.MarshalJsonString(req)),
  616. zap.String("error", err.Error()))
  617. return errors.ErrorTransform(err)
  618. }
  619. resp := param_v1_0.UpdateBillDetailResp{
  620. SimpleResp: param_base.SimpleResp{
  621. Code: 0,
  622. Msg: "SUCCESS",
  623. },
  624. }
  625. httper.JSON(u.Ctx, resp, u.LogID)
  626. return nil
  627. }
  628. // 执行以上定义的任务
  629. task.Do(&task.PanicRecover{
  630. Ctx: u.Ctx,
  631. LogID: u.LogID}, u.Ctx,
  632. getParamsTask, handleDataTask,
  633. )
  634. }
  635. // @Title 添加账单备注
  636. // @Description 添加账单备注
  637. // @Param token header string true "token"
  638. // @Param uid header int64 true "admin id"
  639. // @Param body body rpc_apis.gd_management.BillRemarkReq true "参数"
  640. // @Success 200 {object} params.param_v1_0.BillRemarkResp "响应信息"
  641. // @Failure 500 服务器错误
  642. // @router /bill_remark [put]
  643. func (u *AccountingController) BillRemark() {
  644. u.LogID = fmt.Sprintf("UpdateBillDetail[%d]", time.Now().UnixNano())
  645. req := &param_v1_0.BillRemarkReq{}
  646. getParamsTask := func() error {
  647. httper.FillRequireParams(u.Ctx, req, u.LogID)
  648. return nil
  649. }
  650. // 加入行为日志
  651. /*AddActionLogTask := func() error {
  652. go func() {
  653. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  654. mreq.QueryTypeId = req.Body.QueryTypeId
  655. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  656. if err != nil {
  657. l.Error("rpc",
  658. zap.String("call", "DataApiGetQueryType"),
  659. zap.String("args", utils.MarshalJsonString(req)),
  660. zap.String("error", err.Error()))
  661. return
  662. }
  663. // 构建json
  664. contentBytes, _ := json.Marshal(req.Body)
  665. areq := gd_admin.AddActionLogReq{
  666. Uid: req.Uid,
  667. Name: reply.QueryTypeInfo.QueryTypeName,
  668. Modules: "数据API",
  669. Func: "数据api添加基础api",
  670. Content: string(contentBytes),
  671. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  672. }
  673. AddActionLog(areq)
  674. }()
  675. return nil
  676. }*/
  677. handleDataTask := func() error {
  678. _, err := rpc_apis.Management.BillRemark(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  679. if err != nil {
  680. l.Error("rpc",
  681. zap.String("call", "BillRemark"),
  682. zap.String("args", utils.MarshalJsonString(req)),
  683. zap.String("error", err.Error()))
  684. return errors.ErrorTransform(err)
  685. }
  686. resp := param_v1_0.BillRemarkResp{
  687. SimpleResp: param_base.SimpleResp{
  688. Code: 0,
  689. Msg: "SUCCESS",
  690. },
  691. }
  692. httper.JSON(u.Ctx, resp, u.LogID)
  693. return nil
  694. }
  695. // 执行以上定义的任务
  696. task.Do(&task.PanicRecover{
  697. Ctx: u.Ctx,
  698. LogID: u.LogID}, u.Ctx,
  699. getParamsTask, handleDataTask,
  700. )
  701. }
  702. // @Title 生成账单
  703. // @Description 生成账单
  704. // @Param token header string true "token"
  705. // @Param uid header int64 true "admin id"
  706. // @Param month query int64 false "页号"
  707. // @Success 200 {object} params.param_v1_0.BillListResp "响应信息"
  708. // @Failure 500 服务器错误
  709. // @router /generate_bill [get]
  710. func (u *AccountingController) GenerateBill() {
  711. u.LogID = fmt.Sprintf("GenerateBill[%d]", time.Now().UnixNano())
  712. req := &param_v1_0.GenerateBillReq{}
  713. getParamsTask := func() error {
  714. httper.FillRequireParams(u.Ctx, req, u.LogID)
  715. return nil
  716. }
  717. handleDataTask := func() error {
  718. mreq := gd_management.GenerateBillReq{}
  719. mreq.Month = req.Month
  720. reply, err := rpc_apis.Management.GenerateBill(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  721. if err != nil {
  722. l.Error("rpc",
  723. zap.String("call", "GenerateBill"),
  724. zap.String("args", utils.MarshalJsonString(req)),
  725. zap.String("error", err.Error()))
  726. return errors.ErrorTransform(err)
  727. }
  728. resp := param_v1_0.GenerateBillResp{
  729. SimpleResp: param_base.SimpleResp{
  730. Code: 0,
  731. Msg: "SUCCESS",
  732. },
  733. }
  734. resp.Data = reply
  735. httper.JSON(u.Ctx, resp, u.LogID)
  736. return nil
  737. }
  738. // 执行以上定义的任务
  739. task.Do(&task.PanicRecover{
  740. Ctx: u.Ctx,
  741. LogID: u.LogID}, u.Ctx,
  742. getParamsTask, handleDataTask,
  743. )
  744. }
  745. // @Title 账单导出Excel
  746. // @Description 账单导出Excel
  747. // @Param token header string true "token"
  748. // @Param uid header int64 true "admin id"
  749. // @Param merchant_id query int64 true "商户id"
  750. // @Param bill_id query int64 true "账单id"
  751. // @Param month query string true "月份(2022-02)"
  752. // @Success 200 {object} params.param_v1_0.BillExportExcelResp "响应信息"
  753. // @Failure 500 服务器错误
  754. // @router /bill_export_excel [get]
  755. func (u *AccountingController) BillExportExcel() {
  756. u.LogID = fmt.Sprintf("BillExportExcel[%d]", time.Now().UnixNano())
  757. req := &param_v1_0.BillExportExcelReq{}
  758. getParamsTask := func() error {
  759. httper.FillRequireParams(u.Ctx, req, u.LogID)
  760. return nil
  761. }
  762. handleDataTask := func() error {
  763. mreq := gd_management.BillExportExcelReq{}
  764. mreq.MerchantId = req.MerchantId
  765. mreq.Month = req.Month
  766. mreq.BillId = req.BillId
  767. reply, err := rpc_apis.Management.BillExportExcel(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  768. if err != nil {
  769. l.Error("rpc",
  770. zap.String("call", "BillExportExcel"),
  771. zap.String("args", utils.MarshalJsonString(req)),
  772. zap.String("error", err.Error()))
  773. return errors.ErrorTransform(err)
  774. }
  775. resp := param_v1_0.BillExportExcelResp{
  776. SimpleResp: param_base.SimpleResp{
  777. Code: 0,
  778. Msg: "SUCCESS",
  779. },
  780. }
  781. resp.Data = reply
  782. httper.JSON(u.Ctx, resp, u.LogID)
  783. return nil
  784. }
  785. // 执行以上定义的任务
  786. task.Do(&task.PanicRecover{
  787. Ctx: u.Ctx,
  788. LogID: u.LogID}, u.Ctx,
  789. getParamsTask, handleDataTask,
  790. )
  791. }