sign_up.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. package signmodel
  2. import (
  3. "strings"
  4. "time"
  5. "go-common/app/admin/main/up/util/now"
  6. "go-common/library/log"
  7. xtime "go-common/library/time"
  8. )
  9. const (
  10. // TableSignPay table name
  11. TableSignPay = "sign_pay"
  12. // TableSignUp table name
  13. TableSignUp = "sign_up"
  14. // TableSignTask table name
  15. TableSignTask = "sign_task"
  16. // TableSignContract table name
  17. TableSignContract = "sign_contract"
  18. // TableSignTaskAbsence table name
  19. TableSignTaskAbsence = "sign_task_absence"
  20. // TableSignTaskHistory table name
  21. TableSignTaskHistory = "sign_task_history"
  22. // TableSignViolationHistory table name
  23. TableSignViolationHistory = "sign_violation_history"
  24. )
  25. const (
  26. // DateDefualtFromDB .
  27. DateDefualtFromDB = -28800
  28. // DateDefualt .
  29. DateDefualt = "0000-00-00"
  30. )
  31. const (
  32. //TaskTypeAccumulate 0
  33. TaskTypeAccumulate = 0
  34. //TaskTypeDay 1
  35. TaskTypeDay = 1
  36. //TaskTypeWeek 2
  37. TaskTypeWeek = 2
  38. //TaskTypeMonth 3
  39. TaskTypeMonth = 3
  40. //TaskTypeQuarter 4 季度
  41. TaskTypeQuarter = 4
  42. )
  43. const (
  44. //TaskStateRunning 0
  45. TaskStateRunning = 0
  46. //TaskStateExpire 1
  47. TaskStateExpire = 1
  48. //TaskStateFinish 2
  49. TaskStateFinish = 2
  50. )
  51. // const .
  52. const (
  53. SignUpMidAdd = 1
  54. SignUpMidUpdate = 2
  55. )
  56. // const 。
  57. const (
  58. NotContainEconomic = 1
  59. ContainEconomic = 2
  60. )
  61. const (
  62. // SignUpLogBizID 签约up信息修改日志
  63. SignUpLogBizID int = 261
  64. )
  65. const (
  66. //SignTaskStateInit init
  67. SignTaskStateInit = 0
  68. //SignTaskStateRunning task running
  69. SignTaskStateRunning = 1
  70. //SignTaskStateFinish finish
  71. SignTaskStateFinish = 2
  72. //SignTaskStateDelete delete
  73. SignTaskStateDelete = 100
  74. )
  75. // const 变更类型.
  76. const (
  77. // 年龄
  78. ChangeSexHistory = iota + 1
  79. // 用户id
  80. ChangeMidHistory
  81. // 签约周期
  82. ChangeSignDateHistory
  83. // 地区
  84. ChangeAreaHistory
  85. // 组织
  86. ChangeOrganizationHistory
  87. // 签约类型
  88. ChangeSignTypeHistory
  89. // 年龄
  90. ChangeAgeHistory
  91. // 居住地
  92. ChangeResidenceHistory
  93. // 身份证
  94. ChangeIDCardHistory
  95. // 联系方式
  96. ChangePhoneHistory
  97. // QQ
  98. ChangeQQHistory
  99. // 微信
  100. ChangeWechatHistory
  101. // 经济公司
  102. ChangeEconomicHistory
  103. // 签约付款周期
  104. ChangeSignPayHistory
  105. // 签约任务
  106. ChangeSignTaskHistory
  107. // 签约合同
  108. ChangeSignContractHistory
  109. // 签约备注
  110. ChangeSignNoteHistory
  111. )
  112. const (
  113. //EmailStateNotSend 0
  114. EmailStateNotSend = 0
  115. //EmailStateSendSucc 1
  116. EmailStateSendSucc = 1
  117. )
  118. const (
  119. // AttrYes on
  120. AttrYes = int64(1)
  121. // AttrNo off
  122. AttrNo = int64(0)
  123. // AttrBitIsBusinessArchive bit
  124. AttrBitIsBusinessArchive = uint(0)
  125. )
  126. // SignUpOnlyID struct
  127. type SignUpOnlyID struct {
  128. ID uint32
  129. }
  130. // SignUpOnlySignID struct
  131. type SignUpOnlySignID struct {
  132. SignID uint32
  133. }
  134. // SignUp struct
  135. type SignUp struct {
  136. ID int64
  137. Sex int8
  138. Mid int64
  139. BeginDate xtime.Time
  140. EndDate xtime.Time
  141. State int8
  142. Country string
  143. Province string
  144. City string
  145. Note string
  146. AdminID int
  147. AdminName string
  148. EmailState int8
  149. Ctime xtime.Time `gorm:"column:ctime"`
  150. Mtime xtime.Time `gorm:"column:mtime"`
  151. Organization int8
  152. SignType int8
  153. Age int8
  154. Residence string
  155. IDCard string `gorm:"column:id_card"`
  156. Phone string
  157. QQ int64 `gorm:"column:qq"`
  158. Wechat string `gorm:"column:wechat"`
  159. IsEconomic int8
  160. EconomicCompany string
  161. EconomicBegin xtime.Time
  162. EconomicEnd xtime.Time
  163. TaskState int8
  164. LeaveTimes int
  165. ViolationTimes int
  166. ActiveTid int16
  167. }
  168. // Diff .
  169. func (su *SignUp) Diff(oriSu *SignUp, fields map[int8]struct{}) {
  170. if oriSu.Sex != su.Sex {
  171. fields[ChangeSexHistory] = struct{}{}
  172. }
  173. if oriSu.Mid != su.Mid {
  174. fields[ChangeMidHistory] = struct{}{}
  175. }
  176. if oriSu.BeginDate != su.BeginDate || oriSu.EndDate != su.EndDate {
  177. fields[ChangeSignDateHistory] = struct{}{}
  178. }
  179. if !strings.EqualFold(oriSu.Country, su.Country) || !strings.EqualFold(oriSu.Province, su.Province) || !strings.EqualFold(oriSu.City, su.City) {
  180. fields[ChangeAreaHistory] = struct{}{}
  181. }
  182. if oriSu.Organization != su.Organization {
  183. fields[ChangeOrganizationHistory] = struct{}{}
  184. }
  185. if oriSu.SignType != su.SignType {
  186. fields[ChangeSignTypeHistory] = struct{}{}
  187. }
  188. if oriSu.Age != su.Age {
  189. fields[ChangeAgeHistory] = struct{}{}
  190. }
  191. if oriSu.Residence != su.Residence {
  192. fields[ChangeResidenceHistory] = struct{}{}
  193. }
  194. if oriSu.IDCard != su.IDCard {
  195. fields[ChangeIDCardHistory] = struct{}{}
  196. }
  197. if oriSu.Phone != su.Phone {
  198. fields[ChangePhoneHistory] = struct{}{}
  199. }
  200. if oriSu.QQ != su.QQ {
  201. fields[ChangeQQHistory] = struct{}{}
  202. }
  203. if oriSu.Wechat != su.Wechat {
  204. fields[ChangeWechatHistory] = struct{}{}
  205. }
  206. if oriSu.EconomicBegin == DateDefualtFromDB {
  207. oriSu.EconomicBegin = 0
  208. }
  209. if oriSu.EconomicEnd == DateDefualtFromDB {
  210. oriSu.EconomicEnd = 0
  211. }
  212. if oriSu.IsEconomic != su.IsEconomic || !strings.EqualFold(oriSu.EconomicCompany, su.EconomicCompany) ||
  213. oriSu.EconomicBegin != su.EconomicBegin || oriSu.EconomicEnd != su.EconomicEnd {
  214. fields[ChangeEconomicHistory] = struct{}{}
  215. }
  216. if !strings.EqualFold(oriSu.Note, su.Note) {
  217. fields[ChangeSignNoteHistory] = struct{}{}
  218. }
  219. su.State = oriSu.State
  220. su.EmailState = oriSu.EmailState
  221. su.TaskState = oriSu.TaskState
  222. su.LeaveTimes = oriSu.LeaveTimes
  223. su.ViolationTimes = oriSu.ViolationTimes
  224. su.ActiveTid = oriSu.ActiveTid
  225. su.Ctime = oriSu.Ctime
  226. }
  227. // SignPay struct
  228. type SignPay struct {
  229. ID int64
  230. Mid int64
  231. SignID int64
  232. DueDate xtime.Time
  233. PayValue int64
  234. State int8
  235. Note string
  236. EmailState int8
  237. Ctime xtime.Time `gorm:"column:ctime"`
  238. Mtime xtime.Time `gorm:"column:mtime"`
  239. InTax int8
  240. }
  241. // Diff .
  242. func (sp *SignPay) Diff(mOriSp map[int64]*SignPay, fields map[int8]struct{}) {
  243. var (
  244. ok bool
  245. oriSp *SignPay
  246. )
  247. if oriSp, ok = mOriSp[sp.ID]; !ok {
  248. fields[ChangeSignPayHistory] = struct{}{}
  249. return
  250. }
  251. if sp.DueDate != oriSp.DueDate || sp.PayValue != oriSp.PayValue || sp.InTax != oriSp.InTax {
  252. fields[ChangeSignPayHistory] = struct{}{}
  253. }
  254. sp.Mid = oriSp.Mid
  255. sp.SignID = oriSp.SignID
  256. sp.State = oriSp.State
  257. sp.Note = oriSp.Note
  258. sp.EmailState = oriSp.EmailState
  259. sp.Ctime = oriSp.Ctime
  260. }
  261. // SignTask struct
  262. type SignTask struct {
  263. ID int64 `gorm:"column:id"`
  264. Mid int64 `gorm:"column:mid"`
  265. SignID int64 `gorm:"column:sign_id"`
  266. TaskType int8 `gorm:"column:task_type"`
  267. TaskCounter int `gorm:"column:task_counter"`
  268. TaskCondition int `gorm:"column:task_condition"`
  269. TaskData string `gorm:"column:task_data"`
  270. State int8 `gorm:"column:state"`
  271. Ctime xtime.Time `gorm:"column:ctime"`
  272. Mtime xtime.Time `gorm:"column:mtime"`
  273. Attribute int64 `gorm:"column:attribute"`
  274. FinishNote string `gorm:"column:finish_note"`
  275. }
  276. // Diff .
  277. func (st *SignTask) Diff(mOriSt map[int64]*SignTask, fields map[int8]struct{}) {
  278. var (
  279. ok bool
  280. oriSt *SignTask
  281. )
  282. if oriSt, ok = mOriSt[st.ID]; !ok {
  283. fields[ChangeSignTaskHistory] = struct{}{}
  284. return
  285. }
  286. if st.TaskType != oriSt.TaskType || st.TaskCondition != oriSt.TaskCondition ||
  287. st.AttrVal(AttrBitIsBusinessArchive) != oriSt.AttrVal(AttrBitIsBusinessArchive) {
  288. fields[ChangeSignTaskHistory] = struct{}{}
  289. }
  290. st.Mid = oriSt.Mid
  291. st.SignID = oriSt.SignID
  292. st.TaskCounter = oriSt.TaskCounter
  293. st.TaskData = oriSt.TaskData
  294. st.State = oriSt.State
  295. st.Ctime = oriSt.Ctime
  296. }
  297. // AttrVal get attribute value.
  298. func (st *SignTask) AttrVal(bit uint) int64 {
  299. return (st.Attribute >> bit) & int64(1)
  300. }
  301. // AttrSet set attribute value.
  302. func (st *SignTask) AttrSet(v int64, bit uint) {
  303. st.Attribute = st.Attribute&(^(1 << bit)) | (v << bit)
  304. }
  305. // SignTaskHistory .
  306. type SignTaskHistory struct {
  307. ID int64 `gorm:"column:id"`
  308. Mid int64 `gorm:"column:mid"`
  309. SignID int64 `gorm:"column:sign_id"`
  310. TaskTemplateID int `gorm:"column:task_template_id"`
  311. TaskType int8 `gorm:"column:task_type"`
  312. TaskCounter int `gorm:"column:task_counter"`
  313. TaskCondition int `gorm:"column:task_condition"`
  314. TaskData string `gorm:"column:task_data"`
  315. Attribute int64 `gorm:"column:attribute"`
  316. State int `gorm:"column:state"`
  317. GenerateDate xtime.Time `gorm:"column:generate_date"`
  318. Ctime xtime.Time `gorm:"column:ctime"`
  319. Mtime xtime.Time `gorm:"column:mtime"`
  320. }
  321. // AttrVal get attribute value.
  322. func (sth *SignTaskHistory) AttrVal(bit uint) int64 {
  323. return (sth.Attribute >> bit) & int64(1)
  324. }
  325. // AttrSet set attribute value.
  326. func (sth *SignTaskHistory) AttrSet(v int64, bit uint) {
  327. sth.Attribute = sth.Attribute&(^(1 << bit)) | (v << bit)
  328. }
  329. //SignContract struct
  330. type SignContract struct {
  331. ID int64 `gorm:"column:id"`
  332. Mid int64
  333. SignID int64
  334. Filename string
  335. Filelink string
  336. State int8
  337. Ctime xtime.Time `gorm:"column:ctime"`
  338. Mtime xtime.Time `gorm:"column:mtime"`
  339. }
  340. // Diff .
  341. func (sc *SignContract) Diff(mOriSc map[int64]*SignContract, fields map[int8]struct{}) {
  342. var (
  343. ok bool
  344. oriSc *SignContract
  345. )
  346. if oriSc, ok = mOriSc[sc.ID]; !ok {
  347. log.Error("OriSc(%d) no exsits", sc.ID)
  348. fields[ChangeSignContractHistory] = struct{}{}
  349. return
  350. }
  351. if !strings.EqualFold(sc.Filelink, oriSc.Filelink) {
  352. log.Error("file(%s)----orc_file(%s) no exsits", sc.Filelink, oriSc.Filelink)
  353. fields[ChangeSignContractHistory] = struct{}{}
  354. }
  355. if !strings.EqualFold(sc.Filename, oriSc.Filename) {
  356. log.Error("filename(%s)----orc_filename(%s) no exsits", sc.Filename, oriSc.Filename)
  357. fields[ChangeSignContractHistory] = struct{}{}
  358. }
  359. sc.Mid = oriSc.Mid
  360. sc.SignID = oriSc.SignID
  361. sc.State = oriSc.State
  362. sc.Ctime = oriSc.Ctime
  363. }
  364. // SignTaskAbsence struct
  365. type SignTaskAbsence struct {
  366. ID int64 `gorm:"column:id"`
  367. SignID int64
  368. Mid int64
  369. TaskHistoryID int64
  370. AbsenceCount int
  371. Reason string
  372. State int8
  373. AdminID int64
  374. AdminName string
  375. Ctime xtime.Time `gorm:"column:ctime"`
  376. Mtime xtime.Time `gorm:"column:mtime"`
  377. }
  378. // SignViolationHistory struct
  379. type SignViolationHistory struct {
  380. ID int64 `gorm:"column:id"`
  381. SignID int64
  382. Mid int64
  383. AdminID int64
  384. AdminName string
  385. ViolationReason string
  386. State int8
  387. Ctime xtime.Time `gorm:"column:ctime"`
  388. Mtime xtime.Time `gorm:"column:mtime"`
  389. }
  390. // GetTaskDuration this will return task duration, [startDate, endDate)
  391. func GetTaskDuration(date time.Time, taskType int8) (startDate, endDate time.Time) {
  392. var ndate = now.New(date)
  393. now.WeekStartDay = time.Monday
  394. switch taskType {
  395. case TaskTypeDay:
  396. var begin = ndate.BeginningOfDay()
  397. return begin, begin.AddDate(0, 0, 1)
  398. case TaskTypeWeek:
  399. var begin = ndate.BeginningOfWeek()
  400. return begin, begin.AddDate(0, 0, 7)
  401. case TaskTypeMonth:
  402. var begin = ndate.BeginningOfMonth()
  403. return begin, begin.AddDate(0, 1, 0)
  404. case TaskTypeQuarter:
  405. var begin = ndate.BeginningOfQuarter()
  406. return begin, begin.AddDate(0, 3, 0)
  407. }
  408. return
  409. }