company.go 83 KB

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