Reimburse.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. package controllers
  2. import (
  3. "ERP_salary/Nats/NatsServer"
  4. "ERP_salary/conf"
  5. "ERP_salary/logs"
  6. "ERP_salary/models/Account"
  7. "ERP_salary/models/Reimburse"
  8. "encoding/json"
  9. "fmt"
  10. powerlibs "git.baozhida.cn/ERP_libs/Power"
  11. userlibs "git.baozhida.cn/ERP_libs/User"
  12. "git.baozhida.cn/ERP_libs/lib"
  13. "github.com/beego/beego/v2/adapter/orm"
  14. "strconv"
  15. "strings"
  16. //"github.com/beego/beego/v2/client/orm"
  17. beego "github.com/beego/beego/v2/server/web"
  18. "math"
  19. "time"
  20. )
  21. type ReimburseController struct {
  22. beego.Controller
  23. User userlibs.User
  24. }
  25. func (c *ReimburseController) Prepare() {
  26. c.User = *Account.User_r
  27. }
  28. func (c *ReimburseController) CheckRBAC(T_power string) {
  29. o := orm.NewOrm()
  30. powerDao := powerlibs.NewPower(o)
  31. power, err := powerDao.Read_Power_ByT_id(T_power)
  32. if err != nil {
  33. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权访问!"}
  34. c.ServeJSON()
  35. return
  36. }
  37. if power.T_menu == "*" {
  38. return
  39. }
  40. api := Account.Read_API_List_ByPower(power.T_id, power.T_menu)
  41. flag := false
  42. for _, v := range api {
  43. if v.T_uri == c.Ctx.Request.URL.Path {
  44. flag = true
  45. break
  46. }
  47. }
  48. if !flag {
  49. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权访问!"}
  50. c.ServeJSON()
  51. return
  52. }
  53. }
  54. func (c *ReimburseController) User_List() {
  55. var r_jsons lib.R_JSONS
  56. // 分页参数 初始化
  57. page, _ := c.GetInt("page")
  58. if page < 1 {
  59. page = 1
  60. }
  61. page_z, _ := c.GetInt("page_z")
  62. if page_z < 1 {
  63. page_z = conf.Page_size
  64. }
  65. T_name := c.GetString("T_name")
  66. ReimburseDao := Reimburse.NewReimburse(orm.NewOrm())
  67. uuidList := ReimburseDao.Read_T_uuid_List()
  68. if len(uuidList) == 0 {
  69. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  70. c.ServeJSON()
  71. return
  72. }
  73. WaitAuditList := ReimburseDao.Read_T_uuid_List_by_State(Reimburse.WaitAudit)
  74. WaitAuditListMap := make(map[string]struct{})
  75. for _, v := range WaitAuditList {
  76. WaitAuditListMap[v] = struct{}{}
  77. }
  78. type User struct {
  79. userlibs.User
  80. T_wait_audit bool `json:"T_wait_audit"`
  81. }
  82. R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z)
  83. if err != nil {
  84. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"}
  85. c.ServeJSON()
  86. return
  87. }
  88. var U_List []User
  89. for _, user := range R_List {
  90. var T_wait_audit bool
  91. if _, ok := WaitAuditListMap[user.T_uuid]; ok {
  92. T_wait_audit = true
  93. }
  94. U_List = append(U_List, User{user, T_wait_audit})
  95. }
  96. r_jsons.Num = R_cnt
  97. r_jsons.Data = U_List
  98. r_jsons.Page = page
  99. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  100. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  101. c.ServeJSON()
  102. return
  103. }
  104. // 消费类型
  105. func (c *ReimburseController) FeeType_List() {
  106. type Reimburse_R struct {
  107. Id int
  108. T_name string
  109. T_mid int
  110. T_State int
  111. FeeDetails []Reimburse.FeeType
  112. }
  113. var res []Reimburse_R
  114. list := Reimburse.Read_FeeType_List()
  115. for _, v := range list {
  116. res = append(res, Reimburse_R{
  117. Id: v.Id,
  118. T_name: v.T_name,
  119. T_mid: v.T_mid,
  120. T_State: v.T_State,
  121. FeeDetails: Reimburse.Read_FeeDetails_List(v.Id),
  122. })
  123. }
  124. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: res}
  125. c.ServeJSON()
  126. return
  127. }
  128. //func (c *ReimburseController) FeeType_List() {
  129. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Reimburse.Read_FeeType_List()}
  130. // c.ServeJSON()
  131. // return
  132. //}
  133. // 消费明细
  134. func (c *ReimburseController) FeeDetails_List() {
  135. T_feeType, _ := c.GetInt("T_feeType")
  136. if T_feeType == 0 {
  137. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_feeType Err!"}
  138. c.ServeJSON()
  139. return
  140. }
  141. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Reimburse.Read_FeeDetails_List(T_feeType)}
  142. c.ServeJSON()
  143. return
  144. }
  145. // 管理元报销列表
  146. func (c *ReimburseController) Reimburse_List() {
  147. // 分页参数 初始化
  148. page, _ := c.GetInt("page")
  149. if page < 1 {
  150. page = 1
  151. }
  152. page_z, _ := c.GetInt("page_z")
  153. if page_z < 1 {
  154. page_z = conf.Page_size
  155. }
  156. T_uuid := c.GetString("T_uuid")
  157. userList, _ := NatsServer.Read_User_List_All()
  158. Account.Read_User_All_Map(userList)
  159. ReimburseDao := Reimburse.NewReimburse(orm.NewOrm())
  160. reimburse_List, num := ReimburseDao.Read_Reimburse_Finance_List(T_uuid, page, page_z)
  161. var r_jsons lib.R_JSONS
  162. r_jsons.Data = reimburse_List
  163. r_jsons.Num = num
  164. r_jsons.Page = page
  165. r_jsons.Page_size = int(math.Ceil(float64(num) / float64(page_z)))
  166. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  167. c.ServeJSON()
  168. return
  169. }
  170. // 员工报销列表
  171. func (c *ReimburseController) Reimburse_User_List() {
  172. // 分页参数 初始化
  173. page, _ := c.GetInt("page")
  174. if page < 1 {
  175. page = 1
  176. }
  177. page_z, _ := c.GetInt("page_z")
  178. if page_z < 1 {
  179. page_z = conf.Page_size
  180. }
  181. userList, _ := NatsServer.Read_User_List_All()
  182. Account.Read_User_All_Map(userList)
  183. ReimburseDao := Reimburse.NewReimburse(orm.NewOrm())
  184. reimburse_List, num := ReimburseDao.Read_Reimburse_List(c.User.T_uuid, page, page_z)
  185. var r_jsons lib.R_JSONS
  186. r_jsons.Data = reimburse_List
  187. r_jsons.Num = num
  188. r_jsons.Page = page
  189. r_jsons.Page_size = int(math.Ceil(float64(num) / float64(page_z)))
  190. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  191. c.ServeJSON()
  192. return
  193. }
  194. func (c *ReimburseController) Reimburse_Add() {
  195. type RequestBody struct {
  196. User_tokey string
  197. ReimburseDetails []Reimburse.ReimburseDetails
  198. T_money float32
  199. }
  200. var body RequestBody
  201. data := c.Ctx.Input.RequestBody
  202. err := json.Unmarshal(data, &body)
  203. if err != nil {
  204. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json 反序列化错误:" + err.Error()}
  205. c.ServeJSON()
  206. return
  207. }
  208. if len(body.ReimburseDetails) == 0 {
  209. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报销明细不能为空"}
  210. c.ServeJSON()
  211. return
  212. }
  213. user_r, err := NatsServer.Verification(body.User_tokey, "")
  214. if err != nil {
  215. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登陆!"}
  216. c.ServeJSON()
  217. return
  218. }
  219. // 权限验证
  220. c.CheckRBAC(user_r.T_power)
  221. var_ := Reimburse.Reimburse{
  222. T_uid: user_r.T_uuid,
  223. T_date: time.Now().Format("2006-01-02"),
  224. T_money: body.T_money,
  225. T_State: Reimburse.WaitSubmit,
  226. }
  227. o := orm.NewOrm()
  228. o.Begin()
  229. ReimburseDao := Reimburse.NewReimburse(o)
  230. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  231. id, err := ReimburseDao.Add_Reimburse(var_)
  232. if err != nil {
  233. o.Rollback()
  234. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  235. c.ServeJSON()
  236. return
  237. }
  238. for _, v := range body.ReimburseDetails {
  239. reimburseDetails := Reimburse.ReimburseDetails{
  240. T_reimburse_id: int(id),
  241. T_trip_start_time: v.T_trip_start_time,
  242. T_trip_end_time: v.T_trip_end_time,
  243. T_trip_origin: v.T_trip_origin,
  244. T_trip_terminus: v.T_trip_terminus,
  245. T_fee_type: v.T_fee_type,
  246. T_fee_details: v.T_fee_details,
  247. T_money: v.T_money,
  248. T_reasons: v.T_reasons,
  249. T_project: v.T_project,
  250. T_img: v.T_img,
  251. T_State: 1,
  252. }
  253. _, err = ReimburseDetailsDao.Add_ReimburseDetails(reimburseDetails)
  254. if err != nil {
  255. o.Rollback()
  256. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  257. c.ServeJSON()
  258. return
  259. }
  260. }
  261. o.Commit()
  262. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "添加", var_)
  263. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
  264. c.ServeJSON()
  265. return
  266. }
  267. func (c *ReimburseController) Reimburse_Edit() {
  268. type RequestBody struct {
  269. User_tokey string
  270. ReimburseDetails []Reimburse.ReimburseDetails
  271. T_money float32
  272. T_id int
  273. }
  274. var body RequestBody
  275. data := c.Ctx.Input.RequestBody
  276. err := json.Unmarshal(data, &body)
  277. if err != nil {
  278. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json.Unmarshal is err:" + err.Error()}
  279. c.ServeJSON()
  280. return
  281. }
  282. user_r, err := NatsServer.Verification(body.User_tokey, "")
  283. if err != nil {
  284. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登陆!"}
  285. c.ServeJSON()
  286. return
  287. }
  288. // 权限验证
  289. c.CheckRBAC(user_r.T_power)
  290. o := orm.NewOrm()
  291. o.Begin()
  292. ReimburseDao := Reimburse.NewReimburse(o)
  293. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  294. reimburse, err := ReimburseDao.Read_Reimburse_ById(body.T_id)
  295. if err != nil {
  296. o.Rollback()
  297. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err"}
  298. c.ServeJSON()
  299. return
  300. }
  301. if len(body.ReimburseDetails) == 0 {
  302. o.Rollback()
  303. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报销明细不能为空"}
  304. c.ServeJSON()
  305. return
  306. }
  307. reimburse.T_money = body.T_money
  308. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_money")
  309. if err != nil {
  310. o.Rollback()
  311. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err"}
  312. c.ServeJSON()
  313. return
  314. }
  315. // 删除之前的报销明细
  316. err = ReimburseDetailsDao.Delete_ReimburseDetails(body.T_id)
  317. if err != nil {
  318. o.Rollback()
  319. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  320. c.ServeJSON()
  321. return
  322. }
  323. for _, v := range body.ReimburseDetails {
  324. reimburseDetails := Reimburse.ReimburseDetails{
  325. T_reimburse_id: reimburse.Id,
  326. T_trip_start_time: v.T_trip_start_time,
  327. T_trip_end_time: v.T_trip_end_time,
  328. T_trip_origin: v.T_trip_origin,
  329. T_trip_terminus: v.T_trip_terminus,
  330. T_fee_type: v.T_fee_type,
  331. T_fee_details: v.T_fee_details,
  332. T_money: v.T_money,
  333. T_reasons: v.T_reasons,
  334. T_project: v.T_project,
  335. T_img: v.T_img,
  336. T_State: 1,
  337. }
  338. _, err = ReimburseDetailsDao.Add_ReimburseDetails(reimburseDetails)
  339. if err != nil {
  340. o.Rollback()
  341. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  342. c.ServeJSON()
  343. return
  344. }
  345. }
  346. o.Commit()
  347. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "修改", reimburse)
  348. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: reimburse.Id}
  349. c.ServeJSON()
  350. return
  351. }
  352. func (c *ReimburseController) Reimburse_Del() {
  353. T_id, _ := c.GetInt("T_id")
  354. o := orm.NewOrm()
  355. o.Begin()
  356. ReimburseDao := Reimburse.NewReimburse(o)
  357. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  358. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  359. if err != nil {
  360. o.Rollback()
  361. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  362. c.ServeJSON()
  363. return
  364. }
  365. if reimburse.T_State == Reimburse.AuditPass || reimburse.T_State == Reimburse.RemitPart || reimburse.T_State == Reimburse.RemitAll {
  366. o.Rollback()
  367. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同已审核通过或已打款,禁止删除!"}
  368. c.ServeJSON()
  369. return
  370. }
  371. _, err = ReimburseDao.Delete_Reimburse(reimburse)
  372. if err != nil {
  373. o.Rollback()
  374. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  375. c.ServeJSON()
  376. return
  377. }
  378. //删除报销明细
  379. err = ReimburseDetailsDao.Delete_ReimburseDetails(reimburse.Id)
  380. if err != nil {
  381. o.Rollback()
  382. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  383. c.ServeJSON()
  384. return
  385. }
  386. o.Commit()
  387. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "删除", err)
  388. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: reimburse.Id}
  389. c.ServeJSON()
  390. return
  391. }
  392. func (c *ReimburseController) Reimburse_Get() {
  393. logs.Info("header=======", c.Ctx.Request.Header.Get("User_tokey"))
  394. T_id, _ := c.GetInt("T_id")
  395. o := orm.NewOrm()
  396. ReimburseDao := Reimburse.NewReimburse(o)
  397. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  398. Reimburse.Read_FeeType_All_Map()
  399. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  400. if err != nil {
  401. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  402. c.ServeJSON()
  403. return
  404. }
  405. //删除报销明细
  406. reimburseDetailsList, err := ReimburseDetailsDao.Read_ReimburseDetailsList_ByT_reimburse_id(reimburse.Id)
  407. if err != nil {
  408. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  409. c.ServeJSON()
  410. return
  411. }
  412. var pList []Reimburse.ReimburseDetails_R
  413. for _, v := range reimburseDetailsList {
  414. p := Reimburse.ReimburseDetailsToReimburseDetails_R(v)
  415. pList = append(pList, p)
  416. }
  417. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "删除", err)
  418. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Reimburse.ReimburseToReimburse_Detail(reimburse, pList)}
  419. c.ServeJSON()
  420. return
  421. }
  422. // 提交审核
  423. func (c *ReimburseController) Reimburse_Submit_Audit() {
  424. T_id, _ := c.GetInt("T_id")
  425. o := orm.NewOrm()
  426. ReimburseDao := Reimburse.NewReimburse(o)
  427. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  428. if err != nil {
  429. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  430. c.ServeJSON()
  431. return
  432. }
  433. if c.User.T_uuid != reimburse.T_uid {
  434. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  435. c.ServeJSON()
  436. return
  437. }
  438. if reimburse.T_State != Reimburse.WaitSubmit && reimburse.T_State != Reimburse.AuditUnPass {
  439. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交审核!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  440. c.ServeJSON()
  441. return
  442. }
  443. reimburse.T_State = Reimburse.WaitAudit
  444. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_State")
  445. if err != nil {
  446. c.Data["json"] = lib.JSONS{Code: 202, Msg: "提交审核失败!"}
  447. c.ServeJSON()
  448. return
  449. }
  450. NatsServer.AddNews(conf.FinanceUuid, fmt.Sprintf("【报销审核】您有一条%s的报销审核待处理", c.User.T_name), conf.ReimburseApprovalUrl)
  451. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "提交审核", err)
  452. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  453. c.ServeJSON()
  454. return
  455. }
  456. // 修改审核状态
  457. func (c *ReimburseController) Reimburse_Edit_Audit() {
  458. T_id, _ := c.GetInt("T_id")
  459. T_State, _ := c.GetInt("T_State")
  460. o := orm.NewOrm()
  461. ReimburseDao := Reimburse.NewReimburse(o)
  462. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  463. if err != nil {
  464. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  465. c.ServeJSON()
  466. return
  467. }
  468. if reimburse.T_State == Reimburse.WaitSubmit {
  469. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  470. c.ServeJSON()
  471. return
  472. }
  473. if T_State == Reimburse.RemitPart || T_State == Reimburse.RemitAll {
  474. if reimburse.T_State != Reimburse.AuditPass && reimburse.T_State != Reimburse.RemitPart {
  475. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  476. c.ServeJSON()
  477. return
  478. }
  479. }
  480. if T_State == Reimburse.AuditPass || T_State == Reimburse.AuditUnPass {
  481. if reimburse.T_State != Reimburse.WaitAudit && T_State != Reimburse.AuditUnPass {
  482. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  483. c.ServeJSON()
  484. return
  485. }
  486. }
  487. reimburse.T_State = T_State
  488. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_State")
  489. if err != nil {
  490. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改审核状态失败!"}
  491. c.ServeJSON()
  492. return
  493. }
  494. NatsServer.AddNews(reimburse.T_uid, fmt.Sprintf("【报销申请】您的报销申请%s", Reimburse.Read_Audit_Get(T_State)), conf.MyReimburseUrl)
  495. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "修改审核状态", err)
  496. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  497. c.ServeJSON()
  498. return
  499. }
  500. // 修改(财务)
  501. func (c *ReimburseController) Reimburse_Edit_Finance() {
  502. T_id, _ := c.GetInt("T_id")
  503. T_approval_money, _ := c.GetFloat("T_approval_money")
  504. T_approval_details := c.GetString("T_approval_details")
  505. T_remit_details := c.GetString("T_remit_detials")
  506. o := orm.NewOrm()
  507. o.Begin()
  508. ReimburseDao := Reimburse.NewReimburse(o)
  509. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  510. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  511. if err != nil {
  512. o.Rollback()
  513. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  514. c.ServeJSON()
  515. return
  516. }
  517. // 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
  518. if reimburse.T_State == Reimburse.WaitSubmit {
  519. o.Rollback()
  520. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  521. c.ServeJSON()
  522. return
  523. }
  524. approval_details_list := strings.Split(strings.Trim(T_approval_details, "|"), "|")
  525. for _, detail := range approval_details_list {
  526. id, _ := strconv.Atoi(strings.Split(detail, ",")[0])
  527. money := lib.StringToFloat64TwoDecimal(strings.Split(detail, ",")[1]) // 审批金额
  528. opinion := strings.Split(detail, ",")[2] // 审批意见
  529. err = ReimburseDetailsDao.Update_ReimburseDetails(Reimburse.ReimburseDetails{
  530. Id: id,
  531. T_approval_money: float32(money),
  532. T_approval_opinion: opinion,
  533. }, "T_approval_money", "T_approval_opinion")
  534. if err != nil {
  535. o.Rollback()
  536. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改报销详情失败!"}
  537. c.ServeJSON()
  538. return
  539. }
  540. }
  541. var T_remit float32
  542. remitList := Reimburse.ReimburseToRemitDetail(T_remit_details)
  543. for _, r := range remitList {
  544. T_remit += r.T_money
  545. }
  546. if T_remit == reimburse.T_approval_money && T_remit > 0 {
  547. reimburse.T_State = Reimburse.RemitAll
  548. } else if T_remit < reimburse.T_approval_money && T_remit > 0 {
  549. reimburse.T_State = Reimburse.RemitPart
  550. }
  551. reimburse.T_remit = T_remit
  552. reimburse.T_approval_money = float32(T_approval_money)
  553. reimburse.T_remit_detials = T_remit_details
  554. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_State", "T_remit", "T_remit_detials", "T_approval_money")
  555. if err != nil {
  556. o.Rollback()
  557. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改审核状态失败!"}
  558. c.ServeJSON()
  559. return
  560. }
  561. o.Commit()
  562. if T_remit > 0 {
  563. NatsServer.AddNews(reimburse.T_uid, fmt.Sprintf("【报销打款】您的报销申请已%s", Reimburse.Read_Audit_Get(reimburse.T_State)), conf.MyReimburseUrl)
  564. }
  565. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "修改(财务)", err)
  566. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  567. c.ServeJSON()
  568. return
  569. }