Reimburse.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. if body.T_money == 0 {
  308. o.Rollback()
  309. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报销金额不能为0"}
  310. c.ServeJSON()
  311. return
  312. }
  313. reimburse.T_money = body.T_money
  314. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_money")
  315. if err != nil {
  316. o.Rollback()
  317. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err"}
  318. c.ServeJSON()
  319. return
  320. }
  321. // 删除之前的报销明细
  322. err = ReimburseDetailsDao.Delete_ReimburseDetails(body.T_id)
  323. if err != nil {
  324. o.Rollback()
  325. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  326. c.ServeJSON()
  327. return
  328. }
  329. for _, v := range body.ReimburseDetails {
  330. reimburseDetails := Reimburse.ReimburseDetails{
  331. T_reimburse_id: reimburse.Id,
  332. T_trip_start_time: v.T_trip_start_time,
  333. T_trip_end_time: v.T_trip_end_time,
  334. T_trip_origin: v.T_trip_origin,
  335. T_trip_terminus: v.T_trip_terminus,
  336. T_fee_type: v.T_fee_type,
  337. T_fee_details: v.T_fee_details,
  338. T_money: v.T_money,
  339. T_reasons: v.T_reasons,
  340. T_project: v.T_project,
  341. T_img: v.T_img,
  342. T_State: 1,
  343. }
  344. _, err = ReimburseDetailsDao.Add_ReimburseDetails(reimburseDetails)
  345. if err != nil {
  346. o.Rollback()
  347. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  348. c.ServeJSON()
  349. return
  350. }
  351. }
  352. o.Commit()
  353. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "修改", reimburse)
  354. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: reimburse.Id}
  355. c.ServeJSON()
  356. return
  357. }
  358. func (c *ReimburseController) Reimburse_Del() {
  359. T_id, _ := c.GetInt("T_id")
  360. o := orm.NewOrm()
  361. o.Begin()
  362. ReimburseDao := Reimburse.NewReimburse(o)
  363. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  364. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  365. if err != nil {
  366. o.Rollback()
  367. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  368. c.ServeJSON()
  369. return
  370. }
  371. if reimburse.T_State == Reimburse.AuditPass || reimburse.T_State == Reimburse.RemitPart || reimburse.T_State == Reimburse.RemitAll {
  372. o.Rollback()
  373. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同已审核通过或已打款,禁止删除!"}
  374. c.ServeJSON()
  375. return
  376. }
  377. _, err = ReimburseDao.Delete_Reimburse(reimburse)
  378. if err != nil {
  379. o.Rollback()
  380. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  381. c.ServeJSON()
  382. return
  383. }
  384. //删除报销明细
  385. err = ReimburseDetailsDao.Delete_ReimburseDetails(reimburse.Id)
  386. if err != nil {
  387. o.Rollback()
  388. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  389. c.ServeJSON()
  390. return
  391. }
  392. o.Commit()
  393. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "删除", T_id)
  394. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: reimburse.Id}
  395. c.ServeJSON()
  396. return
  397. }
  398. func (c *ReimburseController) Reimburse_Get() {
  399. logs.Info("header=======", c.Ctx.Request.Header.Get("User_tokey"))
  400. T_id, _ := c.GetInt("T_id")
  401. o := orm.NewOrm()
  402. ReimburseDao := Reimburse.NewReimburse(o)
  403. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  404. Reimburse.Read_FeeType_All_Map()
  405. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  406. if err != nil {
  407. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  408. c.ServeJSON()
  409. return
  410. }
  411. //删除报销明细
  412. reimburseDetailsList, err := ReimburseDetailsDao.Read_ReimburseDetailsList_ByT_reimburse_id(reimburse.Id)
  413. if err != nil {
  414. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  415. c.ServeJSON()
  416. return
  417. }
  418. var pList []Reimburse.ReimburseDetails_R
  419. for _, v := range reimburseDetailsList {
  420. p := Reimburse.ReimburseDetailsToReimburseDetails_R(v)
  421. pList = append(pList, p)
  422. }
  423. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "删除", T_id)
  424. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Reimburse.ReimburseToReimburse_Detail(reimburse, pList)}
  425. c.ServeJSON()
  426. return
  427. }
  428. // 提交审核
  429. func (c *ReimburseController) Reimburse_Submit_Audit() {
  430. T_id, _ := c.GetInt("T_id")
  431. o := orm.NewOrm()
  432. ReimburseDao := Reimburse.NewReimburse(o)
  433. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  434. if err != nil {
  435. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  436. c.ServeJSON()
  437. return
  438. }
  439. if reimburse.T_money == 0 {
  440. c.Data["json"] = lib.JSONS{Code: 202, Msg: "报销总金额为0,请检查!"}
  441. c.ServeJSON()
  442. return
  443. }
  444. if c.User.T_uuid != reimburse.T_uid {
  445. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  446. c.ServeJSON()
  447. return
  448. }
  449. if reimburse.T_State != Reimburse.WaitSubmit && reimburse.T_State != Reimburse.AuditUnPass {
  450. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交审核!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  451. c.ServeJSON()
  452. return
  453. }
  454. reimburse.T_State = Reimburse.WaitAudit
  455. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_State")
  456. if err != nil {
  457. c.Data["json"] = lib.JSONS{Code: 202, Msg: "提交审核失败!"}
  458. c.ServeJSON()
  459. return
  460. }
  461. NatsServer.AddNews(conf.FinanceUuid, fmt.Sprintf("【报销审核】您有一条%s的报销审核待处理", c.User.T_name), conf.ReimburseApprovalUrl)
  462. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "提交审核", reimburse)
  463. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  464. c.ServeJSON()
  465. return
  466. }
  467. // 修改审核状态
  468. func (c *ReimburseController) Reimburse_Edit_Audit() {
  469. T_id, _ := c.GetInt("T_id")
  470. T_State, _ := c.GetInt("T_State")
  471. o := orm.NewOrm()
  472. ReimburseDao := Reimburse.NewReimburse(o)
  473. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  474. if err != nil {
  475. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  476. c.ServeJSON()
  477. return
  478. }
  479. if reimburse.T_State == Reimburse.WaitSubmit {
  480. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  481. c.ServeJSON()
  482. return
  483. }
  484. if T_State == Reimburse.RemitPart || T_State == Reimburse.RemitAll {
  485. if reimburse.T_State != Reimburse.AuditPass && reimburse.T_State != Reimburse.RemitPart {
  486. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  487. c.ServeJSON()
  488. return
  489. }
  490. }
  491. if T_State == Reimburse.AuditPass || T_State == Reimburse.AuditUnPass {
  492. if reimburse.T_State != Reimburse.WaitAudit && T_State != Reimburse.AuditUnPass {
  493. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  494. c.ServeJSON()
  495. return
  496. }
  497. }
  498. reimburse.T_State = T_State
  499. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_State")
  500. if err != nil {
  501. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改审核状态失败!"}
  502. c.ServeJSON()
  503. return
  504. }
  505. NatsServer.AddNews(reimburse.T_uid, fmt.Sprintf("【报销申请】您的报销申请%s", Reimburse.Read_Audit_Get(T_State)), conf.MyReimburseUrl)
  506. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "修改审核状态", reimburse)
  507. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  508. c.ServeJSON()
  509. return
  510. }
  511. // 修改(财务)
  512. func (c *ReimburseController) Reimburse_Edit_Finance() {
  513. T_id, _ := c.GetInt("T_id")
  514. T_approval_money, _ := c.GetFloat("T_approval_money")
  515. T_approval_details := c.GetString("T_approval_details")
  516. T_remit_details := c.GetString("T_remit_detials")
  517. o := orm.NewOrm()
  518. o.Begin()
  519. ReimburseDao := Reimburse.NewReimburse(o)
  520. ReimburseDetailsDao := Reimburse.NewReimburseDetails(o)
  521. reimburse, err := ReimburseDao.Read_Reimburse_ById(T_id)
  522. if err != nil {
  523. o.Rollback()
  524. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  525. c.ServeJSON()
  526. return
  527. }
  528. // 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
  529. if reimburse.T_State == Reimburse.WaitSubmit {
  530. o.Rollback()
  531. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Reimburse.Read_Audit_Get(reimburse.T_State))}
  532. c.ServeJSON()
  533. return
  534. }
  535. approval_details_list := strings.Split(strings.Trim(T_approval_details, "|"), "|")
  536. for _, detail := range approval_details_list {
  537. id, _ := strconv.Atoi(strings.Split(detail, ",")[0])
  538. money := lib.StringToFloat64TwoDecimal(strings.Split(detail, ",")[1]) // 审批金额
  539. opinion := strings.Split(detail, ",")[2] // 审批意见
  540. err = ReimburseDetailsDao.Update_ReimburseDetails(Reimburse.ReimburseDetails{
  541. Id: id,
  542. T_approval_money: float32(money),
  543. T_approval_opinion: opinion,
  544. }, "T_approval_money", "T_approval_opinion")
  545. if err != nil {
  546. o.Rollback()
  547. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改报销详情失败!"}
  548. c.ServeJSON()
  549. return
  550. }
  551. }
  552. var T_remit float32
  553. remitList := Reimburse.ReimburseToRemitDetail(T_remit_details)
  554. for _, r := range remitList {
  555. T_remit += r.T_money
  556. }
  557. if T_remit == reimburse.T_approval_money && T_remit > 0 {
  558. reimburse.T_State = Reimburse.RemitAll
  559. } else if T_remit < reimburse.T_approval_money && T_remit > 0 {
  560. reimburse.T_State = Reimburse.RemitPart
  561. }
  562. reimburse.T_remit = T_remit
  563. reimburse.T_approval_money = float32(T_approval_money)
  564. reimburse.T_remit_detials = T_remit_details
  565. _, err = ReimburseDao.Update_Reimburse(reimburse, "T_State", "T_remit", "T_remit_detials", "T_approval_money")
  566. if err != nil {
  567. o.Rollback()
  568. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改审核状态失败!"}
  569. c.ServeJSON()
  570. return
  571. }
  572. o.Commit()
  573. if T_remit > 0 {
  574. NatsServer.AddNews(reimburse.T_uid, fmt.Sprintf("【报销打款】您的报销申请已%s", Reimburse.Read_Audit_Get(reimburse.T_State)), conf.MyReimburseUrl)
  575. }
  576. NatsServer.AddUserLogs(c.User.T_uuid, "报销", "修改(财务)", reimburse)
  577. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  578. c.ServeJSON()
  579. return
  580. }