company.go 82 KB

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