eta_business.go 51 KB

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