company.go 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/company"
  9. "hongze/hz_crm_api/models/company_user"
  10. "hongze/hz_crm_api/services/alarm_msg"
  11. "hongze/hz_crm_api/utils"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // AddCompanyPermission 新增客户权限
  17. func AddCompanyPermission(companyId, sysUserId, productId int, productName, sysUserName, permissionStr, startDate, endDate string) (companyReportPermissionList []*company.CompanyReportPermission, err error) {
  18. if permissionStr == "" {
  19. return
  20. }
  21. permissionArr := strings.Split(permissionStr, ",")
  22. count, _ := company.GetCompanyReportPermissionCount(companyId, productId)
  23. //删除权限
  24. if count > 0 {
  25. err = company.DeleteCompanyReportPermission(companyId, productId)
  26. if err != nil {
  27. return
  28. }
  29. }
  30. //如果是ficc类型的客户,且权限列表中没有 宏观权限,那么需要默认将宏观加进去
  31. if productId == utils.COMPANY_PRODUCT_FICC_ID && !utils.InArrayByStr(permissionArr, "1") {
  32. permissionArr = append(permissionArr, "1")
  33. }
  34. for _, pv := range permissionArr {
  35. permissionId, tmpErr := strconv.Atoi(pv)
  36. if productId == utils.COMPANY_PRODUCT_RAI_ID && permissionId == 1 {
  37. continue
  38. }
  39. if tmpErr != nil {
  40. err = tmpErr
  41. return
  42. }
  43. permission := new(company.CompanyReportPermission)
  44. permission.CompanyId = companyId
  45. permission.ReportPermissionId = permissionId
  46. permission.CreatedTime = time.Now()
  47. permission.LastUpdatedTime = time.Now()
  48. permission.ChartPermissionId = permissionId
  49. permission.StartDate = startDate
  50. permission.EndDate = endDate
  51. permission.ProductId = productId
  52. permission.ProductName = productName
  53. permission.ModifyTime = time.Now()
  54. permission.Status = "试用"
  55. err = company.AddCompanyReportPermission(permission)
  56. if err != nil {
  57. return
  58. }
  59. companyReportPermissionList = append(companyReportPermissionList, permission)
  60. cpLog := new(company.CompanyPermissionLog)
  61. cpLog.CompanyId = companyId
  62. cpLog.ChartPermissionId = permissionId
  63. cpLog.CreateTime = time.Now()
  64. cpLog.SysUserId = sysUserId
  65. cpLog.SysUserName = sysUserName
  66. cpLog.StartDate = startDate
  67. cpLog.EndDate = endDate
  68. cpLog.ProductId = productId
  69. cpLog.ProductName = productName
  70. go company.AddCompanyPermissionLog(cpLog)
  71. }
  72. return
  73. }
  74. func AddCompanyProductLog(companyProduct *company.CompanyProduct, adminId int, logType string) (err error) {
  75. defer func() {
  76. if err != nil {
  77. go alarm_msg.SendAlarmMsg("services:AddCompanyProductLog;Err:"+err.Error(), 3)
  78. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyProductLog;Err:"+err.Error(), utils.EmailSendToUsers)
  79. }
  80. }()
  81. productLog := new(company.CompanyProductLog)
  82. productLog.CompanyProductId = companyProduct.CompanyProductId
  83. productLog.CompanyId = companyProduct.CompanyId
  84. productLog.ProductId = companyProduct.ProductId
  85. productLog.ProductName = companyProduct.ProductName
  86. productLog.CompanyName = companyProduct.CompanyName
  87. productLog.CompanyName = companyProduct.CompanyName
  88. productLog.Source = companyProduct.Source
  89. productLog.Reasons = companyProduct.Reasons
  90. productLog.Status = companyProduct.Status
  91. productLog.IndustryId = companyProduct.IndustryId
  92. productLog.IndustryName = companyProduct.IndustryName
  93. productLog.SellerId = companyProduct.SellerId
  94. productLog.SellerName = companyProduct.SellerName
  95. productLog.GroupId = companyProduct.GroupId
  96. productLog.DepartmentId = companyProduct.DepartmentId
  97. productLog.IsSuspend = companyProduct.IsSuspend
  98. productLog.SuspendTime = companyProduct.SuspendTime
  99. productLog.ApproveStatus = companyProduct.ApproveStatus
  100. productLog.FreezeTime = companyProduct.FreezeTime
  101. productLog.Remark = companyProduct.Remark
  102. productLog.StartDate = companyProduct.StartDate
  103. productLog.EndDate = companyProduct.EndDate
  104. productLog.CreateTime = companyProduct.CreateTime
  105. productLog.ModifyTime = companyProduct.ModifyTime
  106. productLog.LoseReason = companyProduct.LoseReason
  107. productLog.LossTime = companyProduct.LossTime
  108. productLog.LogType = logType
  109. productLog.LogCreateTime = time.Now()
  110. productLog.AdminId = adminId
  111. err = company.AddCompanyProductLog(productLog)
  112. //修改公司更新时间
  113. sql := `UPDATE company SET last_updated_time=NOW() WHERE company_id=? `
  114. o := orm.NewOrm()
  115. o.Raw(sql, companyProduct.CompanyId).Exec()
  116. return
  117. }
  118. func AddCompanyOperationRecord(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveUserRealName, approveRemark, status string) (err error) {
  119. defer func() {
  120. if err != nil {
  121. go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecord;Err:"+err.Error(), 3)
  122. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
  123. }
  124. }()
  125. record := new(company.CompanyOperationRecord)
  126. record.CompanyId = companyId
  127. record.CompanyName = companyName
  128. record.SellerId = sellerId
  129. record.SysUserId = sysUserId
  130. record.SysRealName = sysUserRealName
  131. record.Remark = remark
  132. record.Operation = operation
  133. record.CreateTime = time.Now()
  134. record.ProductId = productId
  135. record.ProductName = productName
  136. record.ApproveUserId = approveAdminId
  137. record.ApproveRealName = approveUserRealName
  138. record.ApproveContent = approveContent
  139. record.ApproveRemark = approveRemark
  140. record.Status = status
  141. _, err = company.AddCompanyOperationRecord(record)
  142. return
  143. }
  144. // AddCompanyOperationRecordMore 添加操作记录(包含补充信息)
  145. func AddCompanyOperationRecordMore(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveContentExtra, approveUserRealName, approveRemark, status string) (err error) {
  146. defer func() {
  147. if err != nil {
  148. go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecordMore;Err:"+err.Error(), 3)
  149. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
  150. }
  151. }()
  152. record := new(company.CompanyOperationRecord)
  153. record.CompanyId = companyId
  154. record.CompanyName = companyName
  155. record.SellerId = sellerId
  156. record.SysUserId = sysUserId
  157. record.SysRealName = sysUserRealName
  158. record.Remark = remark
  159. record.Operation = operation
  160. record.CreateTime = time.Now()
  161. record.ProductId = productId
  162. record.ProductName = productName
  163. record.ApproveUserId = approveAdminId
  164. record.ApproveRealName = approveUserRealName
  165. record.ApproveContent = approveContent
  166. record.ApproveContentExtra = approveContentExtra
  167. record.ApproveRemark = approveRemark
  168. record.Status = status
  169. _, err = company.AddCompanyOperationRecord(record)
  170. return
  171. }
  172. func GetProductId(roleTypeCode string) (productId int) {
  173. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  174. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  175. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  176. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  177. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
  178. productId = 1
  179. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  180. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  181. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  182. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  183. productId = 2
  184. } else {
  185. productId = 0
  186. }
  187. return
  188. }
  189. // CheckAdminIsSeller 根据用户权限码获取是否属于销售
  190. func CheckAdminIsSeller(roleTypeCode string) (isSeller bool) {
  191. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  192. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  193. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  194. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  195. isSeller = true
  196. }
  197. return
  198. }
  199. //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  200. // button.BtnView = true
  201. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  202. // if !strings.Contains(status, "/") {
  203. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  204. // //button.BtnModifySeller = true
  205. // return
  206. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  207. // button.BtnEdit = true
  208. // button.BtnDelete = true
  209. // //button.BtnModifySeller = true
  210. // return
  211. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  212. // //button.BtnModifySeller = true
  213. // return
  214. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  215. // //button.BtnModifySeller = true
  216. // button.BtnDelete = true
  217. // return
  218. // } else { //永续
  219. // //button.BtnModifySeller = true
  220. // button.BtnDelete = true
  221. // button.BtnEdit = true
  222. // return
  223. // }
  224. // }
  225. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  226. // if productId != 1 {
  227. // return
  228. // } else {
  229. // if !strings.Contains(status, "/") {
  230. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  231. // button.BtnModifySeller = true
  232. // return
  233. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  234. // button.BtnEdit = true
  235. // button.BtnDelete = true
  236. // button.BtnModifySeller = true
  237. // return
  238. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  239. // //button.BtnModifySeller = true
  240. // return
  241. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  242. // //button.BtnModifySeller = true
  243. // button.BtnDelete = true
  244. // return
  245. // } else { //永续
  246. // return
  247. // }
  248. // }
  249. // }
  250. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  251. // if !strings.Contains(status, "/") {
  252. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  253. // button.BtnModifySeller = true
  254. // return
  255. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  256. // button.BtnEdit = true
  257. // button.BtnDelete = true
  258. // return
  259. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  260. // return
  261. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  262. // button.BtnDelete = true
  263. // return
  264. // } else { //永续
  265. // return
  266. // }
  267. // }
  268. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  269. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  270. // return
  271. // }
  272. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  273. // return
  274. // }
  275. // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
  276. // if authority == 2 { //组长
  277. // if !strings.Contains(status, "/") {
  278. // if sysUserId == itemSellerId { //自己客户
  279. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  280. // button.BtnUpdate = true
  281. // button.BtnModifySeller = true
  282. // return
  283. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  284. // button.BtnEdit = true
  285. // button.BtnDelete = true
  286. // button.BtnSuspend = true
  287. // button.BtnDelay = true
  288. // button.BtnTurnPositive = true
  289. // button.BtnModifySeller = true
  290. // return
  291. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  292. // button.BtnThaw = true
  293. // return
  294. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  295. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  296. // button.BtnApplyReceive = true
  297. // } else {
  298. // button.BtnReceive = true
  299. // }
  300. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  301. // button.BtnDelete = true
  302. // }
  303. // return
  304. // } else { //永续
  305. // button.BtnDelete = true
  306. // return
  307. // }
  308. // } else {
  309. // if productId == 1 {
  310. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  311. // button.BtnModifySeller=true
  312. // return
  313. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  314. // button.BtnModifySeller=true
  315. // return
  316. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  317. // button.BtnThaw = true
  318. // return
  319. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  320. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  321. // button.BtnApplyReceive = true
  322. // } else {
  323. // button.BtnReceive = true
  324. // }
  325. // return
  326. // } else { //永续
  327. // button.BtnDelete = true
  328. // return
  329. // }
  330. // } else {
  331. // button.BtnReceive = true
  332. // }
  333. // }
  334. // }
  335. // } else { //销售
  336. // if !strings.Contains(status, "/") {
  337. // if itemSellerId == sysUserId {
  338. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  339. // button.BtnUpdate = true
  340. // return
  341. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  342. // button.BtnEdit = true
  343. // button.BtnDelete = true
  344. // button.BtnSuspend = true
  345. // button.BtnDelay = true
  346. // button.BtnTurnPositive = true
  347. // return
  348. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  349. // button.BtnThaw = true
  350. // return
  351. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  352. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  353. // button.BtnApplyReceive = true
  354. // } else {
  355. // button.BtnReceive = true
  356. // }
  357. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  358. // button.BtnDelete = true
  359. // }
  360. // return
  361. // } else { //永续
  362. // button.BtnDelete = true
  363. // return
  364. // }
  365. // } else {
  366. // if productId == 1 {
  367. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  368. // return
  369. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  370. // return
  371. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  372. // button.BtnThaw = true
  373. // return
  374. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  375. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  376. // button.BtnApplyReceive = true
  377. // } else {
  378. // button.BtnReceive = true
  379. // }
  380. // return
  381. // } else { //永续
  382. // button.BtnDelete = true
  383. // return
  384. // }
  385. // } else {
  386. // button.BtnReceive = true
  387. // }
  388. // }
  389. // }
  390. // }
  391. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  392. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  393. // return
  394. // }
  395. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  396. // return
  397. // }
  398. // if !strings.Contains(status, "/") {
  399. // if authority == 2 { //组长
  400. // if itemSellerId==sysUserId {
  401. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  402. // button.BtnUpdate = true
  403. // button.BtnModifySeller = true
  404. // return
  405. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  406. // button.BtnEdit = true
  407. // button.BtnDelete = true
  408. // button.BtnSuspend = true
  409. // button.BtnDelay = true
  410. // button.BtnTurnPositive = true
  411. // button.BtnModifySeller = true
  412. // return
  413. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  414. // button.BtnThaw = true
  415. // return
  416. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  417. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  418. // button.BtnApplyReceive = true
  419. // } else {
  420. // button.BtnReceive = true
  421. // }
  422. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  423. // button.BtnDelete = true
  424. // }
  425. // return
  426. // } else { //永续
  427. // button.BtnDelete = true
  428. // return
  429. // }
  430. // }else{
  431. // if productId==1 {
  432. // button.BtnReceive=true
  433. // }else{
  434. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  435. // button.BtnModifySeller=true
  436. // return
  437. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  438. // button.BtnModifySeller=true
  439. // return
  440. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  441. // button.BtnThaw = true
  442. // return
  443. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  444. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  445. // button.BtnApplyReceive = true
  446. // } else {
  447. // button.BtnReceive = true
  448. // }
  449. // return
  450. // } else { //永续
  451. // button.BtnDelete = true
  452. // return
  453. // }
  454. // }
  455. // }
  456. // } else {
  457. // if itemSellerId==sysUserId {
  458. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  459. // button.BtnUpdate = true
  460. // return
  461. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  462. // button.BtnEdit = true
  463. // button.BtnDelete = true
  464. // button.BtnSuspend = true
  465. // button.BtnDelay = true
  466. // button.BtnTurnPositive = true
  467. // return
  468. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  469. // button.BtnThaw = true
  470. // return
  471. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  472. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  473. // button.BtnApplyReceive = true
  474. // } else {
  475. // button.BtnReceive = true
  476. // }
  477. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  478. // button.BtnDelete = true
  479. // }
  480. // return
  481. // } else { //永续
  482. // button.BtnDelete = true
  483. // return
  484. // }
  485. // }else{
  486. // if productId==1 {
  487. // button.BtnReceive=true
  488. // }else{
  489. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  490. // return
  491. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  492. // return
  493. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  494. // button.BtnThaw = true
  495. // return
  496. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  497. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  498. // button.BtnApplyReceive = true
  499. // } else {
  500. // button.BtnReceive = true
  501. // }
  502. // return
  503. // } else { //永续
  504. // button.BtnDelete = true
  505. // return
  506. // }
  507. // }
  508. // }
  509. // }
  510. // }
  511. // }
  512. // return button
  513. //}
  514. //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  515. // button.BtnView = true
  516. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  517. // if !strings.Contains(status, "/") {
  518. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  519. // button.BtnView = true
  520. // button.BtnModifySeller = true
  521. // return
  522. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  523. // button.BtnEdit = true
  524. // button.BtnDelete = true
  525. // button.BtnFreeze=true
  526. // return
  527. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  528. // button.BtnModifySeller = true
  529. // button.BtnView = true
  530. // return
  531. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  532. // button.BtnDelete = true
  533. // button.BtnModifySeller = true
  534. // return
  535. // } else { //永续
  536. // button.BtnDelete = true
  537. // button.BtnEdit = true
  538. // return
  539. // }
  540. // }
  541. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  542. // fmt.Println("itemSellerId:",itemSellerId)
  543. // fmt.Println("sysUserId:",sysUserId)
  544. // if !strings.Contains(status, "/") {
  545. // if itemSellerId == sysUserId {
  546. // if productId == 1 {
  547. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  548. // button.BtnModifySeller = true
  549. // button.BtnUpdate = true
  550. // return
  551. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  552. // button.BtnEdit = true
  553. // button.BtnDelete = true
  554. // button.BtnModifySeller = true
  555. // button.BtnSuspend = true
  556. // button.BtnDelay = true
  557. // button.BtnTurnPositive = true
  558. // button.BtnFreeze=true
  559. // return
  560. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  561. // button.BtnModifySeller = true
  562. // button.BtnView = true
  563. // return
  564. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  565. // button.BtnModifySeller = true
  566. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  567. // button.BtnDelete = true
  568. // }
  569. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  570. // button.BtnApplyReceive = true
  571. // } else {
  572. // button.BtnReceive = true
  573. // }
  574. // return
  575. // } else { //永续
  576. // button.BtnDelete = true
  577. // return
  578. // }
  579. // } else {
  580. // //button.BtnReceiveOther=true
  581. // return
  582. // }
  583. // } else {
  584. // if productId == 1 {
  585. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  586. // button.BtnModifySeller = true
  587. // return
  588. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  589. // button.BtnEdit = true
  590. // button.BtnDelete = true
  591. // return
  592. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  593. // button.BtnModifySeller = true
  594. // button.BtnView = true
  595. // return
  596. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  597. // button.BtnModifySeller = true
  598. // button.BtnDelete = true
  599. // button.BtnView = true
  600. // return
  601. // } else { //永续
  602. // return
  603. // }
  604. // } else {
  605. // button.BtnReceiveOther = true
  606. // return
  607. // }
  608. // }
  609. // }
  610. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  611. // if !strings.Contains(status, "/") {
  612. // if itemSellerId == sysUserId {
  613. // if productId == 2 {
  614. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  615. // button.BtnModifySeller = true
  616. // button.BtnUpdate = true
  617. // return
  618. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  619. // button.BtnEdit = true
  620. // button.BtnDelete = true
  621. // button.BtnModifySeller = true
  622. // button.BtnSuspend = true
  623. // button.BtnDelay = true
  624. // button.BtnTurnPositive = true
  625. // button.BtnFreeze=true
  626. // return
  627. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  628. // button.BtnModifySeller = true
  629. // return
  630. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  631. // button.BtnModifySeller = true
  632. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  633. // button.BtnDelete = true
  634. // }
  635. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  636. // button.BtnApplyReceive = true
  637. // } else {
  638. // button.BtnReceive = true
  639. // }
  640. // return
  641. // } else { //永续
  642. // button.BtnDelete = true
  643. // return
  644. // }
  645. // } else {
  646. // return
  647. // }
  648. // } else {
  649. // if productId == 2 {
  650. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  651. // button.BtnModifySeller = true
  652. // button.BtnView = true
  653. // return
  654. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  655. // button.BtnEdit = true
  656. // button.BtnDelete = true
  657. // return
  658. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  659. // button.BtnView = true
  660. // button.BtnModifySeller = true
  661. // return
  662. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  663. // button.BtnModifySeller = true
  664. // button.BtnDelete = true
  665. // button.BtnView = true
  666. // return
  667. // } else { //永续
  668. // return
  669. // }
  670. // } else {
  671. // //button.BtnReceive = true
  672. // return
  673. // }
  674. // }
  675. // }
  676. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  677. // if !strings.Contains(status, "/") {
  678. // if itemSellerId == sysUserId {
  679. // if productId == 1 {
  680. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  681. // button.BtnUpdate = true
  682. // return
  683. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  684. // button.BtnDelete = true
  685. // button.BtnEdit = true
  686. // button.BtnSuspend = true
  687. // button.BtnDelay = true
  688. // button.BtnTurnPositive = true
  689. // button.BtnFreeze=true
  690. // return
  691. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  692. // button.BtnThaw = true
  693. // return
  694. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  695. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  696. // button.BtnApplyReceive = true
  697. // } else {
  698. // button.BtnReceive = true
  699. // }
  700. // if itemSellerId == sysUserId || (sysUserGroupId == itemGroupId && authority == 2) {
  701. // button.BtnDelete = true
  702. // }
  703. // return
  704. // } else { //永续
  705. // button.BtnDelete = true
  706. // return
  707. // }
  708. // } else {
  709. // button.BtnReceiveOther = true
  710. // return
  711. // }
  712. // } else {
  713. // if productId == 1 {
  714. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  715. // return
  716. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  717. // return
  718. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  719. // button.BtnApplyReceive = true
  720. // button.BtnView = false
  721. // return
  722. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  723. // if itemGroupId == sysUserGroupId {
  724. // button.BtnApplyReceive = true
  725. // } else {
  726. // button.BtnReceive = true
  727. // }
  728. // button.BtnView = false
  729. // return
  730. // } else { //永续
  731. // button.BtnDelete = true
  732. // return
  733. // }
  734. // } else {
  735. // button.BtnReceiveOther = true
  736. // button.BtnView = false
  737. // return
  738. // }
  739. // }
  740. // }
  741. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  742. // if !strings.Contains(status, "/") {
  743. // if itemSellerId == sysUserId {
  744. // if productId == 2 {
  745. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  746. // button.BtnUpdate = true
  747. // return
  748. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  749. // button.BtnDelete = true
  750. // button.BtnEdit = true
  751. // button.BtnSuspend = true
  752. // button.BtnDelay = true
  753. // button.BtnTurnPositive = true
  754. // button.BtnFreeze=true
  755. // return
  756. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  757. // button.BtnThaw = true
  758. // return
  759. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  760. // if itemGroupId == sysUserGroupId {
  761. // button.BtnApplyReceive = true
  762. // } else {
  763. // button.BtnReceive = true
  764. // }
  765. // if sysUserGroupId == itemGroupId && authority == 2 {
  766. // button.BtnDelete = true
  767. // }
  768. // return
  769. // } else { //永续
  770. // button.BtnDelete = true
  771. // return
  772. // }
  773. // } else {
  774. // button.BtnReceiveOther = true
  775. // return
  776. // }
  777. // } else {
  778. // if productId == 2 {
  779. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  780. // return
  781. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  782. // return
  783. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  784. // button.BtnApplyReceive = true
  785. // button.BtnView = false
  786. // return
  787. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  788. // if itemGroupId == sysUserGroupId {
  789. // button.BtnApplyReceive = true
  790. // } else {
  791. // button.BtnReceive = true
  792. // }
  793. // button.BtnView = false
  794. // return
  795. // } else { //永续
  796. // button.BtnDelete = true
  797. // return
  798. // }
  799. // } else {
  800. // button.BtnReceiveOther = true
  801. // button.BtnView = false
  802. // return
  803. // }
  804. // }
  805. // }
  806. // }
  807. // return button
  808. //}
  809. //
  810. func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupIdS string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId, shareSellerId int) (button company.ButtonPermission) {
  811. //产品状态map
  812. productStatusMap := make(map[int]string)
  813. if productId == 1 {
  814. productStatusMap[1] = status
  815. } else if productId == 2 {
  816. productStatusMap[2] = status
  817. }
  818. if strings.Contains(status, "/") {
  819. statusSlice := strings.Split(status, "/")
  820. productStatusMap[1] = statusSlice[0]
  821. productStatusMap[2] = statusSlice[1]
  822. }
  823. //所属销售map
  824. sellerIdMap := make(map[int]int)
  825. if productId == 1 {
  826. sellerIdMap[1] = itemSellerId
  827. } else if productId == 2 {
  828. sellerIdMap[2] = itemSellerId
  829. }
  830. if strings.Contains(itemSellerIds, "/") {
  831. sellerIdSlice := strings.Split(itemSellerIds, "/")
  832. sellerIdMap[1], _ = strconv.Atoi(sellerIdSlice[0])
  833. sellerIdMap[2], _ = strconv.Atoi(sellerIdSlice[1])
  834. }
  835. //分组map
  836. groupIdMap := make(map[int]int)
  837. if productId == 1 {
  838. groupIdMap[1] = itemGroupId
  839. } else if productId == 2 {
  840. groupIdMap[2] = itemGroupId
  841. }
  842. if strings.Contains(itemGroupIdS, "/") {
  843. groupIdSlice := strings.Split(itemGroupIdS, "/")
  844. groupIdMap[1], _ = strconv.Atoi(groupIdSlice[0])
  845. groupIdMap[2], _ = strconv.Atoi(groupIdSlice[1])
  846. }
  847. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  848. button.BtnView = true //查看详情权限
  849. if !strings.Contains(status, "/") {
  850. if status == utils.COMPANY_STATUS_FORMAL { //正式
  851. //button.BtnModifySeller = true
  852. button.BtnRemarkView = true
  853. return
  854. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  855. button.BtnEdit = true
  856. button.BtnDelete = true
  857. button.BtnRemarkView = true
  858. //button.BtnModifySeller = true
  859. button.BtnFreeze = false
  860. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  861. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  862. }
  863. return
  864. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  865. //button.BtnModifySeller = true
  866. button.BtnRemarkView = true
  867. return
  868. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  869. //button.BtnModifySeller = true
  870. button.BtnDelete = true
  871. return
  872. } else if status == utils.COMPANY_STATUS_CLOSE { // 关闭
  873. //button.BtnModifySeller = true
  874. button.BtnDelete = true
  875. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  876. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  877. }
  878. return
  879. } else { //永续
  880. //button.BtnModifySeller = true
  881. button.BtnDelete = true
  882. button.BtnEdit = true
  883. return
  884. }
  885. }
  886. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  887. //查看详情权限
  888. productStatus, hasProduct := productStatusMap[1]
  889. if hasProduct {
  890. button.BtnView = true
  891. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  892. button.BtnModifySeller = true
  893. button.BtnShare = true
  894. return
  895. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  896. button.BtnEdit = true
  897. //button.BtnDelete = true
  898. button.BtnModifySeller = true
  899. button.BtnFreeze = false
  900. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  901. return
  902. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  903. button.BtnModifySeller = true
  904. return
  905. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  906. //button.BtnModifySeller = true
  907. //button.BtnDelete = true
  908. return
  909. } else if productStatus == utils.COMPANY_STATUS_CLOSE { // 关闭
  910. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  911. return
  912. } else { //永续
  913. return
  914. }
  915. } else {
  916. productStatus2, hasProduct2 := productStatusMap[2]
  917. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  918. if hasProduct2 {
  919. //其他产品的流失客户可以有查看权限
  920. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  921. button.BtnView = true //查看权限
  922. }
  923. }
  924. }
  925. return
  926. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  927. //查看详情权限
  928. productStatus, hasProduct := productStatusMap[2]
  929. if hasProduct {
  930. button.BtnView = true
  931. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  932. button.BtnModifySeller = true
  933. button.BtnShare = true
  934. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  935. button.BtnEdit = true
  936. //button.BtnDelete = true
  937. button.BtnModifySeller = true
  938. button.BtnFreeze = false
  939. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  940. button.BtnModifySeller = true
  941. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  942. //button.BtnDelete = true
  943. } else { //永续
  944. }
  945. } else {
  946. productStatus2, hasProduct2 := productStatusMap[1]
  947. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  948. if hasProduct2 {
  949. //其他产品的流失客户可以有查看权限
  950. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  951. button.BtnView = true //查看权限
  952. }
  953. }
  954. }
  955. return
  956. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  957. //判断该客户是否有ficc权限
  958. productStatus, hasProduct := productStatusMap[1]
  959. if hasProduct {
  960. //如果有权限的话:
  961. //获取当前ficc的销售id
  962. sellerId, hasSellerId := sellerIdMap[1]
  963. //获取当前ficc的销售分组id
  964. groupId, hasGroupId := groupIdMap[1]
  965. //如果是自己客户,那么拥有查看权限
  966. if hasSellerId {
  967. if sellerId == sysUserId || shareSellerId == sysUserId {
  968. button.BtnView = true //显示权限、详情
  969. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  970. button.BtnUpdate = true //服务更新
  971. button.BtnAddAgreement = true //补充协议
  972. button.BtnTryOut = true
  973. button.BtnModifySeller = true
  974. button.BtnShare = true
  975. button.BtnRemarkEdit = true
  976. button.BtnRemarkView = true
  977. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  978. button.BtnEdit = true
  979. button.BtnDelete = true
  980. button.BtnSuspend = true
  981. button.BtnDelay = true
  982. button.BtnTurnPositive = true
  983. button.BtnFreeze = true
  984. button.BtnModifySeller = true
  985. button.BtnRemarkEdit = true
  986. button.BtnRemarkView = true
  987. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  988. button.BtnThaw = true
  989. button.BtnModifySeller = true
  990. button.BtnRemarkEdit = true
  991. button.BtnRemarkView = true
  992. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  993. button.BtnApplyReceive = true
  994. } else { //永续
  995. //button.BtnDelete = true
  996. }
  997. } else {
  998. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  999. button.BtnView = true //显示权限、详情
  1000. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1001. if groupId == sysUserGroupId {
  1002. button.BtnApplyReceive = true
  1003. } else {
  1004. button.BtnReceive = true
  1005. }
  1006. }
  1007. }
  1008. }
  1009. //如果是组长,且该客户属于本组客户
  1010. if authority == 4 && hasGroupId && groupId == sysUserGroupId && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  1011. button.BtnView = true //查看详情权限
  1012. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1013. button.BtnModifySeller = true
  1014. button.BtnShare = true
  1015. button.BtnRemarkView = true
  1016. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1017. button.BtnModifySeller = true
  1018. button.BtnRemarkView = true
  1019. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1020. button.BtnModifySeller = true
  1021. button.BtnRemarkView = true
  1022. //button.BtnThaw = false
  1023. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1024. if sellerId == sysUserId || groupId == sysUserGroupId || shareSellerId == sysUserId {
  1025. button.BtnApplyReceive = true
  1026. } else {
  1027. button.BtnReceive = true
  1028. }
  1029. } else { //永续
  1030. //button.BtnDelete = true
  1031. }
  1032. }
  1033. //如果是ficc销售主管,且该客户属于本组客户
  1034. //获取父级groupId
  1035. groupIdpid, err := company.GetParentIdFromGroup(groupId)
  1036. if err != nil {
  1037. fmt.Println(err.Error())
  1038. }
  1039. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUserGroupId)
  1040. if err != nil {
  1041. fmt.Println(err.Error())
  1042. }
  1043. var pidBool bool
  1044. //处理主管和销售在不同的二三级分组下的情况
  1045. if groupIdpid != nil && sysUserGroupIdpid != nil {
  1046. pidBool = *groupIdpid == *sysUserGroupIdpid || *groupIdpid == sysUserGroupId || groupId == sysUserGroupId || groupId == *sysUserGroupIdpid
  1047. }
  1048. if authority == 2 && hasGroupId && pidBool && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  1049. button.BtnView = true //查看详情权限
  1050. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1051. button.BtnModifySeller = true
  1052. button.BtnShare = true
  1053. button.BtnRemarkView = true
  1054. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1055. button.BtnModifySeller = true
  1056. button.BtnRemarkView = true
  1057. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1058. button.BtnModifySeller = true
  1059. button.BtnRemarkView = true
  1060. //button.BtnThaw = false
  1061. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1062. if sellerId == sysUserId || groupId == sysUserGroupId || shareSellerId == sysUserId {
  1063. button.BtnApplyReceive = true
  1064. } else {
  1065. button.BtnReceive = true
  1066. }
  1067. } else { //永续
  1068. //button.BtnDelete = true
  1069. }
  1070. }
  1071. //ficc同一个大组当作一个小组来处理领取按钮
  1072. var ids []*string
  1073. if groupIdpid != nil && *groupIdpid != 0 {
  1074. ids, err = company.GetGroupIdsByParentId(*groupIdpid)
  1075. if err != nil {
  1076. fmt.Println(err.Error())
  1077. }
  1078. }
  1079. var idSlice []string
  1080. var sid string
  1081. for _, id := range ids {
  1082. idSlice = append(idSlice, *id)
  1083. }
  1084. sid = strings.Join(idSlice, ",")
  1085. if strings.Contains(sid, strconv.Itoa(itemGroupId)) {
  1086. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1087. button.BtnApplyReceive = true
  1088. button.BtnReceive = false
  1089. }
  1090. }
  1091. } else {
  1092. productStatus2, hasProduct2 := productStatusMap[2]
  1093. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1094. if hasProduct2 {
  1095. //如果客户ficc权限是永续,那么也没有其他部门客户的按钮权限
  1096. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1097. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1098. }
  1099. //其他产品的流失客户可以有查看权限
  1100. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1101. button.BtnView = true //查看权限
  1102. }
  1103. }
  1104. }
  1105. return
  1106. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1107. //判断该客户是否有权益权限
  1108. productStatus, hasProduct := productStatusMap[2]
  1109. if hasProduct {
  1110. //如果有权限的话:
  1111. //获取当前 权益 的销售id
  1112. sellerId, hasSellerId := sellerIdMap[2]
  1113. //获取当前 权益 的销售分组id
  1114. groupId, hasGroupId := groupIdMap[2]
  1115. //如果是自己客户,那么拥有查看权限
  1116. if hasSellerId {
  1117. if sellerId == sysUserId {
  1118. button.BtnView = true //显示权限、详情
  1119. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1120. button.BtnUpdate = true
  1121. button.BtnTryOut = true
  1122. button.BtnModifySeller = true
  1123. button.BtnShare = true
  1124. button.BtnRemarkEdit = true
  1125. button.BtnRemarkView = true
  1126. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1127. button.BtnEdit = true
  1128. button.BtnDelete = true
  1129. button.BtnSuspend = true
  1130. button.BtnDelay = true
  1131. button.BtnTurnPositive = true
  1132. button.BtnModifySeller = true
  1133. button.BtnFreeze = true
  1134. button.BtnRemarkEdit = true
  1135. button.BtnRemarkView = true
  1136. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1137. button.BtnThaw = true
  1138. button.BtnModifySeller = true
  1139. button.BtnRemarkEdit = true
  1140. button.BtnRemarkView = true
  1141. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1142. button.BtnApplyReceive = true
  1143. } else { //永续
  1144. //button.BtnDelete = true
  1145. }
  1146. } else {
  1147. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1148. button.BtnView = true //显示权限、详情
  1149. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1150. if groupId == sysUserGroupId {
  1151. button.BtnApplyReceive = true
  1152. } else {
  1153. button.BtnReceive = true
  1154. }
  1155. }
  1156. }
  1157. }
  1158. //如果是组长,且该客户属于本组客户
  1159. if authority == 2 && hasGroupId && groupId == sysUserGroupId {
  1160. button.BtnView = true //查看详情权限
  1161. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1162. button.BtnModifySeller = true
  1163. button.BtnShare = true
  1164. button.BtnRemarkView = true
  1165. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1166. button.BtnModifySeller = true
  1167. button.BtnRemarkView = true
  1168. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1169. button.BtnModifySeller = true
  1170. button.BtnRemarkView = true
  1171. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1172. if sellerId == sysUserId || groupId == sysUserGroupId {
  1173. button.BtnApplyReceive = true
  1174. } else {
  1175. button.BtnReceive = true
  1176. }
  1177. } else { //永续
  1178. //button.BtnDelete = true
  1179. }
  1180. }
  1181. } else {
  1182. productStatus2, hasProduct2 := productStatusMap[1]
  1183. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1184. if hasProduct2 {
  1185. //如果客户 权益 权限是永续,那么也没有其他部门客户的按钮权限
  1186. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1187. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1188. }
  1189. //其他产品的流失客户可以有查看权限
  1190. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1191. button.BtnView = true //查看权限
  1192. }
  1193. }
  1194. }
  1195. return
  1196. }
  1197. return button
  1198. }
  1199. // GetCompanyPermissionButtonByReceiveEnabled 查询当前销售 "添加客户" 权限来判断按钮权限
  1200. func GetCompanyPermissionButtonByReceiveEnabled(btnItem *company.ButtonPermission, receiveEnabled bool) (buttonNew *company.ButtonPermission) {
  1201. //查询当前销售 "添加客户" 权限是否为禁用
  1202. if !receiveEnabled {
  1203. //申请领取、领取客户、领取其他部门客户按钮权限按钮显示时
  1204. if btnItem.BtnApplyReceive || btnItem.BtnReceive || btnItem.BtnReceiveOther {
  1205. btnItem.BtnApplyReceive = false
  1206. btnItem.BtnReceive = false
  1207. btnItem.BtnReceiveOther = false
  1208. }
  1209. if btnItem.BtnThaw {
  1210. btnItem.BtnThaw = false
  1211. }
  1212. }
  1213. buttonNew = btnItem
  1214. return buttonNew
  1215. }
  1216. //func GetCompanyPermissionButtonOld(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  1217. // button.BtnView = true
  1218. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  1219. // if !strings.Contains(status, "/") {
  1220. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1221. // //button.BtnModifySeller = true
  1222. // return
  1223. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1224. // button.BtnEdit = true
  1225. // button.BtnDelete = true
  1226. // //button.BtnModifySeller = true
  1227. // button.BtnFreeze = false
  1228. // return
  1229. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1230. // //button.BtnModifySeller = true
  1231. // return
  1232. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1233. // //button.BtnModifySeller = true
  1234. // button.BtnDelete = true
  1235. // return
  1236. // } else { //永续
  1237. // //button.BtnModifySeller = true
  1238. // button.BtnDelete = true
  1239. // button.BtnEdit = true
  1240. // return
  1241. // }
  1242. // }
  1243. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1244. // if productId != 1 {
  1245. // return
  1246. // } else {
  1247. // if !strings.Contains(status, "/") {
  1248. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1249. // button.BtnModifySeller = true
  1250. // return
  1251. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1252. // //button.BtnEdit = true
  1253. // //button.BtnDelete = true
  1254. // button.BtnModifySeller = true
  1255. // button.BtnFreeze = false
  1256. // return
  1257. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1258. // //button.BtnModifySeller = true
  1259. // return
  1260. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1261. // //button.BtnModifySeller = true
  1262. // //button.BtnDelete = true
  1263. // return
  1264. // } else { //永续
  1265. // return
  1266. // }
  1267. // }
  1268. // }
  1269. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1270. // if !strings.Contains(status, "/") {
  1271. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1272. // button.BtnModifySeller = true
  1273. // return
  1274. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1275. // //button.BtnEdit = true
  1276. // //button.BtnDelete = true
  1277. // button.BtnModifySeller = true
  1278. // button.BtnFreeze = false
  1279. // return
  1280. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1281. // return
  1282. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1283. // //button.BtnDelete = true
  1284. // return
  1285. // } else { //永续
  1286. // return
  1287. // }
  1288. // }
  1289. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  1290. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1291. // if !strings.Contains(status, "/") {
  1292. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1293. // } else {
  1294. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1295. // statusSlice := strings.Split(status, "/")
  1296. // ficcStatus := statusSlice[0]
  1297. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1298. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1299. // button.BtnApplyReceive = true //申请领取按钮权限
  1300. // } else {
  1301. // button.BtnReceive = true //领取客户按钮权限
  1302. // }
  1303. // return
  1304. // }
  1305. // }
  1306. // return
  1307. // }
  1308. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1309. // return
  1310. // }
  1311. // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
  1312. // if authority == 2 { //组长
  1313. // if !strings.Contains(status, "/") {
  1314. // if sysUserId == itemSellerId { //自己客户
  1315. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1316. // button.BtnUpdate = true
  1317. // button.BtnModifySeller = true
  1318. // button.BtnTryOut = true
  1319. // return
  1320. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1321. // button.BtnEdit = true
  1322. // button.BtnDelete = true
  1323. // button.BtnSuspend = true
  1324. // button.BtnDelay = true
  1325. // button.BtnTurnPositive = true
  1326. // button.BtnModifySeller = true
  1327. // button.BtnFreeze = true
  1328. // return
  1329. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1330. // button.BtnThaw = true
  1331. // return
  1332. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1333. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1334. // button.BtnApplyReceive = true
  1335. // } else {
  1336. // button.BtnReceive = true
  1337. // }
  1338. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1339. // //button.BtnDelete = true
  1340. // }
  1341. // return
  1342. // } else { //永续
  1343. // button.BtnDelete = true
  1344. // return
  1345. // }
  1346. // } else {
  1347. // if productId == 1 {
  1348. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1349. // button.BtnModifySeller = true
  1350. // return
  1351. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1352. // button.BtnModifySeller = true
  1353. // return
  1354. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1355. // button.BtnThaw = false
  1356. // return
  1357. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1358. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1359. // button.BtnApplyReceive = true
  1360. // } else {
  1361. // button.BtnReceive = true
  1362. // }
  1363. // return
  1364. // } else { //永续
  1365. // button.BtnDelete = true
  1366. // return
  1367. // }
  1368. // } else {
  1369. // //button.BtnReceive = true
  1370. // }
  1371. // }
  1372. // }
  1373. // } else { //销售
  1374. // if !strings.Contains(status, "/") {
  1375. // if itemSellerId == sysUserId {
  1376. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1377. // button.BtnUpdate = true
  1378. // button.BtnTryOut = true
  1379. // return
  1380. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1381. // button.BtnEdit = true
  1382. // button.BtnDelete = true
  1383. // button.BtnSuspend = true
  1384. // button.BtnDelay = true
  1385. // button.BtnTurnPositive = true
  1386. // button.BtnFreeze = true
  1387. // return
  1388. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1389. // button.BtnThaw = true
  1390. // return
  1391. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1392. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1393. // button.BtnApplyReceive = true
  1394. // } else {
  1395. // button.BtnReceive = true
  1396. // }
  1397. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1398. // //button.BtnDelete = true
  1399. // }
  1400. // return
  1401. // } else { //永续
  1402. // button.BtnDelete = true
  1403. // return
  1404. // }
  1405. // } else {
  1406. // if productId == 1 {
  1407. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1408. // return
  1409. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1410. // return
  1411. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1412. // button.BtnThaw = false
  1413. // return
  1414. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1415. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1416. // button.BtnApplyReceive = true
  1417. // } else {
  1418. // button.BtnReceive = true
  1419. // }
  1420. // return
  1421. // } else { //永续
  1422. // button.BtnDelete = true
  1423. // return
  1424. // }
  1425. // } else {
  1426. // //button.BtnReceive = true
  1427. // }
  1428. // }
  1429. // } else {
  1430. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1431. // statusSlice := strings.Split(status, "/")
  1432. // ficcStatus := statusSlice[0]
  1433. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1434. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1435. // button.BtnApplyReceive = true //申请领取按钮权限
  1436. // } else {
  1437. // button.BtnReceive = true //领取客户按钮权限
  1438. // }
  1439. // return
  1440. // }
  1441. // }
  1442. // }
  1443. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  1444. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1445. // return
  1446. // }
  1447. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1448. // if !strings.Contains(status, "/") {
  1449. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1450. // } else {
  1451. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1452. // statusSlice := strings.Split(status, "/")
  1453. // raiStatus := statusSlice[1]
  1454. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1455. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1456. // button.BtnApplyReceive = true //申请领取按钮权限
  1457. // } else {
  1458. // button.BtnReceive = true //领取客户按钮权限
  1459. // }
  1460. // return
  1461. // }
  1462. // }
  1463. // return
  1464. // }
  1465. // if !strings.Contains(status, "/") {
  1466. // if authority == 2 { //组长
  1467. // if itemSellerId == sysUserId {
  1468. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1469. // button.BtnUpdate = true
  1470. // button.BtnModifySeller = true
  1471. // button.BtnTryOut = true
  1472. // return
  1473. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1474. // button.BtnEdit = true
  1475. // button.BtnDelete = true
  1476. // button.BtnSuspend = true
  1477. // button.BtnDelay = true
  1478. // button.BtnTurnPositive = true
  1479. // button.BtnModifySeller = true
  1480. // button.BtnFreeze = true
  1481. // return
  1482. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1483. // button.BtnThaw = true
  1484. // return
  1485. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1486. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1487. // button.BtnApplyReceive = true
  1488. // } else {
  1489. // button.BtnReceive = true
  1490. // }
  1491. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1492. // //button.BtnDelete = true
  1493. // }
  1494. // return
  1495. // } else { //永续
  1496. // button.BtnDelete = true
  1497. // return
  1498. // }
  1499. // } else {
  1500. // if productId == 1 {
  1501. // //button.BtnReceive = true
  1502. // } else {
  1503. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1504. // button.BtnModifySeller = true
  1505. // return
  1506. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1507. // button.BtnModifySeller = true
  1508. // return
  1509. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1510. // button.BtnThaw = false
  1511. // return
  1512. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1513. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1514. // button.BtnApplyReceive = true
  1515. // } else {
  1516. // button.BtnReceive = true
  1517. // }
  1518. // return
  1519. // } else { //永续
  1520. // button.BtnDelete = true
  1521. // return
  1522. // }
  1523. // }
  1524. // }
  1525. // } else {
  1526. // if itemSellerId == sysUserId {
  1527. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1528. // button.BtnUpdate = true
  1529. // button.BtnTryOut = true
  1530. // return
  1531. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1532. // button.BtnEdit = true
  1533. // button.BtnDelete = true
  1534. // button.BtnSuspend = true
  1535. // button.BtnDelay = true
  1536. // button.BtnTurnPositive = true
  1537. // button.BtnFreeze = true
  1538. // return
  1539. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1540. // button.BtnThaw = true
  1541. // return
  1542. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1543. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1544. // button.BtnApplyReceive = true //申请领取按钮权限
  1545. // } else {
  1546. // button.BtnReceive = true //领取客户按钮权限
  1547. // }
  1548. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1549. // //button.BtnDelete = true
  1550. // }
  1551. // return
  1552. // } else { //永续
  1553. // button.BtnDelete = true
  1554. // return
  1555. // }
  1556. // } else {
  1557. // if productId == 1 {
  1558. // //button.BtnReceive = true
  1559. // } else {
  1560. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1561. // return
  1562. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1563. // return
  1564. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1565. // button.BtnThaw = false
  1566. // return
  1567. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1568. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1569. // button.BtnApplyReceive = true //申请领取按钮权限
  1570. // } else {
  1571. // button.BtnReceive = true //领取客户按钮权限
  1572. // }
  1573. // return
  1574. // } else { //永续
  1575. // button.BtnDelete = true
  1576. // return
  1577. // }
  1578. // }
  1579. // }
  1580. // }
  1581. // } else {
  1582. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1583. // statusSlice := strings.Split(status, "/")
  1584. // raiStatus := statusSlice[1]
  1585. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1586. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1587. // button.BtnApplyReceive = true //申请领取按钮权限
  1588. // } else {
  1589. // button.BtnReceive = true //领取客户按钮权限
  1590. // }
  1591. // return
  1592. // }
  1593. // }
  1594. // }
  1595. // return button
  1596. //}
  1597. // 校验当前操作员是否具有联系人权限是否有操作权限
  1598. func CheckCompanyUserButton(roleTypeCode string, itemSellerId, sysUserId, productId, shareSellerId int, status string) (ok bool) {
  1599. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1600. ok = true
  1601. return
  1602. }
  1603. if sysUserId == itemSellerId || shareSellerId == sysUserId {
  1604. ok = true
  1605. //如果客户状态是流失,那么就无法操作
  1606. if status == utils.COMPANY_STATUS_LOSE || status == utils.COMPANY_STATUS_CLOSE {
  1607. ok = false
  1608. return
  1609. }
  1610. return
  1611. } else {
  1612. if productId == 1 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1613. //如果是ficc类型,同时当前账户是ficc管理员
  1614. ok = true
  1615. } else if productId == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1616. //如果是权益类型,同时当前账户是 权益管理员
  1617. ok = true
  1618. }
  1619. }
  1620. return
  1621. }
  1622. // GenerateOpenCompanyCode 生成第三方code编号
  1623. func GenerateOpenCompanyCode(companyId int) (openCode string) {
  1624. openCode = utils.MD5(fmt.Sprint(companyId, "hzyj20210902"))
  1625. return
  1626. }
  1627. // GenerateOpenCompanyProductCode 生成客户产品第三方code编号
  1628. func GenerateOpenCompanyProductCode(companyId, productId int) (openCode string) {
  1629. openCode = utils.MD5(fmt.Sprint(companyId, "_", productId, "hzyj20210902"))
  1630. return
  1631. }
  1632. // GetApplyTurnContractType
  1633. // 获取客户申请合同类型
  1634. func GetApplyTurnContractType(companyId, productId int) (contractType string, err error) {
  1635. //合同类型
  1636. contractType = "新签合同"
  1637. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  1638. if err != nil {
  1639. if err.Error() == utils.ErrNoRow() {
  1640. err = nil
  1641. return
  1642. }
  1643. err = errors.New("获取客户信息失败,Err:" + err.Error())
  1644. return
  1645. }
  1646. // 当前客户产品状态为试用,那么是续约合同
  1647. if companyProduct.Status == "正式" {
  1648. contractType = "续约合同"
  1649. }
  1650. var condition string
  1651. var pars []interface{}
  1652. condition += " AND product_id = ?"
  1653. pars = append(pars, productId)
  1654. condition += " AND status = ?"
  1655. pars = append(pars, 1)
  1656. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  1657. if err != nil {
  1658. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1659. return
  1660. }
  1661. if len(list) > 0 {
  1662. contractType = "续约合同"
  1663. }
  1664. //查询是否存在正式转试用的记录,如果存在,那么合同类型是续约合同
  1665. total, err := company.GetCompanyProductOperationRecordCount(companyProduct.CompanyId, companyProduct.ProductId)
  1666. if err != nil {
  1667. err = errors.New("查询用户变更记录异常,Err:" + err.Error())
  1668. return
  1669. }
  1670. if total > 0 {
  1671. contractType = "续约合同"
  1672. }
  1673. return
  1674. }
  1675. // GetLastContractPermissionList
  1676. // 获取客户的最近合同的权限期限
  1677. func GetLastContractPermissionList(companyId, productId int) (permissionMap map[int]company.PermissionLookItem, err error) {
  1678. permissionMap = map[int]company.PermissionLookItem{}
  1679. contractList, err := company.GetCompanyWillContractList(companyId, productId)
  1680. if err != nil {
  1681. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1682. return
  1683. }
  1684. for _, contractInfo := range contractList {
  1685. permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(strconv.Itoa(contractInfo.CompanyContractId))
  1686. if permissionErr != nil {
  1687. err = errors.New("获取合同信息失败,Err:" + permissionErr.Error())
  1688. return
  1689. }
  1690. for _, v := range permissionList {
  1691. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1692. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1693. if tmpErr != nil {
  1694. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1695. return
  1696. }
  1697. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1698. if err != nil {
  1699. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1700. return
  1701. }
  1702. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1703. if nowEndDateTime.After(perEndDateTime) {
  1704. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1705. ChartPermissionId: v.ChartPermissionId,
  1706. PermissionName: v.ChartPermissionName,
  1707. StartDate: v.StartDate,
  1708. EndDate: v.EndDate,
  1709. //Status string `description:"'正式','试用','关闭'"`
  1710. //ExpireDay string `description:"到期天数"`
  1711. ClassifyName: v.ClassifyName,
  1712. }
  1713. }
  1714. } else {
  1715. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1716. ChartPermissionId: v.ChartPermissionId,
  1717. PermissionName: v.ChartPermissionName,
  1718. StartDate: v.StartDate,
  1719. EndDate: v.EndDate,
  1720. //Status string `description:"'正式','试用','关闭'"`
  1721. //ExpireDay string `description:"到期天数"`
  1722. ClassifyName: v.ClassifyName,
  1723. }
  1724. }
  1725. }
  1726. }
  1727. //获取权限
  1728. permissionList, permissionErr := company.GetCompanyReportPermissionListByProductId(companyId, productId)
  1729. if permissionErr != nil {
  1730. err = errors.New("获取权限失败,Err:" + permissionErr.Error())
  1731. return
  1732. }
  1733. for _, v := range permissionList {
  1734. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1735. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1736. if tmpErr != nil {
  1737. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1738. return
  1739. }
  1740. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1741. if err != nil {
  1742. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1743. return
  1744. }
  1745. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1746. if nowEndDateTime.After(perEndDateTime) {
  1747. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1748. ChartPermissionId: v.ChartPermissionId,
  1749. PermissionName: v.PermissionName,
  1750. StartDate: v.StartDate,
  1751. EndDate: v.EndDate,
  1752. //Status string `description:"'正式','试用','关闭'"`
  1753. //ExpireDay string `description:"到期天数"`
  1754. ClassifyName: v.ClassifyName,
  1755. }
  1756. }
  1757. } else {
  1758. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1759. ChartPermissionId: v.ChartPermissionId,
  1760. PermissionName: v.PermissionName,
  1761. StartDate: v.StartDate,
  1762. EndDate: v.EndDate,
  1763. //Status string `description:"'正式','试用','关闭'"`
  1764. //ExpireDay string `description:"到期天数"`
  1765. ClassifyName: v.ClassifyName,
  1766. }
  1767. }
  1768. }
  1769. return
  1770. }
  1771. // GetFiccLastUserViewHistoryByCompanyIds 根据客户id集合map获取ficc最后一次阅读时间
  1772. func GetFiccLastUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTime map[int]time.Time, err error) {
  1773. //user_view_record mobile
  1774. companyViewTime = make(map[int]time.Time)
  1775. userViewList, err := models.GetLastUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1776. if err != nil {
  1777. return
  1778. }
  1779. for _, userView := range userViewList {
  1780. companyViewTime[userView.CompanyId] = userView.ViewTime
  1781. }
  1782. //user_view_record email
  1783. userViewList, err = models.GetLastUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1784. if err != nil {
  1785. return
  1786. }
  1787. checkLastTime(companyViewTime, userViewList)
  1788. //AdvisoryArticleViewRecord mobile
  1789. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1790. if err != nil {
  1791. return
  1792. }
  1793. checkLastTime(companyViewTime, userViewList)
  1794. //AdvisoryArticleViewRecord email
  1795. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1796. if err != nil {
  1797. return
  1798. }
  1799. checkLastTime(companyViewTime, userViewList)
  1800. //ReportViewRecord mobile
  1801. mobileOrEmailViewList, err := models.GetLastReportViewRecordByMobileList(mobileList)
  1802. if err != nil {
  1803. return
  1804. }
  1805. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, mobileCompanyIdMap)
  1806. //ReportViewRecord email
  1807. mobileOrEmailViewList, err = models.GetLastReportViewRecordByEmailList(emailList)
  1808. if err != nil {
  1809. return
  1810. }
  1811. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, emailCompanyIdMap)
  1812. //UserViewStatistics mobile
  1813. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1814. if err != nil {
  1815. return
  1816. }
  1817. checkLastTime(companyViewTime, userViewList)
  1818. //UserViewStatistics email
  1819. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1820. if err != nil {
  1821. return
  1822. }
  1823. checkLastTime(companyViewTime, userViewList)
  1824. return
  1825. }
  1826. // GetRaiLastUserViewHistoryByCompanyIds 根据客户id集合map获取权益最后一次阅读时间
  1827. func GetRaiLastUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTime map[int]time.Time, err error) {
  1828. //CygxArticleViewRecord mobile
  1829. companyViewTime = make(map[int]time.Time)
  1830. userViewList, err := models.GetLastCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1831. if err != nil {
  1832. return
  1833. }
  1834. for _, userView := range userViewList {
  1835. companyViewTime[userView.CompanyId] = userView.ViewTime
  1836. }
  1837. //CygxArticleViewRecord email
  1838. userViewList, err = models.GetLastCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1839. if err != nil {
  1840. return
  1841. }
  1842. checkLastTime(companyViewTime, userViewList)
  1843. return
  1844. }
  1845. // checkLastTime 检测最后的时间并重新赋值
  1846. func checkLastTime(companyViewTime map[int]time.Time, userViewList []*models.CompanyLastViewSlice) {
  1847. for _, userView := range userViewList {
  1848. if viewTime, ok := companyViewTime[userView.CompanyId]; ok {
  1849. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1850. companyViewTime[userView.CompanyId] = userView.ViewTime
  1851. }
  1852. } else { //如果没有数据,那么直接赋值
  1853. companyViewTime[userView.CompanyId] = userView.ViewTime
  1854. }
  1855. }
  1856. return
  1857. }
  1858. // checkMobileOrEmailLastTime 根据用户信息检测最后的时间并重新赋值
  1859. func checkMobileOrEmailLastTime(companyViewTime map[int]time.Time, userViewList []*models.MobileOrEmailLastViewSlice, companyMap map[string]int) {
  1860. for _, userView := range userViewList {
  1861. // 先找到客户id
  1862. companyId, ok := companyMap[userView.Mobile]
  1863. if !ok {
  1864. continue
  1865. }
  1866. // 相同客户id的数据进行比较
  1867. if viewTime, ok := companyViewTime[companyId]; ok {
  1868. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1869. companyViewTime[companyId] = userView.ViewTime
  1870. }
  1871. } else { //如果没有数据,那么直接赋值
  1872. companyViewTime[companyId] = userView.ViewTime
  1873. }
  1874. }
  1875. return
  1876. }
  1877. // GetFiccCountUserViewHistoryByCompanyIds 根据客户id集合map获取ficc的阅读次数
  1878. func GetFiccCountUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTotal map[int]int, err error) {
  1879. //user_view_record mobile
  1880. companyViewTotal = make(map[int]int)
  1881. userViewList, err := models.GetCountUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1882. if err != nil {
  1883. return
  1884. }
  1885. for _, userView := range userViewList {
  1886. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1887. }
  1888. userViewList, err = models.GetCountUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1889. if err != nil {
  1890. return
  1891. }
  1892. checkCount(companyViewTotal, userViewList)
  1893. //AdvisoryArticleViewRecord mobile
  1894. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1895. if err != nil {
  1896. return
  1897. }
  1898. checkCount(companyViewTotal, userViewList)
  1899. //AdvisoryArticleViewRecord email
  1900. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1901. if err != nil {
  1902. return
  1903. }
  1904. checkCount(companyViewTotal, userViewList)
  1905. //ReportViewRecord mobile
  1906. mobileOrEmailViewList, err := models.GetCountReportViewRecordByMobileList(mobileList)
  1907. if err != nil {
  1908. return
  1909. }
  1910. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, mobileCompanyIdMap)
  1911. //ReportViewRecord email
  1912. mobileOrEmailViewList, err = models.GetCountReportViewRecordByEmailList(emailList)
  1913. if err != nil {
  1914. return
  1915. }
  1916. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, emailCompanyIdMap)
  1917. //UserViewStatistics mobile
  1918. userViewList, err = models.GetUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1919. if err != nil {
  1920. return
  1921. }
  1922. checkCount(companyViewTotal, userViewList)
  1923. //UserViewStatistics email
  1924. userViewList, err = models.GetUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1925. if err != nil {
  1926. return
  1927. }
  1928. checkCount(companyViewTotal, userViewList)
  1929. return
  1930. }
  1931. // GetRaiCountUserViewHistoryByCompanyIds 根据客户id集合map获取权益的阅读次数
  1932. func GetRaiCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  1933. //CygxArticleViewRecord mobile
  1934. companyViewTotal = make(map[int]int)
  1935. userViewList, err := models.GetCountCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1936. if err != nil {
  1937. return
  1938. }
  1939. for _, userView := range userViewList {
  1940. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1941. }
  1942. //CygxArticleViewRecord email
  1943. userViewList, err = models.GetCountCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1944. if err != nil {
  1945. return
  1946. }
  1947. checkCount(companyViewTotal, userViewList)
  1948. return
  1949. }
  1950. // GetAllCountUserViewHistoryByCompanyIds 根据客户id集合map获取所有的阅读次数
  1951. //func GetAllCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  1952. // companyViewTotal = make(map[int]int)
  1953. // companyFiccViewTotal, err := GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  1954. // if err != nil {
  1955. // return
  1956. // }
  1957. //
  1958. // companyRaiViewTotal, err := GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  1959. // if err != nil {
  1960. // return
  1961. // }
  1962. //
  1963. // companyIdList := strings.Split(companyIdStr, ",")
  1964. //
  1965. // for _, companyIdStr := range companyIdList {
  1966. // companyId, _ := strconv.Atoi(companyIdStr)
  1967. // ficcTotal, ok := companyFiccViewTotal[companyId]
  1968. // if !ok {
  1969. // ficcTotal = 0
  1970. // }
  1971. // raiTotal, ok := companyRaiViewTotal[companyId]
  1972. // if !ok {
  1973. // raiTotal = 0
  1974. // }
  1975. // companyViewTotal[companyId] = ficcTotal + raiTotal
  1976. // }
  1977. // return
  1978. //}
  1979. func checkCount(companyViewTotal map[int]int, userViewList []*models.CompanyViewTotalSlice) {
  1980. for _, userView := range userViewList {
  1981. if viewTotal, ok := companyViewTotal[userView.CompanyId]; ok {
  1982. companyViewTotal[userView.CompanyId] = viewTotal + userView.ViewTotal
  1983. } else { //如果没有数据,那么直接赋值
  1984. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1985. }
  1986. }
  1987. return
  1988. }
  1989. // checkMobileOrEmailCount 根据手机号或者邮箱进行数据比较
  1990. func checkMobileOrEmailCount(companyViewTotal map[int]int, mobileOrEmailViewList []*models.MobileOrEmailViewTotalSlice, companyMap map[string]int) {
  1991. for _, userView := range mobileOrEmailViewList {
  1992. // 先找到客户id
  1993. companyId, ok := companyMap[userView.Mobile]
  1994. if !ok {
  1995. continue
  1996. }
  1997. // 相同客户id的数据进行比较
  1998. if viewTotal, ok := companyViewTotal[companyId]; ok {
  1999. companyViewTotal[companyId] = viewTotal + userView.ViewTotal
  2000. } else { //如果没有数据,那么直接赋值
  2001. companyViewTotal[companyId] = userView.ViewTotal
  2002. }
  2003. }
  2004. return
  2005. }
  2006. // ModifyCompanyProductLastViewData 修改客户产品的总共阅读次数以及最近阅读时间
  2007. func ModifyCompanyProductLastViewData(companyIdList []int) (err error) {
  2008. defer func() {
  2009. if err != nil {
  2010. go alarm_msg.SendAlarmMsg("修改客户产品的总共阅读次数以及最近阅读时间失败,"+fmt.Sprint("companyIdList:", companyIdList, ";err:", err), 3)
  2011. //go utils.SendEmail("修改客户产品的总共阅读次数以及最近阅读时间失败", fmt.Sprint("companyIdList:", companyIdList, ";err:", err), utils.EmailSendToUsers)
  2012. }
  2013. }()
  2014. wxUserList, err := models.GetWxUserByCompanyIds(companyIdList)
  2015. if err != nil {
  2016. return
  2017. }
  2018. mobileList := make([]string, 0)
  2019. mobileCompanyIdMap := make(map[string]int, 0)
  2020. emailList := make([]string, 0)
  2021. emailCompanyIdMap := make(map[string]int, 0)
  2022. for _, v := range wxUserList {
  2023. if v.Mobile != `` {
  2024. mobileList = append(mobileList, v.Mobile)
  2025. mobileCompanyIdMap[v.Mobile] = v.CompanyId
  2026. }
  2027. if v.Email != `` {
  2028. emailList = append(emailList, v.Email)
  2029. emailCompanyIdMap[v.Email] = v.CompanyId
  2030. }
  2031. }
  2032. companyIdStr := ``
  2033. for _, companyId := range companyIdList {
  2034. companyIdStr += fmt.Sprint(companyId, ",")
  2035. }
  2036. companyIdStr = companyIdStr[:len(companyIdStr)-1]
  2037. companyFiccViewTotalMap, err := GetFiccCountUserViewHistoryByCompanyIds(companyIdStr, mobileList, emailList, mobileCompanyIdMap, emailCompanyIdMap)
  2038. if err != nil {
  2039. return
  2040. }
  2041. companyFiccLastViewMap, err := GetFiccLastUserViewHistoryByCompanyIds(companyIdStr, mobileList, emailList, mobileCompanyIdMap, emailCompanyIdMap)
  2042. if err != nil {
  2043. return
  2044. }
  2045. companyRaiViewTotalMap, err := GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  2046. if err != nil {
  2047. return
  2048. }
  2049. companyRaiLastViewMap, err := GetRaiLastUserViewHistoryByCompanyIds(companyIdStr)
  2050. if err != nil {
  2051. return
  2052. }
  2053. for _, companyId := range companyIdList {
  2054. //ficc
  2055. var companyFiccViewTotal int
  2056. var companyFiccLastView time.Time
  2057. var companyFiccLastViewStr string
  2058. companyFiccViewTotal, _ = companyFiccViewTotalMap[companyId]
  2059. companyFiccLastView, _ = companyFiccLastViewMap[companyId]
  2060. if companyFiccLastView.IsZero() {
  2061. companyFiccLastViewStr = "0000-00-00 00:00:00"
  2062. } else {
  2063. companyFiccLastViewStr = companyFiccLastView.Format(utils.FormatDateTime)
  2064. }
  2065. company.ModifyCompanyProductLastViewData(companyId, 1, companyFiccViewTotal, companyFiccLastViewStr)
  2066. //权益
  2067. var companyRaiViewTotal int
  2068. var companyRaiLastView time.Time
  2069. var companyRaiLastViewStr string
  2070. companyRaiViewTotal, _ = companyRaiViewTotalMap[companyId]
  2071. companyRaiLastView, _ = companyRaiLastViewMap[companyId]
  2072. if companyRaiLastView.IsZero() {
  2073. companyRaiLastViewStr = "0000-00-00 00:00:00"
  2074. } else {
  2075. companyRaiLastViewStr = companyRaiLastView.Format(utils.FormatDateTime)
  2076. }
  2077. company.ModifyCompanyProductLastViewData(companyId, 2, companyRaiViewTotal, companyRaiLastViewStr)
  2078. }
  2079. return
  2080. }
  2081. // CompanyDeleteBakInfo 删除客户时的备份信息
  2082. type CompanyDeleteBakInfo struct {
  2083. CompanyId int `description:"客户id"`
  2084. CompanyName string `description:"客户名称"`
  2085. CompanyInfo *company.Company `description:"客户主表信息"`
  2086. CompanyProductInfo []*company.CompanyProduct `description:"客户产品信息"`
  2087. CompanyPermissionInfo []*company.CompanyReportPermission `description:"客户产品权限信息"`
  2088. UserSellerRelationInfo []*models.UserSellerRelation `description:"联系人与销售关系信息"`
  2089. UserRecordInfo []*models.UserRecord `description:"联系人关系信息"`
  2090. UserInfo []*models.WxUser `description:"联系人信息"`
  2091. CompanyChartPermissionInfo []*company_user.ChartClassifyPermission `description:"客户图表权限信息"`
  2092. CompanyContract []*company.CompanyContract `description:"客户合同信息"`
  2093. CompanyContractPermission []*company.CompanyContractPermission `description:"客户合同权限信息"`
  2094. OpUserId int `description:"操作人id"`
  2095. OpUserName string `description:"操作人名称"`
  2096. }
  2097. // GetBeforeDeleteCompanyInfo 获取删除客户之前的信息
  2098. func GetBeforeDeleteCompanyInfo(companyId int) (companyProductLists []*company.CompanyProduct, companyReportPermissions []*company.CompanyReportPermission, wxUsers []*models.WxUser, userSellerRelations []*models.UserSellerRelation, companyContracts []*company.CompanyContract, companyContractPermissions []*company.CompanyContractPermission, companyInfo *company.Company, err error) {
  2099. o := orm.NewOrm()
  2100. //删除客户产品
  2101. bakSql := `SELECT * FROM company_product WHERE company_id=? `
  2102. _, err = o.Raw(bakSql, companyId).QueryRows(&companyProductLists)
  2103. if err != nil {
  2104. return
  2105. }
  2106. //删除客户权限
  2107. bakSql = `SELECT * FROM company_report_permission WHERE company_id=? `
  2108. _, err = o.Raw(bakSql, companyId).QueryRows(&companyReportPermissions)
  2109. if err != nil {
  2110. return
  2111. }
  2112. //联系人表
  2113. bakSql = `SELECT * FROM wx_user WHERE company_id=? `
  2114. _, err = o.Raw(bakSql, companyId).QueryRows(&wxUsers)
  2115. if err != nil {
  2116. return
  2117. }
  2118. //联系人 与 销售 关系表
  2119. bakSql = `SELECT * FROM user_seller_relation WHERE company_id=? `
  2120. _, err = o.Raw(bakSql, companyId).QueryRows(&userSellerRelations)
  2121. if err != nil {
  2122. return
  2123. }
  2124. // 合同
  2125. bakSql = `SELECT * FROM company_contract WHERE company_id=? `
  2126. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContracts)
  2127. if err != nil {
  2128. return
  2129. }
  2130. // 合同权限
  2131. bakSql = `SELECT * FROM company_contract_permission WHERE company_id=? `
  2132. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContractPermissions)
  2133. if err != nil {
  2134. return
  2135. }
  2136. // 客户
  2137. bakSql = `SELECT * FROM company WHERE company_id=? `
  2138. err = o.Raw(bakSql, companyId).QueryRow(&companyInfo)
  2139. if err != nil {
  2140. return
  2141. }
  2142. return
  2143. }
  2144. // CheckCompanyReceiveButton 查询领取客户按钮的权限
  2145. func CheckCompanyReceiveButton(adminId int) (receiveEnabled bool, err error) {
  2146. receiveEnabled = true
  2147. receivePermissionInfo, err := company.GetSellerCompanyPermissionByAdminIdType(adminId, 1)
  2148. if err != nil {
  2149. if err.Error() != utils.ErrNoRow() {
  2150. err = errors.New("获取账号权限失败,Err:" + err.Error())
  2151. return
  2152. }
  2153. } else {
  2154. if receivePermissionInfo != nil && receivePermissionInfo.Enabled == 0 {
  2155. receiveEnabled = false
  2156. }
  2157. }
  2158. return
  2159. }
  2160. // AddWxUserOpLog 记录新增用户的日志
  2161. func AddWxUserOpLog(wxUserOpLog company.WxUserOpLog) {
  2162. userSellerRelationList, err := models.GetUserSellerRelationList(wxUserOpLog.UserId)
  2163. if err != nil {
  2164. return
  2165. }
  2166. userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
  2167. wxUserOpLog.UserSellerInfo = string(userSellerRelationInfo)
  2168. company.AddWxUserOpLog(&wxUserOpLog)
  2169. }
  2170. // FilterReadAndContractAuth 根据已购品种和阅读权限获取筛选条件
  2171. func FilterReadAndContractAuth(chartPermissions, contractPermissions, condition string) (cond string, empty bool, err error) {
  2172. cond = condition
  2173. var queryChart, queryContract bool
  2174. if chartPermissions != "" && chartPermissions != "1" {
  2175. queryChart = true
  2176. }
  2177. if contractPermissions != "" && contractPermissions != "1" {
  2178. queryContract = true
  2179. }
  2180. if !queryChart && !queryContract {
  2181. return
  2182. }
  2183. readIds := make([]int, 0)
  2184. buyIds := make([]int, 0)
  2185. // 阅读权限
  2186. if queryChart {
  2187. {
  2188. // 处理权益的主观客观的筛选条件搜索
  2189. ids := make([]int, 0)
  2190. strIdArr := strings.Split(chartPermissions, ",")
  2191. for _, s := range strIdArr {
  2192. v, _ := strconv.Atoi(s)
  2193. ids = append(ids, v)
  2194. }
  2195. if len(ids) == 0 {
  2196. err = fmt.Errorf("权限ID有误")
  2197. return
  2198. }
  2199. names, e := company.GetPermissionNameByPermissionIds(ids)
  2200. if e != nil {
  2201. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2202. return
  2203. }
  2204. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2205. if e != nil {
  2206. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2207. return
  2208. }
  2209. companyIds, e := company.GetCompanyIdsStrByReportPermissionIds(permissionIds)
  2210. if e != nil {
  2211. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2212. return
  2213. }
  2214. readIds = companyIds
  2215. }
  2216. }
  2217. // 已购合同权限
  2218. if queryContract {
  2219. {
  2220. // 处理权益的主观客观的筛选条件搜索
  2221. ids := make([]int, 0)
  2222. strIdArr := strings.Split(contractPermissions, ",")
  2223. for _, s := range strIdArr {
  2224. v, _ := strconv.Atoi(s)
  2225. ids = append(ids, v)
  2226. }
  2227. if len(ids) == 0 {
  2228. err = fmt.Errorf("权限ID有误")
  2229. return
  2230. }
  2231. names, e := company.GetPermissionNameByPermissionIds(ids)
  2232. if e != nil {
  2233. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2234. return
  2235. }
  2236. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2237. if e != nil {
  2238. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2239. return
  2240. }
  2241. companyIds, e := company.GetCompanyIdsStrByContractPermissionIds(permissionIds)
  2242. if e != nil {
  2243. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2244. return
  2245. }
  2246. buyIds = companyIds
  2247. // 勾选了已购品种的, 仅筛选正式客户
  2248. cond += ` AND b.status = '正式'`
  2249. }
  2250. }
  2251. queryIds := make([]int, 0)
  2252. queryIdArr := make([]string, 0)
  2253. // 阅读权限和已购品种同时筛选取两者的companyIds交集
  2254. if queryChart && queryContract {
  2255. queryIds = utils.IntersectInt(readIds, buyIds)
  2256. } else if queryChart && !queryContract {
  2257. queryIds = readIds
  2258. } else if !queryChart && queryContract {
  2259. queryIds = buyIds
  2260. }
  2261. if len(queryIds) == 0 {
  2262. empty = true
  2263. return
  2264. }
  2265. for _, q := range queryIds {
  2266. queryIdArr = append(queryIdArr, strconv.Itoa(q))
  2267. }
  2268. cond += ` AND a.company_id IN (` + strings.Join(queryIdArr, ",") + `) `
  2269. return
  2270. }
  2271. // GetShareCompanyPermissionButton 正式客户共享-权限按钮(目前仅FICC有正式客户共享, 所以不管权益角色)
  2272. func GetShareCompanyPermissionButton(roleTypeCode, statuses string, productId int) (button *company.ButtonPermission) {
  2273. statusMap := make(map[int]string)
  2274. statusMap[productId] = statuses
  2275. if strings.Contains(statuses, "/") {
  2276. statusArr := strings.Split(statuses, "/")
  2277. statusMap[1] = statusArr[0]
  2278. statusMap[2] = statusArr[1]
  2279. }
  2280. // 查看权限均有
  2281. button = new(company.ButtonPermission)
  2282. button.BtnView = true
  2283. // 超管, FICC管理员
  2284. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2285. button.BtnModifySeller = true
  2286. button.BtnRemarkView = true
  2287. button.BtnServiceRecord = true
  2288. }
  2289. status, ok := statusMap[1]
  2290. if !ok {
  2291. return
  2292. }
  2293. // ficc销售
  2294. ficcArr := []string{
  2295. utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
  2296. }
  2297. if !utils.InArrayByStr(ficcArr, roleTypeCode) {
  2298. return
  2299. }
  2300. if status == utils.COMPANY_STATUS_TRY_OUT {
  2301. button.BtnTurnPositive = true
  2302. button.BtnRemarkEdit = true
  2303. button.BtnRemarkView = true
  2304. button.BtnServiceRecord = true
  2305. }
  2306. if status == utils.COMPANY_STATUS_FORMAL {
  2307. button.BtnUpdate = true
  2308. button.BtnAddAgreement = true
  2309. button.BtnTryOut = true
  2310. button.BtnRemarkEdit = true
  2311. button.BtnRemarkView = true
  2312. button.BtnServiceRecord = true
  2313. }
  2314. return
  2315. }