Reimburse.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. package Reimburse
  2. import (
  3. "ERP_salary/logs"
  4. "ERP_salary/models/Account"
  5. "fmt"
  6. "git.baozhida.cn/ERP_libs/lib"
  7. "github.com/beego/beego/v2/adapter/orm"
  8. orm2 "github.com/beego/beego/v2/client/orm"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. const (
  14. Delete int = iota
  15. WaitSubmit // 待提交审核
  16. WaitAudit // 待审核
  17. AuditPass // 审核通过
  18. AuditUnPass // 审核不通过
  19. RemitPart // 部分打款
  20. RemitAll // 全部打款
  21. )
  22. var (
  23. AuditMap = map[int]string{
  24. WaitSubmit: "待提交审核",
  25. WaitAudit: "待审核",
  26. AuditPass: "审核通过",
  27. AuditUnPass: "审核不通过",
  28. RemitPart: "部分打款",
  29. RemitAll: "全部打款",
  30. }
  31. )
  32. func Read_Audit_Get(Id int) string {
  33. v, ok := AuditMap[Id]
  34. if ok {
  35. return v
  36. } else {
  37. return "未知状态"
  38. }
  39. }
  40. // 报销
  41. type Reimburse struct {
  42. Id int `orm:"column(ID);size(11);auto;pk"`
  43. T_uid string `orm:"index;size(64);null"` // 用户uuid
  44. T_date string `orm:"size(64);null"` // 提交日期,2023-08-11
  45. T_money float32 `orm:"digits(12);decimals(2)"` // 报销总金额
  46. T_remit float32 `orm:"digits(12);decimals(2)"` // 打款金额
  47. T_State int `orm:"size(20);default(1)"` // 0 删除 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
  48. T_remit_detials string `orm:"size(1024)"` // 打款明细 日期,打款金额|日期,打款金额|
  49. T_approval_money float32 `orm:"digits(12);decimals(2)"` // 审批金额
  50. CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
  51. UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
  52. }
  53. func (t *Reimburse) TableName() string {
  54. return "reimburse"
  55. }
  56. type ReimburseDaoImpl struct {
  57. orm orm.Ormer
  58. }
  59. func NewReimburse(orm orm.Ormer) *ReimburseDaoImpl {
  60. return &ReimburseDaoImpl{orm: orm}
  61. }
  62. func init() {
  63. //注册模型
  64. orm.Debug = true
  65. orm.RegisterModel(new(Reimburse))
  66. }
  67. type Reimburse_R struct {
  68. Id int
  69. T_uid string // 用户uuid
  70. T_user_name string // 用户名称
  71. T_date string // 提交日期,2023-08-11
  72. T_money float32 // 报销总金额
  73. T_remit float32 // 打款金额
  74. T_approval_money float32 // 审批金额
  75. T_State int // 0 删除 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
  76. }
  77. type RemitDetail_R struct {
  78. T_time string // 打款时间
  79. T_money float32 // 打款金额
  80. }
  81. type Reimburse_Detail struct {
  82. Id int
  83. T_uid string // 用户uuid
  84. T_user_name string // 用户名称
  85. T_date string // 提交日期,2023-08-11
  86. T_money float32 // 报销总金额
  87. T_remit float32 // 打款金额
  88. T_State int // 0 删除 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
  89. T_approval_money float32 // 审批金额
  90. T_approval_opinion string // 审批意见
  91. T_reimburse_details []ReimburseDetails_R // 报销明细
  92. T_remit_detail []RemitDetail_R // 打款明细
  93. }
  94. // ---------------- 特殊方法 -------------------
  95. func ReimburseToReimburse_R(t Reimburse) (r Reimburse_R) {
  96. r.Id = t.Id
  97. r.T_uid = t.T_uid
  98. r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
  99. r.T_date = t.T_date
  100. r.T_money = t.T_money
  101. r.T_remit = t.T_remit
  102. r.T_State = t.T_State
  103. r.T_approval_money = t.T_approval_money
  104. return r
  105. }
  106. func ReimburseToReimburse_Detail(t Reimburse, T_reimburse_details []ReimburseDetails_R) (r Reimburse_Detail) {
  107. r.Id = t.Id
  108. r.T_uid = t.T_uid
  109. r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
  110. r.T_date = t.T_date
  111. r.T_money = t.T_money
  112. r.T_remit = t.T_remit
  113. r.T_State = t.T_State
  114. r.T_approval_money = t.T_approval_money
  115. r.T_reimburse_details = T_reimburse_details
  116. r.T_remit_detail = ReimburseToRemitDetail(t.T_remit_detials)
  117. return r
  118. }
  119. func ReimburseToRemitDetail(T_detail string) (r []RemitDetail_R) {
  120. if len(T_detail) == 0 {
  121. return
  122. }
  123. detailList := strings.Split(strings.Trim(T_detail, "|"), "|")
  124. for _, detail := range detailList {
  125. T_time := strings.Split(detail, ",")[0]
  126. T_money := lib.StringToFloat64TwoDecimal(strings.Split(detail, ",")[1])
  127. r = append(r, RemitDetail_R{
  128. T_time: T_time,
  129. T_money: float32(T_money),
  130. })
  131. }
  132. return r
  133. }
  134. func (dao *ReimburseDaoImpl) Read_Reimburse_ById(id int) (r Reimburse, err error) {
  135. o := orm.NewOrm()
  136. r = Reimburse{Id: id}
  137. err = o.Read(&r)
  138. if err != nil {
  139. logs.Error(lib.FuncName(), err)
  140. return r, err
  141. }
  142. return r, err
  143. }
  144. // 添加
  145. func (dao *ReimburseDaoImpl) Add_Reimburse(m Reimburse) (id int64, err error) {
  146. o := orm.NewOrm()
  147. id, err = o.Insert(&m)
  148. if err != nil {
  149. logs.Error(lib.FuncName(), err)
  150. return
  151. }
  152. return
  153. }
  154. // 修改
  155. func (dao *ReimburseDaoImpl) Update_Reimburse(m Reimburse, cols ...string) (id int64, err error) {
  156. o := orm.NewOrm()
  157. id, err = o.Update(&m, cols...)
  158. if err != nil {
  159. logs.Error(lib.FuncName(), err)
  160. return
  161. }
  162. fmt.Println("Number of records updated in database:", id)
  163. return id, nil
  164. }
  165. // 删除
  166. func (dao *ReimburseDaoImpl) Delete_Reimburse(m Reimburse) (id int64, err error) {
  167. o := orm.NewOrm()
  168. m.T_State = Delete
  169. id, err = o.Update(&m, "T_State")
  170. if err != nil {
  171. logs.Error(lib.FuncName(), err)
  172. return
  173. }
  174. fmt.Println("Number of records updated in database:", id)
  175. return id, nil
  176. }
  177. // 获取列表
  178. func (dao *ReimburseDaoImpl) Read_Reimburse_List(T_uid string, page, page_z int) (r []Reimburse_R, cnt int64) {
  179. o := orm.NewOrm()
  180. // 也可以直接使用 Model 结构体作为表名
  181. var map_r []Reimburse
  182. qs := o.QueryTable(new(Reimburse))
  183. var offset int64
  184. if page <= 1 {
  185. offset = 0
  186. } else {
  187. offset = int64((page - 1) * page_z)
  188. }
  189. cond := orm.NewCondition()
  190. cond = cond.And("T_State__gt", Delete)
  191. if len(T_uid) > 0 {
  192. cond = cond.And("T_uid", T_uid)
  193. }
  194. var err error
  195. _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
  196. if err != nil {
  197. logs.Error(lib.FuncName(), err)
  198. return
  199. }
  200. cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
  201. if err != nil {
  202. logs.Error(lib.FuncName(), err)
  203. return
  204. }
  205. for _, v := range map_r {
  206. r = append(r, ReimburseToReimburse_R(v))
  207. }
  208. return r, cnt
  209. }
  210. // 获取列表
  211. func (dao *ReimburseDaoImpl) Read_Reimburse_Finance_List(T_uuid string, page, page_z int) (r []Reimburse_R, cnt int64) {
  212. o := orm.NewOrm()
  213. // 也可以直接使用 Model 结构体作为表名
  214. var map_r []Reimburse
  215. qs := o.QueryTable(new(Reimburse))
  216. var offset int64
  217. if page <= 1 {
  218. offset = 0
  219. } else {
  220. offset = int64((page - 1) * page_z)
  221. }
  222. cond := orm.NewCondition()
  223. state := []int{WaitAudit, AuditPass, AuditUnPass, RemitPart, RemitAll}
  224. cond = cond.And("T_uid", T_uuid).And("T_State__in", state)
  225. var err error
  226. _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
  227. if err != nil {
  228. logs.Error(lib.FuncName(), err)
  229. return
  230. }
  231. cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
  232. if err != nil {
  233. logs.Error(lib.FuncName(), err)
  234. return
  235. }
  236. for _, v := range map_r {
  237. r = append(r, ReimburseToReimburse_R(v))
  238. }
  239. return r, cnt
  240. }
  241. func (dao *ReimburseDaoImpl) Read_T_uuid_List_by_State(state int) (lists []string) {
  242. o := orm.NewOrm()
  243. sql := "SELECT DISTINCT t_uid FROM reimburse WHERE t__state =" + strconv.Itoa(state) + " LIMIT 0,1000"
  244. _, err := o.Raw(sql).QueryRows(&lists)
  245. if err != nil {
  246. logs.Error(lib.FuncName(), err)
  247. return
  248. }
  249. return lists
  250. }
  251. func (dao *ReimburseDaoImpl) Read_T_uuid_List() (lists []string) {
  252. o := orm.NewOrm()
  253. sql := "SELECT DISTINCT t_uid FROM reimburse LIMIT 0,1000"
  254. _, err := o.Raw(sql).QueryRows(&lists)
  255. if err != nil {
  256. logs.Error(lib.FuncName(), err)
  257. return
  258. }
  259. return lists
  260. }