company.go 89 KB

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