company.go 87 KB

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