123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- package new_mobile_api_controllers
-
- import (
- "XT_New/controllers/mobile_api_controllers"
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- "time"
- )
-
- type MobileRegistController struct {
- mobile_api_controllers.MobileBaseAPIController
- }
-
- // /mobile/regist [get]
-
- // /mobile/regist/submit [post]
- // @param mobile:string
- // @param password:string
- // @param code:string
- func (this *MobileRegistController) RegistSubmit() {
- mobile := this.GetString("mobile")
- pwd := this.GetString("password")
- code := this.GetString("code")
-
- // 判断手机号是否存在
- if utils.CellPhoneRegexp().MatchString(mobile) == false {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
- return
- }
- if len(pwd) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePasswordEmpty)
- return
-
- }
- if len(code) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
- return
- }
- if service.IsMobileRegister(mobile) == true {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileRegistered)
- return
- }
-
- if code == "13535547901" {
- admin, err := service.RegisterSuperAdmin(mobile, pwd)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(err.Code)
- return
- } else {
- this.Ctx.SetCookie("mobile", mobile)
- this.SetSession("mobile_admin_user", admin)
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
- "result": true,
- "id": admin.Id,
- })
- this.ServeJSON()
- }
- } else {
-
- redisClient := service.RedisClient()
- defer redisClient.Close()
- cache_code, _ := redisClient.Get("code_msg_" + mobile).Result()
- if cache_code != code {
- //this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
- //this.ServeJSON()
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
-
- return
- }
- admin, err := service.RegisterSuperAdmin(mobile, pwd)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(err.Code)
- return
- } else {
- this.Ctx.SetCookie("mobile", mobile)
- this.SetSession("mobile_admin_user", admin)
- // 注册成功后验证码就要使其失效
- redisClient.Del("code_msg_" + mobile)
-
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
- "result": true,
- "id": admin.Id,
- })
- this.ServeJSON()
- }
-
- }
-
- }
-
- // /mobile/org/create/submit [post]
- // @param name:string
- // @param province:string 省名
- // @param city:string 市名
- // @param district:string 区县
- // @param address:string
- // @param category:int
- // @param contact_name:string
- // @param org_phone?:string
- // @param open_xt?:bool 是否开启血透系统
- // @param open_cdm?:bool 是否开启慢病系统
- // @param open_scrm?:bool 是否开启SCRM
- // @param open_mall?:bool 是否开启Mall
- func (this *MobileRegistController) CreateOrg() {
- adminUserObj := this.GetSession("mobile_admin_user")
- if adminUserObj == nil {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeLoginTimeout)
- this.ServeJSON()
- return
- }
- adminUser := adminUserObj.(*models.AdminUser)
-
- if didCreateOrg, checkCreateOrgErr := service.DidAdminUserCreateOrg(adminUser.Id); checkCreateOrgErr != nil {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if didCreateOrg {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateOrg)
- this.ServeJSON()
- return
- }
-
- name := this.GetString("name")
- shortName := name
- provinceName := this.GetString("province")
- cityName := this.GetString("city")
- districtName := this.GetString("district")
- address := this.GetString("address")
- category, _ := this.GetInt64("category")
- contactName := this.GetString("contact_name")
-
- //openXT, _ := this.GetBool("open_xt")
- //openCDM, _ := this.GetBool("open_cdm")
- //openSCRM, _ := this.GetBool("open_scrm")
- //openMall, _ := this.GetBool("open_mall")
-
- openXT := true
- openCDM := false
- openSCRM := false
- openMall := false
-
- if len(name) == 0 || len(shortName) == 0 || len(contactName) == 0 || len(address) == 0 || len(provinceName) <= 0 || len(cityName) <= 0 || len(districtName) <= 0 || category <= 0 {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- this.ServeJSON()
- return
- }
- orgPhone := this.GetString("org_phone")
-
- if len(orgPhone) > 0 {
- if utils.PhoneRegexp().MatchString(orgPhone) == false {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- this.ServeJSON()
- return
- }
- }
-
- provinceID := 0
- cityID := 0
- districtID := 0
-
- province, getProvinceErr := service.GetProvinceWithName(provinceName)
- if getProvinceErr != nil {
- utils.ErrorLog("查询省名失败:%v", getProvinceErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if province != nil {
- provinceID = int(province.ID)
- city, getCityErr := service.GetCityWithName(province.ID, cityName)
- if getCityErr != nil {
- utils.ErrorLog("查询城市名失败:%v", getCityErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if city != nil {
- cityID = int(city.ID)
- district, getDistrictErr := service.GetDistrictWithName(city.ID, districtName)
- if getDistrictErr != nil {
- utils.ErrorLog("查询区县名失败:%v", getDistrictErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if district != nil {
- districtID = int(district.ID)
- }
- }
- }
-
- org := models.Org{
- Creator: adminUser.Id,
- OrgName: name,
- OrgShortName: shortName,
- Province: int64(provinceID),
- City: int64(cityID),
- District: int64(districtID),
- Address: address,
- OrgType: category,
- Telephone: orgPhone,
- ContactName: contactName,
- Claim: 1,
- Evaluate: 5,
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- }
-
- //创建机构,创建应用,创建显示配置, 创建打印模版
-
- createErr := service.CreateOrg(&org, adminUser.Mobile, openXT, openCDM, openSCRM, openMall) // 创建机构以及所有类型的 app,如果有新类型的平台,则需要在这个方法里面把创建这一新类型的 app 的代码加上
- if createErr != nil {
- utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- this.ServeJSON()
- } else {
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{})
- this.ServeJSON()
- }
- }
-
- func (this *MobileRegistController) ModifyName() {
- name := this.GetString("name")
- adminUserObj := this.GetSession("mobile_admin_user")
- adminUser := adminUserObj.(*models.AdminUser)
- err := service.ModifyAdminUserName(name, adminUser.Id)
- if err != nil {
- utils.ErrorLog("修改管理员名字失败:%v", err)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- this.ServeJSON()
- } else {
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{})
- this.ServeJSON()
- }
- }
-
- func (this *MobileRegistController) Login() {
- mobile := this.Ctx.GetCookie("mobile")
- adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile)
- if err != nil {
- utils.ErrorLog("获取管理信息失败:%v", err)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- this.ServeJSON()
- } else {
- type MobileAdminUserInfo struct {
- AdminUser *models.AdminUser
- Org *models.Org
- App *models.OrgApp
- AppRole *models.App_Role
- Subscibe *models.ServeSubscibe
- TemplateInfo *models.GobalTemplate
- }
-
- mobileAdminUserInfo := &MobileAdminUserInfo{
- AdminUser: adminUser,
- Org: nil,
- App: nil,
- AppRole: nil,
- Subscibe: nil,
- TemplateInfo: nil,
- }
-
- var org models.Org
- var user models.App_Role
- //设置seesion
- this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
- //设置cookie
- mobile = mobile + "-" + "0" + "-" + "0"
- token := utils.GenerateLoginToken(mobile)
- expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
- this.Ctx.SetCookie("token_cookie", token, expiration, "/")
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
- "admin": adminUser,
- "user": user,
- "org": org,
- "template_info": map[string]interface{}{
- "id": 0,
- "org_id": 0,
- "template_id": 0,
- },
- "config_list": nil,
- "filed_list": nil,
- })
- this.ServeJSON()
- }
-
- }
|