eta_business.go 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039
  1. package eta_business
  2. import (
  3. "encoding/json"
  4. "eta/eta_forum_admin/controllers"
  5. "eta/eta_forum_admin/models"
  6. "eta/eta_forum_admin/models/eta_business"
  7. "eta/eta_forum_admin/models/help_doc"
  8. "eta/eta_forum_admin/services"
  9. etaBusinessService "eta/eta_forum_admin/services/eta_business"
  10. "eta/eta_forum_admin/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "sort"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // EtaBusinessController ETA商家
  19. type EtaBusinessController struct {
  20. controllers.BaseAuthController
  21. }
  22. // PageList
  23. // @Title 商家列表-分页
  24. // @Description 商家列表-分页
  25. // @Param Keyword query string false "关键词: 商家名称/社会信用码/商家编码"
  26. // @Param SellerIds query string false "销售IDs"
  27. // @Param SigningStatus query string false "签约状态: 1-首次签约; 2-续约中; 3-已终止"
  28. // @Param Province query string false "省份筛选"
  29. // @Param City query string false "城市筛选"
  30. // @Param IndustryId query int false "行业ID"
  31. // @Param SortParam query int false "排序字段: 1-签约时间; 2-到期时间; 3-创建时间; 4-用户上限"
  32. // @Param SortType query int false "排序类型: 1-正序; 2-倒序"
  33. // @Param chartClassifyIds query string false "分类id,用逗号分隔"
  34. // @Success 200 Ret=200 获取成功
  35. // @router /page_list [get]
  36. func (this *EtaBusinessController) PageList() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. if br.ErrMsg == "" {
  40. br.IsSendEmail = false
  41. }
  42. this.Data["json"] = br
  43. this.ServeJSON()
  44. }()
  45. sysUser := this.SysUser
  46. if sysUser == nil {
  47. br.Msg = "请登录"
  48. br.ErrMsg = "请登录,SysUser Is Empty"
  49. br.Ret = 408
  50. return
  51. }
  52. // 分页
  53. pageSize, _ := this.GetInt("PageSize")
  54. currentIndex, _ := this.GetInt("CurrentIndex")
  55. var startSize int
  56. if pageSize <= 0 {
  57. pageSize = utils.PageSize20
  58. }
  59. if currentIndex <= 0 {
  60. currentIndex = 1
  61. }
  62. startSize = utils.StartIndex(currentIndex, pageSize)
  63. // 权限校验
  64. resp := new(eta_business.EtaBusinessListResp)
  65. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  66. if e != nil {
  67. br.Msg = "操作失败"
  68. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  69. return
  70. }
  71. if !ok {
  72. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  73. br.Data = resp
  74. br.Ret = 200
  75. br.Success = true
  76. br.Msg = "获取成功"
  77. return
  78. }
  79. cond := ``
  80. pars := make([]interface{}, 0)
  81. // 筛选项
  82. {
  83. // 关键词
  84. keyword := this.GetString("Keyword", "")
  85. keyword = strings.TrimSpace(keyword)
  86. if keyword != "" {
  87. kw := fmt.Sprint("%", keyword, "%")
  88. cond += fmt.Sprintf(` AND (e.%s LIKE ? OR e.%s LIKE ? OR e.%s LIKE ?)`, eta_business.EtaBusinessColumns.BusinessName, eta_business.EtaBusinessColumns.BusinessCode, eta_business.EtaBusinessColumns.CreditCode)
  89. pars = append(pars, kw, kw, kw)
  90. }
  91. // 销售
  92. sellerIds := this.GetString("SellerIds", "")
  93. if sellerIds != "" {
  94. arr := strings.Split(sellerIds, ",")
  95. ids := make([]int, 0)
  96. for _, s := range arr {
  97. v, e := strconv.Atoi(s)
  98. if e != nil {
  99. br.Msg = "销售ID有误"
  100. return
  101. }
  102. ids = append(ids, v)
  103. }
  104. if len(ids) == 0 {
  105. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  106. br.Data = resp
  107. br.Ret = 200
  108. br.Success = true
  109. br.Msg = "获取成功"
  110. return
  111. }
  112. cond += fmt.Sprintf(` AND e.%s IN (%s)`, eta_business.EtaBusinessColumns.SellerId, utils.GetOrmInReplace(len(ids)))
  113. pars = append(pars, ids)
  114. }
  115. // 签约状态
  116. signingStatus, _ := this.GetInt("SigningStatus", 0)
  117. if signingStatus > 0 {
  118. cond += fmt.Sprintf(` AND e.%s = ?`, eta_business.EtaBusinessColumns.SigningStatus)
  119. pars = append(pars, signingStatus)
  120. }
  121. // 商家地址
  122. province := this.GetString("Province", "")
  123. province = strings.TrimSpace(province)
  124. if province != "" {
  125. provinceArr := strings.Split(province, ",")
  126. if len(provinceArr) == 0 {
  127. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  128. br.Data = resp
  129. br.Ret = 200
  130. br.Success = true
  131. br.Msg = "获取成功"
  132. return
  133. }
  134. cond += fmt.Sprintf(` AND e.%s IN (%s)`, eta_business.EtaBusinessColumns.Province, utils.GetOrmInReplace(len(provinceArr)))
  135. pars = append(pars, provinceArr)
  136. }
  137. city := this.GetString("City", "")
  138. city = strings.TrimSpace(city)
  139. if city != "" {
  140. cityArr := strings.Split(city, ",")
  141. if len(cityArr) == 0 {
  142. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  143. br.Data = resp
  144. br.Ret = 200
  145. br.Success = true
  146. br.Msg = "获取成功"
  147. return
  148. }
  149. cond += fmt.Sprintf(` AND e.%s IN (%s)`, eta_business.EtaBusinessColumns.City, utils.GetOrmInReplace(len(cityArr)))
  150. pars = append(pars, cityArr)
  151. }
  152. // 行业
  153. industryId, _ := this.GetInt("IndustryId", 0)
  154. if industryId > 0 {
  155. cond += fmt.Sprintf(` AND e.%s = ?`, eta_business.EtaBusinessColumns.IndustryId)
  156. pars = append(pars, industryId)
  157. }
  158. // 国家
  159. nation := this.GetString("Nation", "")
  160. nation = strings.TrimSpace(nation)
  161. if nation != "" {
  162. cond += ` AND e.nation = ? `
  163. pars = append(pars, nation)
  164. }
  165. // 分类id
  166. chartClassifyIds := this.GetString("ChartClassifyIds", "")
  167. chartClassifyIds = strings.TrimSpace(chartClassifyIds)
  168. if chartClassifyIds != "" {
  169. chartClassifyIdsArr := strings.Split(chartClassifyIds, ",")
  170. if len(chartClassifyIdsArr) > 0 {
  171. cond += fmt.Sprintf(` AND p.chart_classify_id IN (%s)`, utils.GetOrmInReplace(len(chartClassifyIdsArr)))
  172. pars = append(pars, chartClassifyIdsArr)
  173. }
  174. }
  175. }
  176. order := ``
  177. // 排序
  178. {
  179. fieldArr := []int{1, 2, 3, 4}
  180. typeArr := []int{1, 2}
  181. fieldMap := map[int]string{
  182. 1: "signing_time",
  183. 2: "expired_time",
  184. 3: "create_time",
  185. 4: "user_max",
  186. }
  187. typeMap := map[int]string{
  188. 1: "ASC",
  189. 2: "DESC",
  190. }
  191. sortParam, _ := this.GetInt("SortParam", 0)
  192. sortType, _ := this.GetInt("SortType", 0)
  193. if utils.InArrayByInt(fieldArr, sortParam) && utils.InArrayByInt(typeArr, sortType) {
  194. order = fmt.Sprintf("%s %s", fieldMap[sortParam], typeMap[sortType])
  195. }
  196. fmt.Println("order: ", order)
  197. }
  198. // 获取列表
  199. businessOb := new(eta_business.EtaBusiness)
  200. total, e := businessOb.GetWithChartClassifyCountByCondition(cond, pars)
  201. if e != nil {
  202. br.Msg = "获取失败"
  203. br.ErrMsg = "获取商家总数失败, Err: " + e.Error()
  204. return
  205. }
  206. list, e := businessOb.GetPageItemsWithChartClassifyByCondition(cond, pars, []string{}, order, startSize, pageSize)
  207. if e != nil {
  208. br.Msg = "获取失败"
  209. br.ErrMsg = "获取商家列表失败, Err: " + e.Error()
  210. return
  211. }
  212. items := make([]*eta_business.EtaBusinessItem, 0)
  213. for _, v := range list {
  214. b := new(eta_business.EtaBusinessItem)
  215. b.EtaBusinessId = v.EtaBusinessId
  216. b.BusinessName = v.BusinessName
  217. b.BusinessCode = v.BusinessCode
  218. b.CreditCode = v.CreditCode
  219. b.RegionType = v.RegionType
  220. b.Province = v.Province
  221. b.City = v.City
  222. b.Address = v.Address
  223. b.SellerId = v.SellerId
  224. b.SellerName = v.SellerName
  225. b.Leader = v.Leader
  226. b.IndustryId = v.IndustryId
  227. b.IndustryName = v.IndustryName
  228. b.CapitalScale = v.CapitalScale
  229. b.ResearchTeamSize = v.ResearchTeamSize
  230. b.UserMax = v.UserMax
  231. b.SigningStatus = v.SigningStatus
  232. b.Enable = v.Enable
  233. b.ContractId = v.ContractId
  234. b.SigningTime = utils.TimeTransferString(utils.FormatDate, v.SigningTime)
  235. b.ExpiredTime = utils.TimeTransferString(utils.FormatDate, v.ExpiredTime)
  236. b.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  237. b.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
  238. b.Nation = v.Nation
  239. items = append(items, b)
  240. }
  241. resp.List = items
  242. resp.Paging = paging.GetPaging(currentIndex, pageSize, total)
  243. br.Data = resp
  244. br.Ret = 200
  245. br.Success = true
  246. br.Msg = "获取成功"
  247. }
  248. // Add
  249. // @Title 新增商家
  250. // @Description 新增商家
  251. // @Param request body eta_business.EtaBusinessAddReq true "type json string"
  252. // @Success 200 Ret=200 操作成功
  253. // @router /add [post]
  254. func (this *EtaBusinessController) Add() {
  255. br := new(models.BaseResponse).Init()
  256. defer func() {
  257. if br.ErrMsg == "" {
  258. br.IsSendEmail = false
  259. }
  260. this.Data["json"] = br
  261. this.ServeJSON()
  262. }()
  263. sysUser := this.SysUser
  264. if sysUser == nil {
  265. br.Msg = "请登录"
  266. br.ErrMsg = "请登录,SysUser Is Empty"
  267. br.Ret = 408
  268. return
  269. }
  270. // 操作权限校验
  271. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  272. if e != nil {
  273. br.Msg = "操作失败"
  274. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  275. return
  276. }
  277. if !ok {
  278. br.Msg = "无权操作"
  279. return
  280. }
  281. // 参数校验
  282. var req eta_business.EtaBusinessAddReq
  283. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  284. br.Msg = "参数解析异常!"
  285. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  286. return
  287. }
  288. req.BusinessName = strings.TrimSpace(req.BusinessName)
  289. if req.BusinessName == "" {
  290. br.Msg = "商家名称不可为空"
  291. return
  292. }
  293. if req.CreditCode == "" {
  294. br.Msg = "社会统一信用码不可为空"
  295. return
  296. }
  297. req.Province = strings.TrimSpace(req.Province)
  298. if req.Nation == "" {
  299. if req.Province == "" {
  300. br.Msg = "省份不可为空"
  301. return
  302. }
  303. req.City = strings.TrimSpace(req.City)
  304. if req.City == "" {
  305. br.Msg = "城市不可为空"
  306. return
  307. }
  308. }
  309. req.Leader = strings.TrimSpace(req.Leader)
  310. if req.Leader == "" {
  311. br.Msg = "决策人不可为空"
  312. return
  313. }
  314. if req.IndustryId <= 0 || req.IndustryName == "" {
  315. br.Msg = "所属行业不可为空"
  316. return
  317. }
  318. if req.ResearchTeamSize == "" {
  319. br.Msg = "研究团队规模不可为空"
  320. return
  321. }
  322. /*if req.UserMax <= 0 {
  323. br.Msg = "用户上限不可小于0"
  324. return
  325. }*/
  326. req.CapitalScale = strings.TrimSpace(req.CapitalScale)
  327. // 如果仅校验不新增, 那么不做第二页签约时间的校验(已废弃, 20230919签约时间非必填)
  328. var signTime, expiredTime time.Time
  329. if !req.IsCheck {
  330. if req.SigningTime != "" && req.ExpiredTime != "" {
  331. signTime, e = time.ParseInLocation(utils.FormatDate, req.SigningTime, time.Local)
  332. if e != nil {
  333. br.Msg = "签约时间格式有误"
  334. br.ErrMsg = "签约时间格式有误, Err: " + e.Error()
  335. return
  336. }
  337. expiredTime, e = time.ParseInLocation(utils.FormatDate, req.ExpiredTime, time.Local)
  338. if e != nil {
  339. br.Msg = "到期时间格式有误"
  340. br.ErrMsg = "到期时间格式有误, Err: " + e.Error()
  341. return
  342. }
  343. if !expiredTime.After(signTime) {
  344. br.Msg = "到期时间不得早于签约时间"
  345. return
  346. }
  347. }
  348. }
  349. // 重名校验
  350. {
  351. item := new(eta_business.EtaBusiness)
  352. cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessColumns.BusinessName)
  353. pars := make([]interface{}, 0)
  354. pars = append(pars, req.BusinessName)
  355. exist, e := item.GetItemByCondition(cond, pars)
  356. if e != nil && e.Error() != utils.ErrNoRow() {
  357. br.Msg = "操作失败"
  358. br.ErrMsg = "获取重名商家失败, Err: " + e.Error()
  359. return
  360. }
  361. if exist != nil {
  362. br.Msg = "商家名称已存在"
  363. return
  364. }
  365. }
  366. // 社会信用码重复校验
  367. {
  368. item := new(eta_business.EtaBusiness)
  369. cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessColumns.CreditCode)
  370. pars := make([]interface{}, 0)
  371. pars = append(pars, req.CreditCode)
  372. exist, e := item.GetItemByCondition(cond, pars)
  373. if e != nil && e.Error() != utils.ErrNoRow() {
  374. br.Msg = "操作失败"
  375. br.ErrMsg = "获取重复信用码商家失败, Err: " + e.Error()
  376. return
  377. }
  378. if exist != nil {
  379. br.Msg = "商家社会信用码已存在"
  380. return
  381. }
  382. }
  383. // 如果只做校验不新增, 此处校验通过后直接返回true
  384. if req.IsCheck {
  385. br.Data = true
  386. br.Ret = 200
  387. br.Success = true
  388. br.Msg = "校验通过"
  389. return
  390. }
  391. // 商家编码
  392. businessCode, e := eta_business.CreateEtaBusinessCode()
  393. if e != nil {
  394. br.Msg = "操作失败"
  395. br.ErrMsg = "生成商家编码失败, Err: " + e.Error()
  396. return
  397. }
  398. codeEncrypt := utils.MD5(fmt.Sprintf("%s%s", businessCode, utils.BusinessCodeSalt))
  399. now := time.Now().Local()
  400. status := eta_business.EtaBusinessSigningStatusWait // 默认待签约
  401. // 若当前时间不在首次签约时间内, 也算作已终止, 进入合约期时会由定时任务改为首次签约
  402. if !signTime.IsZero() && !expiredTime.IsZero() {
  403. if !now.Before(signTime) && !now.After(expiredTime) {
  404. status = eta_business.EtaBusinessSigningStatusFirst // 首次签约
  405. } else {
  406. status = eta_business.EtaBusinessSigningStatusTerminate // 已终止
  407. }
  408. }
  409. // 新增商家和签约
  410. businessItem := new(eta_business.EtaBusiness)
  411. businessItem.BusinessName = req.BusinessName
  412. businessItem.BusinessCode = businessCode
  413. businessItem.CodeEncrypt = codeEncrypt
  414. businessItem.CreditCode = req.CreditCode
  415. businessItem.RegionType = req.RegionType
  416. businessItem.Province = req.Province
  417. businessItem.City = req.City
  418. businessItem.Address = req.Province + req.City
  419. businessItem.SellerId = req.SellerId
  420. businessItem.SellerName = req.SellerName
  421. businessItem.Leader = req.Leader
  422. businessItem.IndustryId = req.IndustryId
  423. businessItem.IndustryName = req.IndustryName
  424. businessItem.CapitalScale = req.CapitalScale
  425. businessItem.ResearchTeamSize = req.ResearchTeamSize
  426. //businessItem.UserMax = req.UserMax
  427. businessItem.Enable = 1
  428. businessItem.SigningStatus = status
  429. businessItem.SigningTime = signTime
  430. businessItem.ExpiredTime = expiredTime
  431. businessItem.CreateTime = now
  432. businessItem.ModifyTime = now
  433. businessItem.Nation = req.Nation
  434. contractItem := new(eta_business.EtaBusinessContract)
  435. if !signTime.IsZero() && !expiredTime.IsZero() {
  436. contractItem.SigningTime = signTime
  437. contractItem.ExpiredTime = expiredTime
  438. contractItem.IsFirst = 1
  439. contractItem.CreateTime = now
  440. contractItem.ModifyTime = now
  441. } else {
  442. contractItem = nil
  443. }
  444. if e = eta_business.CreateEtaBusinessAndContract(businessItem, contractItem); e != nil {
  445. br.Msg = "操作失败"
  446. br.ErrMsg = "新增商家和签约失败, Err: " + e.Error()
  447. return
  448. }
  449. // 给商家帮助文档所有分类的权限
  450. if e = help_doc.AddAllHelpDocClassifyVisible(businessItem.EtaBusinessId); e != nil {
  451. br.Msg = "操作失败"
  452. br.ErrMsg = "新增商家分类文档权限失败, Err: " + e.Error()
  453. return
  454. }
  455. resp := new(eta_business.EtaBusinessAddResp)
  456. resp.EtaBusinessId = businessItem.EtaBusinessId
  457. // 操作日志
  458. go func() {
  459. recordOb := new(eta_business.EtaBusinessOperationRecord)
  460. recordOb.EtaBusinessId = businessItem.EtaBusinessId
  461. recordOb.SellerId = businessItem.SellerId
  462. recordOb.SysUserId = sysUser.AdminId
  463. recordOb.SysRealName = sysUser.RealName
  464. recordOb.OperationType = eta_business.EtaBusinessOperationTypeAdd
  465. recordOb.OperationRemark = fmt.Sprintf("%s新增商户", sysUser.RealName)
  466. recordOb.CreateTime = time.Now().Local()
  467. _ = recordOb.Create()
  468. }()
  469. br.Ret = 200
  470. br.Success = true
  471. br.Msg = "操作成功"
  472. br.Data = resp
  473. }
  474. // Edit
  475. // @Title 编辑商家
  476. // @Description 编辑商家
  477. // @Param request body eta_business.EtaBusinessEditReq true "type json string"
  478. // @Success 200 Ret=200 操作成功
  479. // @router /edit [post]
  480. func (this *EtaBusinessController) Edit() {
  481. br := new(models.BaseResponse).Init()
  482. defer func() {
  483. if br.ErrMsg == "" {
  484. br.IsSendEmail = false
  485. }
  486. this.Data["json"] = br
  487. this.ServeJSON()
  488. }()
  489. sysUser := this.SysUser
  490. if sysUser == nil {
  491. br.Msg = "请登录"
  492. br.ErrMsg = "请登录,SysUser Is Empty"
  493. br.Ret = 408
  494. return
  495. }
  496. var req eta_business.EtaBusinessEditReq
  497. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  498. br.Msg = "参数解析异常!"
  499. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  500. return
  501. }
  502. if req.EtaBusinessId <= 0 {
  503. br.Msg = "参数有误"
  504. br.ErrMsg = "参数有误, 商家ID为空"
  505. return
  506. }
  507. if req.Nation == "" {
  508. req.Province = strings.TrimSpace(req.Province)
  509. if req.Province == "" {
  510. br.Msg = "省份不可为空"
  511. return
  512. }
  513. req.City = strings.TrimSpace(req.City)
  514. if req.City == "" {
  515. br.Msg = "城市不可为空"
  516. return
  517. }
  518. }
  519. req.Leader = strings.TrimSpace(req.Leader)
  520. if req.Leader == "" {
  521. br.Msg = "决策人不可为空"
  522. return
  523. }
  524. if req.IndustryId <= 0 || req.IndustryName == "" {
  525. br.Msg = "所属行业不可为空"
  526. return
  527. }
  528. if req.ResearchTeamSize == "" {
  529. br.Msg = "研究团队规模不可为空"
  530. return
  531. }
  532. /*if req.UserMax <= 0 {
  533. br.Msg = "用户上限不可小于0"
  534. return
  535. }*/
  536. req.CapitalScale = strings.TrimSpace(req.CapitalScale)
  537. // 权限校验
  538. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  539. if e != nil {
  540. br.Msg = "操作失败"
  541. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  542. return
  543. }
  544. if !ok {
  545. br.Msg = "无权操作"
  546. return
  547. }
  548. ob := new(eta_business.EtaBusiness)
  549. item, e := ob.GetItemById(req.EtaBusinessId)
  550. if e != nil {
  551. if e.Error() == utils.ErrNoRow() {
  552. br.Msg = "商家不存在, 请刷新页面"
  553. return
  554. }
  555. br.Msg = "操作失败"
  556. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  557. return
  558. }
  559. item.Province = req.Province
  560. item.City = req.City
  561. item.Address = req.Province + req.City
  562. item.Leader = req.Leader
  563. item.IndustryId = req.IndustryId
  564. item.IndustryName = req.IndustryName
  565. item.CapitalScale = req.CapitalScale
  566. item.ResearchTeamSize = req.ResearchTeamSize
  567. //item.UserMax = req.UserMax
  568. item.Nation = req.Nation
  569. item.ModifyTime = time.Now().Local()
  570. cols := []string{
  571. "Province", "City", "Address", "Leader", "IndustryId", "IndustryName", "CapitalScale", "ResearchTeamSize", "ModifyTime",
  572. }
  573. if e := item.Update(cols); e != nil {
  574. br.Msg = "操作失败"
  575. br.ErrMsg = "编辑商家失败, Err: " + e.Error()
  576. return
  577. }
  578. // 操作日志
  579. go func() {
  580. recordOb := new(eta_business.EtaBusinessOperationRecord)
  581. recordOb.EtaBusinessId = item.EtaBusinessId
  582. recordOb.SellerId = item.SellerId
  583. recordOb.SysUserId = sysUser.AdminId
  584. recordOb.SysRealName = sysUser.RealName
  585. recordOb.OperationType = eta_business.EtaBusinessOperationTypeEdit
  586. recordOb.OperationRemark = fmt.Sprintf("%s编辑商户", sysUser.RealName)
  587. recordOb.CreateTime = time.Now().Local()
  588. _ = recordOb.Create()
  589. }()
  590. br.Ret = 200
  591. br.Success = true
  592. br.Msg = "操作成功"
  593. }
  594. // Signing
  595. // @Title 签约续约
  596. // @Description 签约续约(业务上仅用于续约, 兼容首次签约)
  597. // @Param request body eta_business.EtaBusinessSigningReq true "type json string"
  598. // @Success 200 Ret=200 操作成功
  599. // @router /signing [post]
  600. func (this *EtaBusinessController) Signing() {
  601. br := new(models.BaseResponse).Init()
  602. defer func() {
  603. if br.ErrMsg == "" {
  604. br.IsSendEmail = false
  605. }
  606. this.Data["json"] = br
  607. this.ServeJSON()
  608. }()
  609. sysUser := this.SysUser
  610. if sysUser == nil {
  611. br.Msg = "请登录"
  612. br.ErrMsg = "请登录,SysUser Is Empty"
  613. br.Ret = 408
  614. return
  615. }
  616. var req eta_business.EtaBusinessSigningReq
  617. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  618. br.Msg = "参数解析异常!"
  619. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  620. return
  621. }
  622. if req.EtaBusinessId <= 0 {
  623. br.Msg = "参数有误"
  624. br.ErrMsg = "参数有误, 商家ID为空"
  625. return
  626. }
  627. if req.SigningTime == "" {
  628. br.Msg = "签约时间不可为空"
  629. return
  630. }
  631. if req.ExpiredTime == "" {
  632. br.Msg = "到期时间不可为空"
  633. return
  634. }
  635. signTime, e := time.ParseInLocation(utils.FormatDate, req.SigningTime, time.Local)
  636. if e != nil {
  637. br.Msg = "签约时间格式有误"
  638. br.ErrMsg = "签约时间格式有误, Err: " + e.Error()
  639. return
  640. }
  641. expiredTime, e := time.ParseInLocation(utils.FormatDate, req.ExpiredTime, time.Local)
  642. if e != nil {
  643. br.Msg = "到期时间格式有误"
  644. br.ErrMsg = "到期时间格式有误, Err: " + e.Error()
  645. return
  646. }
  647. if !expiredTime.After(signTime) {
  648. br.Msg = "到期时间不得早于签约时间"
  649. return
  650. }
  651. // 权限校验
  652. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  653. if e != nil {
  654. br.Msg = "操作失败"
  655. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  656. return
  657. }
  658. if !ok {
  659. br.Msg = "无权操作"
  660. return
  661. }
  662. // 获取商家信息
  663. businessOb := new(eta_business.EtaBusiness)
  664. business, e := businessOb.GetItemById(req.EtaBusinessId)
  665. if e != nil {
  666. if e.Error() == utils.ErrNoRow() {
  667. br.Msg = "商家不存在, 请刷新页面"
  668. return
  669. }
  670. br.Msg = "操作失败"
  671. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  672. return
  673. }
  674. // 续约不可早于当前生效合约的到期时间
  675. if business.ContractId > 0 {
  676. {
  677. ob := new(eta_business.EtaBusinessContract)
  678. item, e := ob.GetItemById(business.ContractId)
  679. if e != nil {
  680. br.Msg = "操作失败"
  681. br.ErrMsg = "获取商家当前合同失败, Err: " + e.Error()
  682. return
  683. }
  684. if !signTime.After(item.ExpiredTime) {
  685. br.Msg = "签约时间不可早于当前合同的到期时间"
  686. return
  687. }
  688. }
  689. }
  690. // 获取历史签约, 签约日期不可交叠
  691. contract := new(eta_business.EtaBusinessContract)
  692. cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessContractColumns.EtaBusinessId)
  693. pars := make([]interface{}, 0)
  694. pars = append(pars, req.EtaBusinessId)
  695. contracts, e := contract.GetItemsByCondition(cond, pars, []string{}, "signing_time ASC")
  696. if e != nil {
  697. br.Msg = "操作失败"
  698. br.ErrMsg = "获取商家签约列表失败, Err: " + e.Error()
  699. return
  700. }
  701. // 校验签约时间是否重叠
  702. isFirst := true // 是否为首次签约
  703. changeFirst := false // 是否需要更新首次签约合同
  704. if len(contracts) > 0 {
  705. isFirst = false
  706. for k, c := range contracts {
  707. pass := false
  708. if expiredTime.Before(c.SigningTime) {
  709. pass = true
  710. }
  711. if signTime.After(c.ExpiredTime) {
  712. pass = true
  713. }
  714. if !pass {
  715. br.Msg = "签约时间在存续期内, 请检查"
  716. return
  717. }
  718. // 若该合同签约时间早于第一份合同(业务上未限制所以可能会出现这种情况, contracts已排序), 则更新为首次签约合同
  719. if k == 0 && signTime.Before(c.SigningTime) {
  720. changeFirst = true
  721. isFirst = true
  722. }
  723. }
  724. }
  725. // 新增签约
  726. contract.EtaBusinessId = req.EtaBusinessId
  727. contract.SigningTime = signTime
  728. contract.ExpiredTime = expiredTime
  729. contract.CreateTime = time.Now().Local()
  730. contract.ModifyTime = time.Now().Local()
  731. if isFirst {
  732. contract.IsFirst = 1
  733. }
  734. if e = contract.CreateMaybeUpdateFirst(contract, changeFirst); e != nil {
  735. br.Msg = "操作失败"
  736. br.ErrMsg = "新增签约失败, Err: " + e.Error()
  737. return
  738. }
  739. // 签约后续操作
  740. go func() {
  741. _ = etaBusinessService.UpdateEtaBusinessAfterSigning(business.EtaBusinessId)
  742. }()
  743. // 续约操作日志
  744. if !isFirst {
  745. go func() {
  746. recordOb := new(eta_business.EtaBusinessOperationRecord)
  747. recordOb.EtaBusinessId = business.EtaBusinessId
  748. recordOb.SellerId = business.SellerId
  749. recordOb.SysUserId = sysUser.AdminId
  750. recordOb.SysRealName = sysUser.RealName
  751. recordOb.OperationType = eta_business.EtaBusinessOperationTypeRenewalContract
  752. recordOb.OperationRemark = fmt.Sprintf("%s添加续约", sysUser.RealName)
  753. recordOb.CreateTime = time.Now().Local()
  754. _ = recordOb.Create()
  755. }()
  756. }
  757. br.Ret = 200
  758. br.Success = true
  759. br.Msg = "操作成功"
  760. }
  761. // Enable
  762. // @Title 禁用启用
  763. // @Description 禁用启用
  764. // @Param request body eta_business.EtaBusinessEnableReq true "type json string"
  765. // @Success 200 Ret=200 操作成功
  766. // @router /enable [post]
  767. func (this *EtaBusinessController) Enable() {
  768. br := new(models.BaseResponse).Init()
  769. defer func() {
  770. if br.ErrMsg == "" {
  771. br.IsSendEmail = false
  772. }
  773. this.Data["json"] = br
  774. this.ServeJSON()
  775. }()
  776. sysUser := this.SysUser
  777. if sysUser == nil {
  778. br.Msg = "请登录"
  779. br.ErrMsg = "请登录,SysUser Is Empty"
  780. br.Ret = 408
  781. return
  782. }
  783. var req eta_business.EtaBusinessEnableReq
  784. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  785. br.Msg = "参数解析异常!"
  786. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  787. return
  788. }
  789. if req.EtaBusinessId <= 0 {
  790. br.Msg = "参数有误"
  791. br.ErrMsg = "参数有误, 商家ID为空"
  792. return
  793. }
  794. // 权限校验
  795. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  796. if e != nil {
  797. br.Msg = "操作失败"
  798. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  799. return
  800. }
  801. if !ok {
  802. br.Msg = "无权操作"
  803. return
  804. }
  805. // 获取商家信息
  806. businessOb := new(eta_business.EtaBusiness)
  807. business, e := businessOb.GetItemById(req.EtaBusinessId)
  808. if e != nil {
  809. if e.Error() == utils.ErrNoRow() {
  810. br.Msg = "商家不存在, 请刷新页面"
  811. return
  812. }
  813. br.Msg = "操作失败"
  814. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  815. return
  816. }
  817. // 禁启用
  818. typeMap := map[int]int{
  819. 0: eta_business.EtaBusinessOperationTypeEnable,
  820. 1: eta_business.EtaBusinessOperationTypeDisable,
  821. }
  822. typeRemarkMap := map[int]string{
  823. 0: "启用",
  824. 1: "禁用",
  825. }
  826. operateType := typeMap[business.Enable]
  827. operateRemark := typeRemarkMap[business.Enable]
  828. business.Enable = business.Enable ^ 1
  829. business.ModifyTime = time.Now().Local()
  830. cols := []string{"Enable", "ModifyTime"}
  831. if e = business.Update(cols); e != nil {
  832. br.Msg = "操作失败"
  833. br.ErrMsg = "更新商家状态失败, Err: " + e.Error()
  834. return
  835. }
  836. // 操作日志
  837. go func() {
  838. recordOb := new(eta_business.EtaBusinessOperationRecord)
  839. recordOb.EtaBusinessId = business.EtaBusinessId
  840. recordOb.SellerId = business.SellerId
  841. recordOb.SysUserId = sysUser.AdminId
  842. recordOb.SysRealName = sysUser.RealName
  843. recordOb.OperationType = operateType
  844. recordOb.OperationRemark = fmt.Sprintf("%s%s商户", sysUser.RealName, operateRemark)
  845. recordOb.CreateTime = time.Now().Local()
  846. _ = recordOb.Create()
  847. }()
  848. br.Ret = 200
  849. br.Success = true
  850. br.Msg = "操作成功"
  851. }
  852. // MoveSeller
  853. // @Title 移动销售
  854. // @Description 移动销售
  855. // @Param request body eta_business.EtaBusinessMoveSellerReq true "type json string"
  856. // @Success 200 Ret=200 操作成功
  857. // @router /move_seller [post]
  858. func (this *EtaBusinessController) MoveSeller() {
  859. br := new(models.BaseResponse).Init()
  860. defer func() {
  861. if br.ErrMsg == "" {
  862. br.IsSendEmail = false
  863. }
  864. this.Data["json"] = br
  865. this.ServeJSON()
  866. }()
  867. sysUser := this.SysUser
  868. if sysUser == nil {
  869. br.Msg = "请登录"
  870. br.ErrMsg = "请登录,SysUser Is Empty"
  871. br.Ret = 408
  872. return
  873. }
  874. var req eta_business.EtaBusinessMoveSellerReq
  875. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  876. br.Msg = "参数解析异常!"
  877. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  878. return
  879. }
  880. if req.EtaBusinessId <= 0 {
  881. br.Msg = "参数有误"
  882. br.ErrMsg = "参数有误, 商家ID为空"
  883. return
  884. }
  885. if req.SellerId <= 0 || req.SellerName == "" {
  886. br.Msg = "销售不可为空"
  887. return
  888. }
  889. // 权限校验
  890. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  891. if e != nil {
  892. br.Msg = "操作失败"
  893. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  894. return
  895. }
  896. if !ok {
  897. br.Msg = "无权操作"
  898. return
  899. }
  900. // 获取商家信息
  901. businessOb := new(eta_business.EtaBusiness)
  902. business, e := businessOb.GetItemById(req.EtaBusinessId)
  903. if e != nil {
  904. if e.Error() == utils.ErrNoRow() {
  905. br.Msg = "商家不存在, 请刷新页面"
  906. return
  907. }
  908. br.Msg = "操作失败"
  909. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  910. return
  911. }
  912. // 更新销售
  913. business.SellerId = req.SellerId
  914. business.SellerName = req.SellerName
  915. business.ModifyTime = time.Now().Local()
  916. cols := []string{"SellerId", "SellerName", "ModifyTime"}
  917. if e = business.Update(cols); e != nil {
  918. br.Msg = "操作失败"
  919. br.ErrMsg = "移动至销售失败, Err: " + e.Error()
  920. return
  921. }
  922. // 操作日志
  923. go func() {
  924. recordOb := new(eta_business.EtaBusinessOperationRecord)
  925. recordOb.EtaBusinessId = business.EtaBusinessId
  926. recordOb.SellerId = req.SellerId
  927. recordOb.SysUserId = sysUser.AdminId
  928. recordOb.SysRealName = sysUser.RealName
  929. recordOb.OperationType = eta_business.EtaBusinessOperationTypeMoveSeller
  930. recordOb.OperationRemark = fmt.Sprintf("%s移动到: %s", sysUser.RealName, req.SellerName)
  931. recordOb.CreateTime = time.Now().Local()
  932. _ = recordOb.Create()
  933. }()
  934. br.Ret = 200
  935. br.Success = true
  936. br.Msg = "操作成功"
  937. }
  938. // Detail
  939. // @Title 商家详情
  940. // @Description 商家详情
  941. // @Param EtaBusinessId query int true "商家ID"
  942. // @Success 200 Ret=200 获取成功
  943. // @router /detail [get]
  944. func (this *EtaBusinessController) Detail() {
  945. br := new(models.BaseResponse).Init()
  946. defer func() {
  947. if br.ErrMsg == "" {
  948. br.IsSendEmail = false
  949. }
  950. this.Data["json"] = br
  951. this.ServeJSON()
  952. }()
  953. sysUser := this.SysUser
  954. if sysUser == nil {
  955. br.Msg = "请登录"
  956. br.ErrMsg = "请登录,SysUser Is Empty"
  957. br.Ret = 408
  958. return
  959. }
  960. // 权限校验
  961. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  962. if e != nil {
  963. br.Msg = "获取失败"
  964. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  965. return
  966. }
  967. if !ok {
  968. br.Ret = 200
  969. br.Success = true
  970. br.Msg = "获取成功"
  971. return
  972. }
  973. businessId, _ := this.GetInt("EtaBusinessId", 0)
  974. if businessId <= 0 {
  975. br.Msg = "参数有误"
  976. br.ErrMsg = "参数有误, 商家ID"
  977. return
  978. }
  979. businessOb := new(eta_business.EtaBusiness)
  980. item, e := businessOb.GetItemById(businessId)
  981. if e != nil {
  982. if e.Error() == utils.ErrNoRow() {
  983. br.Msg = "商家不存在, 请刷新页面"
  984. return
  985. }
  986. br.Msg = "获取失败"
  987. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  988. return
  989. }
  990. resp := new(eta_business.EtaBusinessItem)
  991. resp.EtaBusinessId = item.EtaBusinessId
  992. resp.BusinessName = item.BusinessName
  993. resp.BusinessCode = item.BusinessCode
  994. resp.CreditCode = item.CreditCode
  995. resp.RegionType = item.RegionType
  996. resp.Province = item.Province
  997. resp.City = item.City
  998. resp.Address = item.Address
  999. resp.SellerId = item.SellerId
  1000. resp.SellerName = item.SellerName
  1001. resp.Leader = item.Leader
  1002. resp.IndustryId = item.IndustryId
  1003. resp.IndustryName = item.IndustryName
  1004. resp.CapitalScale = item.CapitalScale
  1005. resp.ResearchTeamSize = item.ResearchTeamSize
  1006. resp.UserMax = item.UserMax
  1007. resp.SigningStatus = item.SigningStatus
  1008. resp.Enable = item.Enable
  1009. resp.ContractId = item.ContractId
  1010. resp.SigningTime = utils.TimeTransferString(utils.FormatDate, item.SigningTime)
  1011. resp.ExpiredTime = utils.TimeTransferString(utils.FormatDate, item.ExpiredTime)
  1012. resp.CreateTime = item.CreateTime.Format(utils.FormatDateTime)
  1013. resp.ModifyTime = item.ModifyTime.Format(utils.FormatDateTime)
  1014. resp.Nation = item.Nation
  1015. br.Data = resp
  1016. br.Ret = 200
  1017. br.Success = true
  1018. br.Msg = "获取成功"
  1019. }
  1020. // ContractList
  1021. // @Title 商家签约列表
  1022. // @Description 商家签约列表
  1023. // @Param EtaBusinessId query int true "商家ID"
  1024. // @Success 200 Ret=200 获取成功
  1025. // @router /contract_list [get]
  1026. func (this *EtaBusinessController) ContractList() {
  1027. br := new(models.BaseResponse).Init()
  1028. defer func() {
  1029. if br.ErrMsg == "" {
  1030. br.IsSendEmail = false
  1031. }
  1032. this.Data["json"] = br
  1033. this.ServeJSON()
  1034. }()
  1035. sysUser := this.SysUser
  1036. if sysUser == nil {
  1037. br.Msg = "请登录"
  1038. br.ErrMsg = "请登录,SysUser Is Empty"
  1039. br.Ret = 408
  1040. return
  1041. }
  1042. // 权限校验
  1043. resp := make([]*eta_business.EtaBusinessContractItem, 0)
  1044. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1045. if e != nil {
  1046. br.Msg = "操作失败"
  1047. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1048. return
  1049. }
  1050. if !ok {
  1051. br.Data = resp
  1052. br.Ret = 200
  1053. br.Success = true
  1054. br.Msg = "获取成功"
  1055. return
  1056. }
  1057. businessId, _ := this.GetInt("EtaBusinessId", 0)
  1058. if businessId <= 0 {
  1059. br.Msg = "参数有误"
  1060. br.ErrMsg = "参数有误, 商家ID"
  1061. return
  1062. }
  1063. cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessContractColumns.EtaBusinessId)
  1064. pars := make([]interface{}, 0)
  1065. pars = append(pars, businessId)
  1066. order := `signing_time ASC`
  1067. contractOb := new(eta_business.EtaBusinessContract)
  1068. list, e := contractOb.GetItemsByCondition(cond, pars, []string{}, order)
  1069. if e != nil {
  1070. br.Msg = "获取失败"
  1071. br.ErrMsg = "获取商家签约列表失败, Err: " + e.Error()
  1072. return
  1073. }
  1074. now := time.Now().Local()
  1075. for _, v := range list {
  1076. b := new(eta_business.EtaBusinessContractItem)
  1077. b.EtaBusinessContractId = v.EtaBusinessContractId
  1078. b.EtaBusinessId = v.EtaBusinessId
  1079. b.SigningTime = utils.TimeTransferString(utils.FormatDate, v.SigningTime)
  1080. b.ExpiredTime = utils.TimeTransferString(utils.FormatDate, v.ExpiredTime)
  1081. // 到期天数, 终止日按当天的23:59:59算
  1082. strEnd := v.ExpiredTime.Format(utils.FormatDate)
  1083. strEnd = strEnd + " 23:59:59"
  1084. endTime, e := time.ParseInLocation(utils.FormatDateTime, strEnd, time.Local)
  1085. if e != nil {
  1086. br.Msg = "获取失败"
  1087. br.ErrMsg = "签约日期有误, Err: " + e.Error()
  1088. return
  1089. }
  1090. b.ExpireDay = "-"
  1091. if now.After(v.SigningTime) && now.Before(endTime) {
  1092. diff := utils.GetDiffDays(v.ExpiredTime, now)
  1093. b.ExpireDay = strconv.Itoa(diff)
  1094. b.Using = true
  1095. }
  1096. resp = append(resp, b)
  1097. }
  1098. br.Data = resp
  1099. br.Ret = 200
  1100. br.Success = true
  1101. br.Msg = "获取成功"
  1102. }
  1103. // OperateRecordList
  1104. // @Title 操作日志列表
  1105. // @Description 操作日志列表
  1106. // @Param EtaBusinessId query int true "商家ID"
  1107. // @Success 200 Ret=200 获取成功
  1108. // @router /operate_record_list [get]
  1109. func (this *EtaBusinessController) OperateRecordList() {
  1110. br := new(models.BaseResponse).Init()
  1111. defer func() {
  1112. if br.ErrMsg == "" {
  1113. br.IsSendEmail = false
  1114. }
  1115. this.Data["json"] = br
  1116. this.ServeJSON()
  1117. }()
  1118. sysUser := this.SysUser
  1119. if sysUser == nil {
  1120. br.Msg = "请登录"
  1121. br.ErrMsg = "请登录,SysUser Is Empty"
  1122. br.Ret = 408
  1123. return
  1124. }
  1125. // 权限校验
  1126. resp := make([]*eta_business.EtaBusinessOperationRecordItem, 0)
  1127. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1128. if e != nil {
  1129. br.Msg = "操作失败"
  1130. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1131. return
  1132. }
  1133. if !ok {
  1134. br.Data = resp
  1135. br.Ret = 200
  1136. br.Success = true
  1137. br.Msg = "获取成功"
  1138. return
  1139. }
  1140. businessId, _ := this.GetInt("EtaBusinessId", 0)
  1141. if businessId <= 0 {
  1142. br.Msg = "参数有误"
  1143. br.ErrMsg = "参数有误, 商家ID"
  1144. return
  1145. }
  1146. cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessOperationRecordColumns.EtaBusinessId)
  1147. pars := make([]interface{}, 0)
  1148. pars = append(pars, businessId)
  1149. recordOb := new(eta_business.EtaBusinessOperationRecord)
  1150. list, e := recordOb.GetItemsByCondition(cond, pars, []string{}, "")
  1151. if e != nil {
  1152. br.Msg = "获取失败"
  1153. br.ErrMsg = "获取商家操作日志列表失败, Err: " + e.Error()
  1154. return
  1155. }
  1156. for _, v := range list {
  1157. r := new(eta_business.EtaBusinessOperationRecordItem)
  1158. r.EtaBusinessId = v.EtaBusinessId
  1159. r.SysUserId = v.SysUserId
  1160. r.SysRealName = v.SysRealName
  1161. r.OperationType = v.OperationType
  1162. r.OperationRemark = v.OperationRemark
  1163. r.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  1164. resp = append(resp, r)
  1165. }
  1166. br.Data = resp
  1167. br.Ret = 200
  1168. br.Success = true
  1169. br.Msg = "获取成功"
  1170. }
  1171. // EditSign
  1172. // @Title 编辑签约
  1173. // @Description 编辑签约
  1174. // @Param request body eta_business.EtaBusinessEditSignReq true "type json string"
  1175. // @Success 200 Ret=200 操作成功
  1176. // @router /edit_sign [post]
  1177. func (this *EtaBusinessController) EditSign() {
  1178. br := new(models.BaseResponse).Init()
  1179. defer func() {
  1180. if br.ErrMsg == "" {
  1181. br.IsSendEmail = false
  1182. }
  1183. this.Data["json"] = br
  1184. this.ServeJSON()
  1185. }()
  1186. sysUser := this.SysUser
  1187. if sysUser == nil {
  1188. br.Msg = "请登录"
  1189. br.ErrMsg = "请登录,SysUser Is Empty"
  1190. br.Ret = 408
  1191. return
  1192. }
  1193. var req eta_business.EtaBusinessEditSignReq
  1194. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1195. br.Msg = "参数解析异常!"
  1196. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1197. return
  1198. }
  1199. if req.EtaBusinessContractId <= 0 {
  1200. br.Msg = "参数有误"
  1201. br.ErrMsg = "参数有误, 商家签约ID为空"
  1202. return
  1203. }
  1204. if req.SigningTime == "" {
  1205. br.Msg = "签约时间不可为空"
  1206. return
  1207. }
  1208. if req.ExpiredTime == "" {
  1209. br.Msg = "到期时间不可为空"
  1210. return
  1211. }
  1212. signTime, e := time.ParseInLocation(utils.FormatDate, req.SigningTime, time.Local)
  1213. if e != nil {
  1214. br.Msg = "签约时间格式有误"
  1215. br.ErrMsg = "签约时间格式有误, Err: " + e.Error()
  1216. return
  1217. }
  1218. expiredTime, e := time.ParseInLocation(utils.FormatDate, req.ExpiredTime, time.Local)
  1219. if e != nil {
  1220. br.Msg = "到期时间格式有误"
  1221. br.ErrMsg = "到期时间格式有误, Err: " + e.Error()
  1222. return
  1223. }
  1224. if !expiredTime.After(signTime) {
  1225. br.Msg = "到期时间不得早于签约时间"
  1226. return
  1227. }
  1228. // 权限校验
  1229. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1230. if e != nil {
  1231. br.Msg = "操作失败"
  1232. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1233. return
  1234. }
  1235. if !ok {
  1236. br.Msg = "无权操作"
  1237. return
  1238. }
  1239. contractOb := new(eta_business.EtaBusinessContract)
  1240. contract, e := contractOb.GetItemById(req.EtaBusinessContractId)
  1241. if e != nil {
  1242. if e.Error() == utils.ErrNoRow() {
  1243. br.Msg = "签约信息不存在, 请刷新页面"
  1244. return
  1245. }
  1246. br.Msg = "操作失败"
  1247. br.ErrMsg = "获取商家签约信息失败, Err: " + e.Error()
  1248. return
  1249. }
  1250. businessOb := new(eta_business.EtaBusiness)
  1251. business, e := businessOb.GetItemById(contract.EtaBusinessId)
  1252. if e != nil {
  1253. if e.Error() == utils.ErrNoRow() {
  1254. br.Msg = "商家不存在, 请刷新页面"
  1255. return
  1256. }
  1257. br.Msg = "操作失败"
  1258. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  1259. return
  1260. }
  1261. // 续约不可早于当前生效合约的到期时间
  1262. if business.ContractId > 0 && business.ContractId != req.EtaBusinessContractId {
  1263. {
  1264. ob := new(eta_business.EtaBusinessContract)
  1265. item, e := ob.GetItemById(business.ContractId)
  1266. if e != nil {
  1267. br.Msg = "操作失败"
  1268. br.ErrMsg = "获取商家当前合同失败, Err: " + e.Error()
  1269. return
  1270. }
  1271. if !signTime.After(item.ExpiredTime) {
  1272. br.Msg = "签约时间不可早于当前合同的到期时间"
  1273. return
  1274. }
  1275. }
  1276. }
  1277. // 获取历史签约, 签约日期不可交叠
  1278. cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessContractColumns.EtaBusinessId)
  1279. pars := make([]interface{}, 0)
  1280. pars = append(pars, contract.EtaBusinessId)
  1281. contracts, e := contractOb.GetItemsByCondition(cond, pars, []string{}, "signing_time ASC")
  1282. if e != nil {
  1283. br.Msg = "操作失败"
  1284. br.ErrMsg = "获取商家签约列表失败, Err: " + e.Error()
  1285. return
  1286. }
  1287. // 校验签约时间是否重叠
  1288. isFirst := true // 是否为首次签约
  1289. changeFirst := false // 是否需要更新首次签约合同
  1290. if len(contracts) > 0 {
  1291. isFirst = false
  1292. for k, c := range contracts {
  1293. if c.EtaBusinessContractId == req.EtaBusinessContractId {
  1294. continue
  1295. }
  1296. pass := false
  1297. if expiredTime.Before(c.SigningTime) {
  1298. pass = true
  1299. }
  1300. if signTime.After(c.ExpiredTime) {
  1301. pass = true
  1302. }
  1303. if !pass {
  1304. br.Msg = "签约时间在存续期内, 请检查"
  1305. return
  1306. }
  1307. // 若该合同签约时间早于第一份合同(业务上未限制所以可能会出现这种情况, contracts已排序), 则更新为首次签约合同
  1308. if k == 0 && signTime.Before(c.SigningTime) {
  1309. changeFirst = true
  1310. isFirst = true
  1311. }
  1312. }
  1313. }
  1314. // 新增签约
  1315. contract.SigningTime = signTime
  1316. contract.ExpiredTime = expiredTime
  1317. contract.ModifyTime = time.Now().Local()
  1318. if isFirst {
  1319. contract.IsFirst = 1
  1320. }
  1321. updateCols := []string{"SigningTime", "ExpiredTime", "ModifyTime"}
  1322. if e = contract.UpdateMaybeUpdateFirst(contract, changeFirst, updateCols); e != nil {
  1323. br.Msg = "操作失败"
  1324. br.ErrMsg = "编辑签约失败, Err: " + e.Error()
  1325. return
  1326. }
  1327. // 签约后续操作
  1328. go func() {
  1329. _ = etaBusinessService.UpdateEtaBusinessAfterSigning(business.EtaBusinessId)
  1330. }()
  1331. // 续约操作日志
  1332. if !isFirst {
  1333. go func() {
  1334. recordOb := new(eta_business.EtaBusinessOperationRecord)
  1335. recordOb.EtaBusinessId = business.EtaBusinessId
  1336. recordOb.SellerId = business.SellerId
  1337. recordOb.SysUserId = sysUser.AdminId
  1338. recordOb.SysRealName = sysUser.RealName
  1339. recordOb.OperationType = eta_business.EtaBusinessOperationTypeEditContract
  1340. recordOb.OperationRemark = fmt.Sprintf("%s编辑续约", sysUser.RealName)
  1341. recordOb.CreateTime = time.Now().Local()
  1342. _ = recordOb.Create()
  1343. }()
  1344. }
  1345. br.Ret = 200
  1346. br.Success = true
  1347. br.Msg = "操作成功"
  1348. }
  1349. // RemoveSign
  1350. // @Title 删除签约
  1351. // @Description 删除签约
  1352. // @Param request body eta_business.EtaBusinessRemoveSignReq true "type json string"
  1353. // @Success 200 Ret=200 操作成功
  1354. // @router /remove_sign [post]
  1355. func (this *EtaBusinessController) RemoveSign() {
  1356. br := new(models.BaseResponse).Init()
  1357. defer func() {
  1358. if br.ErrMsg == "" {
  1359. br.IsSendEmail = false
  1360. }
  1361. this.Data["json"] = br
  1362. this.ServeJSON()
  1363. }()
  1364. sysUser := this.SysUser
  1365. if sysUser == nil {
  1366. br.Msg = "请登录"
  1367. br.ErrMsg = "请登录,SysUser Is Empty"
  1368. br.Ret = 408
  1369. return
  1370. }
  1371. var req eta_business.EtaBusinessRemoveSignReq
  1372. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1373. br.Msg = "参数解析异常!"
  1374. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1375. return
  1376. }
  1377. if req.EtaBusinessContractId <= 0 {
  1378. br.Msg = "参数有误"
  1379. br.ErrMsg = "参数有误, 商家签约ID为空"
  1380. return
  1381. }
  1382. // 权限校验
  1383. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1384. if e != nil {
  1385. br.Msg = "操作失败"
  1386. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1387. return
  1388. }
  1389. if !ok {
  1390. br.Msg = "无权操作"
  1391. return
  1392. }
  1393. // 获取商家信息
  1394. contractOb := new(eta_business.EtaBusinessContract)
  1395. contract, e := contractOb.GetItemById(req.EtaBusinessContractId)
  1396. if e != nil {
  1397. if e.Error() == utils.ErrNoRow() {
  1398. br.Msg = "签约信息不存在, 请刷新页面"
  1399. return
  1400. }
  1401. br.Msg = "操作失败"
  1402. br.ErrMsg = "获取商家签约信息失败, Err: " + e.Error()
  1403. return
  1404. }
  1405. // 获取商家信息
  1406. businessOb := new(eta_business.EtaBusiness)
  1407. business, e := businessOb.GetItemById(contract.EtaBusinessId)
  1408. if e != nil {
  1409. if e.Error() == utils.ErrNoRow() {
  1410. br.Msg = "商家不存在, 请检查"
  1411. return
  1412. }
  1413. br.Msg = "操作失败"
  1414. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  1415. return
  1416. }
  1417. // 删除签约
  1418. if e = contract.Del(); e != nil {
  1419. br.Msg = "操作失败"
  1420. br.ErrMsg = "删除签约失败, Err: " + e.Error()
  1421. return
  1422. }
  1423. // 签约后续操作
  1424. go func() {
  1425. _ = etaBusinessService.UpdateEtaBusinessAfterSigning(business.EtaBusinessId)
  1426. }()
  1427. // 操作日志
  1428. go func() {
  1429. recordOb := new(eta_business.EtaBusinessOperationRecord)
  1430. recordOb.EtaBusinessId = business.EtaBusinessId
  1431. recordOb.SellerId = business.SellerId
  1432. recordOb.SysUserId = sysUser.AdminId
  1433. recordOb.SysRealName = sysUser.RealName
  1434. recordOb.OperationType = eta_business.EtaBusinessOperationTypeRemoveContract
  1435. recordOb.OperationRemark = fmt.Sprintf("%s删除签约", sysUser.RealName)
  1436. recordOb.CreateTime = time.Now().Local()
  1437. _ = recordOb.Create()
  1438. }()
  1439. br.Ret = 200
  1440. br.Success = true
  1441. br.Msg = "操作成功"
  1442. }
  1443. // @Title 设置社区图表分类权限
  1444. // @Description 设置社区图表分类权限
  1445. // @Param request body eta_business.AddBusinessChartClassifyPermissionReq true "type json string"
  1446. // @Success 200 {object} system.SysRoleListResp
  1447. // @router /add_chart_permission [post]
  1448. func (this *EtaBusinessController) AddChartPermission() {
  1449. br := new(models.BaseResponse).Init()
  1450. defer func() {
  1451. this.Data["json"] = br
  1452. this.ServeJSON()
  1453. }()
  1454. sysUser := this.SysUser
  1455. if sysUser == nil {
  1456. br.Msg = "请登录"
  1457. br.ErrMsg = "请登录,SysUser Is Empty"
  1458. return
  1459. }
  1460. var req eta_business.AddBusinessChartClassifyPermissionReq
  1461. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1462. if err != nil {
  1463. br.Msg = "参数解析异常!"
  1464. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1465. return
  1466. }
  1467. if req.EtaBusinessId <= 0 {
  1468. br.Msg = "请选择商户"
  1469. return
  1470. }
  1471. // 权限校验
  1472. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1473. if e != nil {
  1474. br.Msg = "操作失败"
  1475. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1476. return
  1477. }
  1478. if !ok {
  1479. br.Msg = "无权操作"
  1480. return
  1481. }
  1482. ob := new(eta_business.EtaBusiness)
  1483. businessInfo, e := ob.GetItemById(req.EtaBusinessId)
  1484. if e != nil {
  1485. if e.Error() == utils.ErrNoRow() {
  1486. br.Msg = "商家不存在, 请刷新页面"
  1487. return
  1488. }
  1489. br.Msg = "获取商家信息失败"
  1490. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  1491. return
  1492. }
  1493. chartClassifyIdArr := strings.Split(req.ChartClassifyIdStr, ",")
  1494. addList := make([]*eta_business.BusinessChartClassifyPermission, 0)
  1495. for _, v := range chartClassifyIdArr {
  1496. if v == "" {
  1497. continue
  1498. }
  1499. classifyId, e := strconv.Atoi(v)
  1500. if e != nil {
  1501. br.Msg = "设置社区权限失败"
  1502. br.ErrMsg = "classifyId 解析失败,Err:" + e.Error()
  1503. return
  1504. }
  1505. //item := new(system.SysRoleMenu)
  1506. item := new(eta_business.BusinessChartClassifyPermission)
  1507. item.ChartClassifyId = classifyId
  1508. item.BusinessCode = businessInfo.BusinessCode
  1509. item.EtaBusinessId = req.EtaBusinessId
  1510. item.CreateTime = time.Now()
  1511. item.ModifyTime = time.Now()
  1512. item.AdminId = sysUser.AdminId
  1513. item.Source = 1
  1514. addList = append(addList, item)
  1515. }
  1516. err = eta_business.AddBusinessChartClassifyPermission(addList, businessInfo.BusinessCode)
  1517. if err != nil {
  1518. br.Msg = "设置社区权限失败"
  1519. br.ErrMsg = "设置社区权限失败,Err:" + err.Error()
  1520. return
  1521. }
  1522. br.Ret = 200
  1523. br.Success = true
  1524. br.IsAddLog = true
  1525. br.Msg = "设置成功"
  1526. }
  1527. // @Title 获取社区图表分类权限
  1528. // @Description 获取社区图表分类权限
  1529. // @Param request body eta_business.AddBusinessChartClassifyPermissionReq true "type json string"
  1530. // @Success 200 {object} system.SysRoleListResp
  1531. // @router /get_chart_permission [get]
  1532. func (this *EtaBusinessController) GetChartPermission() {
  1533. br := new(models.BaseResponse).Init()
  1534. defer func() {
  1535. this.Data["json"] = br
  1536. this.ServeJSON()
  1537. }()
  1538. sysUser := this.SysUser
  1539. if sysUser == nil {
  1540. br.Msg = "请登录"
  1541. br.ErrMsg = "请登录,SysUser Is Empty"
  1542. return
  1543. }
  1544. keyword := this.GetString("Keyword")
  1545. etaBusinessId, _ := this.GetInt("EtaBusinessId")
  1546. if etaBusinessId <= 0 {
  1547. br.Msg = "请选择商户"
  1548. return
  1549. }
  1550. // 权限校验
  1551. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1552. if e != nil {
  1553. br.Msg = "操作失败"
  1554. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1555. return
  1556. }
  1557. if !ok {
  1558. br.Msg = "无权操作"
  1559. return
  1560. }
  1561. ob := new(eta_business.EtaBusiness)
  1562. businessInfo, e := ob.GetItemById(etaBusinessId)
  1563. if e != nil {
  1564. if e.Error() == utils.ErrNoRow() {
  1565. br.Msg = "商家不存在, 请刷新页面"
  1566. return
  1567. }
  1568. br.Msg = "获取商家信息失败"
  1569. br.ErrMsg = "获取商家信息失败, Err: " + e.Error()
  1570. return
  1571. }
  1572. permissionList, err := eta_business.GetBusinessChartClassifyPermission(businessInfo.EtaBusinessId)
  1573. if err != nil {
  1574. br.Msg = "获取社区权限失败"
  1575. br.ErrMsg = "获取社区权限失败,Err:" + err.Error()
  1576. return
  1577. }
  1578. permissionClassifyIdsMap := make(map[int]struct{})
  1579. checkList := make([]int, 0)
  1580. for _, v := range permissionList {
  1581. if _, ok1 := permissionClassifyIdsMap[v.ChartClassifyId]; !ok1 {
  1582. permissionClassifyIdsMap[v.ChartClassifyId] = struct{}{}
  1583. checkList = append(checkList, v.ChartClassifyId)
  1584. }
  1585. }
  1586. allList := make([]*models.ChartClassifyItems, 0)
  1587. keywordClassifyIdMap := make(map[int]struct{})
  1588. keywordClassifyIds := make([]int, 0)
  1589. if keyword != "" {
  1590. keywordList, e := models.GetChartClassifyListByKeyword(keyword)
  1591. if e != nil {
  1592. br.Msg = "获取失败"
  1593. br.ErrMsg = "获取失败,Err:" + e.Error()
  1594. return
  1595. }
  1596. for _, v := range keywordList {
  1597. if _, ok1 := keywordClassifyIdMap[v.ChartClassifyId]; !ok1 {
  1598. keywordClassifyIdMap[v.ChartClassifyId] = struct{}{}
  1599. // 解析当前的父级路径,找到路径下的所有分类
  1600. if v.LevelPath == "" {
  1601. br.Msg = "获取失败"
  1602. br.ErrMsg = "获取失败,Err: 分类的父级路径为空"
  1603. return
  1604. }
  1605. paths := strings.Split(v.LevelPath, ",")
  1606. for _, path := range paths {
  1607. if path != "" {
  1608. pathInt, _ := strconv.Atoi(path)
  1609. if _, ok2 := keywordClassifyIdMap[pathInt]; !ok2 {
  1610. keywordClassifyIdMap[pathInt] = struct{}{}
  1611. }
  1612. }
  1613. }
  1614. }
  1615. }
  1616. for k := range keywordClassifyIdMap {
  1617. keywordClassifyIds = append(keywordClassifyIds, k)
  1618. }
  1619. if len(keywordClassifyIds) > 0 {
  1620. allList, err = models.GetChartClassifyItemsByIdList(keywordClassifyIds)
  1621. if err != nil && err.Error() != utils.ErrNoRow() {
  1622. br.Msg = "获取失败"
  1623. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1624. return
  1625. }
  1626. }
  1627. } else {
  1628. allList, err = models.GetChartClassify()
  1629. if err != nil && err.Error() != utils.ErrNoRow() {
  1630. br.Msg = "获取失败"
  1631. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1632. return
  1633. }
  1634. }
  1635. nodeAll := make([]*models.ChartClassifyItems, 0)
  1636. list := make([]*models.ChartClassifyItems, 0)
  1637. var sortList models.ChartClassifyItemList
  1638. if len(allList) > 0 {
  1639. nodeAll = services.GetClassifyTreeRecursive(allList, 0)
  1640. //根据sort值排序
  1641. sortList = nodeAll
  1642. sort.Sort(sortList)
  1643. }
  1644. list = append(list, sortList...)
  1645. resp := new(models.BusinessChartClassifyResp)
  1646. resp.List = list
  1647. resp.CheckList = checkList
  1648. br.Ret = 200
  1649. br.Success = true
  1650. br.Msg = "获取成功"
  1651. br.Data = resp
  1652. }
  1653. // PageList
  1654. // @Title 商家列表
  1655. // @Description 商家列表
  1656. // @Param Keyword query string false "关键词: 商家名称/社会信用码/商家编码"
  1657. // @Success 200 Ret=200 获取成功
  1658. // @router /list [get]
  1659. func (this *EtaBusinessController) AllList() {
  1660. br := new(models.BaseResponse).Init()
  1661. defer func() {
  1662. if br.ErrMsg == "" {
  1663. br.IsSendEmail = false
  1664. }
  1665. this.Data["json"] = br
  1666. this.ServeJSON()
  1667. }()
  1668. sysUser := this.SysUser
  1669. if sysUser == nil {
  1670. br.Msg = "请登录"
  1671. br.ErrMsg = "请登录,SysUser Is Empty"
  1672. br.Ret = 408
  1673. return
  1674. }
  1675. // 权限校验
  1676. resp := new(eta_business.EtaBusinessAllListResp)
  1677. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1678. if e != nil {
  1679. br.Msg = "操作失败"
  1680. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1681. return
  1682. }
  1683. if !ok {
  1684. resp.List = make([]*eta_business.EtaBusinessItem, 0)
  1685. br.Data = resp
  1686. br.Ret = 200
  1687. br.Success = true
  1688. br.Msg = "获取成功"
  1689. return
  1690. }
  1691. cond := ``
  1692. pars := make([]interface{}, 0)
  1693. // 筛选项
  1694. {
  1695. // 关键词
  1696. keyword := this.GetString("Keyword", "")
  1697. keyword = strings.TrimSpace(keyword)
  1698. if keyword != "" {
  1699. kw := fmt.Sprint("%", keyword, "%")
  1700. cond += fmt.Sprintf(` AND (%s LIKE ? OR %s LIKE ? OR %s LIKE ?)`, eta_business.EtaBusinessColumns.BusinessName, eta_business.EtaBusinessColumns.BusinessCode, eta_business.EtaBusinessColumns.CreditCode)
  1701. pars = append(pars, kw, kw, kw)
  1702. }
  1703. }
  1704. order := ``
  1705. // 排序
  1706. {
  1707. fieldArr := []int{1, 2, 3, 4}
  1708. typeArr := []int{1, 2}
  1709. fieldMap := map[int]string{
  1710. 1: "signing_time",
  1711. 2: "expired_time",
  1712. 3: "create_time",
  1713. 4: "user_max",
  1714. }
  1715. typeMap := map[int]string{
  1716. 1: "ASC",
  1717. 2: "DESC",
  1718. }
  1719. sortParam, _ := this.GetInt("SortParam", 0)
  1720. sortType, _ := this.GetInt("SortType", 0)
  1721. if utils.InArrayByInt(fieldArr, sortParam) && utils.InArrayByInt(typeArr, sortType) {
  1722. order = fmt.Sprintf("%s %s", fieldMap[sortParam], typeMap[sortType])
  1723. }
  1724. fmt.Println("order: ", order)
  1725. }
  1726. // 获取列表
  1727. businessOb := new(eta_business.EtaBusiness)
  1728. list, e := businessOb.GetItemsByCondition(cond, pars, []string{}, order)
  1729. if e != nil {
  1730. br.Msg = "获取失败"
  1731. br.ErrMsg = "获取商家列表失败, Err: " + e.Error()
  1732. return
  1733. }
  1734. items := make([]*eta_business.EtaBusinessItem, 0)
  1735. for _, v := range list {
  1736. b := new(eta_business.EtaBusinessItem)
  1737. b.EtaBusinessId = v.EtaBusinessId
  1738. b.BusinessName = v.BusinessName
  1739. b.BusinessCode = v.BusinessCode
  1740. b.CreditCode = v.CreditCode
  1741. b.RegionType = v.RegionType
  1742. b.Province = v.Province
  1743. b.City = v.City
  1744. b.Address = v.Address
  1745. b.SellerId = v.SellerId
  1746. b.SellerName = v.SellerName
  1747. b.Leader = v.Leader
  1748. b.IndustryId = v.IndustryId
  1749. b.IndustryName = v.IndustryName
  1750. b.CapitalScale = v.CapitalScale
  1751. b.ResearchTeamSize = v.ResearchTeamSize
  1752. b.UserMax = v.UserMax
  1753. b.SigningStatus = v.SigningStatus
  1754. b.Enable = v.Enable
  1755. b.ContractId = v.ContractId
  1756. b.SigningTime = utils.TimeTransferString(utils.FormatDate, v.SigningTime)
  1757. b.ExpiredTime = utils.TimeTransferString(utils.FormatDate, v.ExpiredTime)
  1758. b.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  1759. b.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
  1760. b.Nation = v.Nation
  1761. items = append(items, b)
  1762. }
  1763. resp.List = items
  1764. br.Data = resp
  1765. br.Ret = 200
  1766. br.Success = true
  1767. br.Msg = "获取成功"
  1768. }
  1769. // GetReportPermission
  1770. // @Title 获取报告分类权限
  1771. // @Description 获取报告分类权限
  1772. // @Param EtaBusinessId query int false "商户ID"
  1773. // @Success 200 Ret=200 操作成功
  1774. // @router /get_report_permission [get]
  1775. func (this *EtaBusinessController) GetReportPermission() {
  1776. br := new(models.BaseResponse).Init()
  1777. defer func() {
  1778. if br.ErrMsg == "" {
  1779. br.IsSendEmail = false
  1780. }
  1781. this.Data["json"] = br
  1782. this.ServeJSON()
  1783. }()
  1784. sysUser := this.SysUser
  1785. if sysUser == nil {
  1786. br.Msg = "请登录"
  1787. br.ErrMsg = "请登录,SysUser Is Empty"
  1788. br.Ret = 408
  1789. return
  1790. }
  1791. etaBusinessId, _ := this.GetInt("EtaBusinessId")
  1792. permissions := make([]*models.ChartPermission, 0)
  1793. {
  1794. permissionOb := new(models.ChartPermission)
  1795. cond := ` AND product_id = 1`
  1796. pars := make([]interface{}, 0)
  1797. list, e := permissionOb.GetItemsByCondition(cond, pars)
  1798. if e != nil {
  1799. br.Msg = "获取失败"
  1800. br.ErrMsg = fmt.Sprintf("获取品种分类失败, %v", e)
  1801. return
  1802. }
  1803. permissions = list
  1804. }
  1805. // 品种树
  1806. resp := new(models.BusinessReportPermissionResp)
  1807. resp.CheckList = make([]int, 0)
  1808. resp.List = make([]*models.ChartPermissionItem, 0)
  1809. childMap := make(map[int][]*models.ChartPermissionItem)
  1810. for _, v := range permissions {
  1811. t := new(models.ChartPermissionItem)
  1812. t.PermissionId = v.ChartPermissionId
  1813. t.PermissionName = v.PermissionName
  1814. t.ParentId = v.ParentId
  1815. t.IsPublic = v.IsPublic
  1816. t.Enabled = v.Enabled
  1817. t.Sort = v.Sort
  1818. t.CreateTime = v.CreatedTime.Format(utils.FormatDateTime)
  1819. t.Child = make([]*models.ChartPermissionItem, 0)
  1820. if v.ParentId == 0 {
  1821. resp.List = append(resp.List, t)
  1822. continue
  1823. }
  1824. if v.ParentId > 0 {
  1825. if childMap[v.ParentId] == nil {
  1826. childMap[v.ParentId] = make([]*models.ChartPermissionItem, 0)
  1827. }
  1828. childMap[v.ParentId] = append(childMap[v.ParentId], t)
  1829. }
  1830. }
  1831. for _, r := range resp.List {
  1832. r.Child = childMap[r.PermissionId]
  1833. }
  1834. // 获取商家勾选权限
  1835. if etaBusinessId > 0 {
  1836. selected, e := eta_business.GetBusinessReportPermission(etaBusinessId)
  1837. if e != nil {
  1838. br.Msg = "获取失败"
  1839. br.ErrMsg = fmt.Sprintf("获取商家已勾选报告权限失败, %v", e)
  1840. return
  1841. }
  1842. for _, v := range selected {
  1843. resp.CheckList = append(resp.CheckList, v.ChartPermissionId)
  1844. }
  1845. }
  1846. br.Data = resp
  1847. br.Ret = 200
  1848. br.Success = true
  1849. br.Msg = "获取成功"
  1850. }
  1851. // AddReportPermission
  1852. // @Title 设置报告分类权限
  1853. // @Description 设置报告分类权限
  1854. // @Param request body eta_business.AddBusinessReportPermissionReq true "type json string"
  1855. // @Success 200 {object} system.SysRoleListResp
  1856. // @router /add_report_permission [post]
  1857. func (this *EtaBusinessController) AddReportPermission() {
  1858. br := new(models.BaseResponse).Init()
  1859. defer func() {
  1860. this.Data["json"] = br
  1861. this.ServeJSON()
  1862. }()
  1863. sysUser := this.SysUser
  1864. if sysUser == nil {
  1865. br.Msg = "请登录"
  1866. br.ErrMsg = "请登录,SysUser Is Empty"
  1867. return
  1868. }
  1869. var req eta_business.AddBusinessReportPermissionReq
  1870. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1871. if err != nil {
  1872. br.Msg = "参数解析异常!"
  1873. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1874. return
  1875. }
  1876. if req.EtaBusinessId <= 0 {
  1877. br.Msg = "请选择商户"
  1878. return
  1879. }
  1880. // 权限校验
  1881. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  1882. if e != nil {
  1883. br.Msg = "操作失败"
  1884. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  1885. return
  1886. }
  1887. if !ok {
  1888. br.Msg = "无权操作"
  1889. return
  1890. }
  1891. ob := new(eta_business.EtaBusiness)
  1892. businessInfo, e := ob.GetItemById(req.EtaBusinessId)
  1893. if e != nil {
  1894. if e.Error() == utils.ErrNoRow() {
  1895. br.Msg = "商家不存在, 请刷新页面"
  1896. return
  1897. }
  1898. br.Msg = "操作失败"
  1899. br.ErrMsg = fmt.Sprintf("获取商户信息失败, %v", e)
  1900. return
  1901. }
  1902. addList := make([]*eta_business.BusinessReportPermission, 0)
  1903. for _, v := range req.ChartPermissionIds {
  1904. item := new(eta_business.BusinessReportPermission)
  1905. item.ChartPermissionId = v
  1906. item.BusinessCode = businessInfo.BusinessCode
  1907. item.EtaBusinessId = req.EtaBusinessId
  1908. item.CreateTime = time.Now()
  1909. item.ModifyTime = time.Now()
  1910. item.AdminId = sysUser.AdminId
  1911. addList = append(addList, item)
  1912. }
  1913. err = eta_business.AddBusinessReportPermission(addList, businessInfo.BusinessCode)
  1914. if err != nil {
  1915. br.Msg = "操作失败"
  1916. br.ErrMsg = fmt.Sprintf("设置商户报告权限失败, %v", err)
  1917. return
  1918. }
  1919. br.Ret = 200
  1920. br.Success = true
  1921. br.IsAddLog = true
  1922. br.Msg = "操作成功"
  1923. }