scrm-go

site_microwebsite_service.go 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. package site_service
  2. import (
  3. "SCRM/models"
  4. "SCRM/service"
  5. "fmt"
  6. "time"
  7. )
  8. func AddPatientModel(model *models.SgjPatientModel)error{
  9. err := service.PatientWriteDB().Create(&model).Error
  10. fmt.Println("插入错误",err)
  11. return err
  12. }
  13. func QueryModel(orgID int64)( models.SgjPatientModel,error) {
  14. model := models.SgjPatientModel{}
  15. err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&model).Error
  16. return model,err
  17. }
  18. func AddRotation(rotation models.SgjPatientRotation) error {
  19. err := service.PatientWriteDB().Create(&rotation).Error
  20. fmt.Println("插入数据",err)
  21. return err
  22. }
  23. func AddRotationUpload(connecmodel *models.SgjPatientConnecmodel) error {
  24. err := service.PatientWriteDB().Create(&connecmodel).Error
  25. fmt.Println("错误是什么,err",err)
  26. return err
  27. }
  28. func AddHispital(newmodel models.SgjPatientHospital) error {
  29. err := service.PatientWriteDB().Create(&newmodel).Error
  30. return err
  31. }
  32. func AddOffices(offices models.SgjPatientOffices) error {
  33. err := service.PatientWriteDB().Create(&offices).Error
  34. return err
  35. }
  36. func AddDoctor(doctor models.SgjPatientDoctor) error {
  37. err := service.PatientWriteDB().Create(&doctor).Error
  38. return err
  39. }
  40. func AddDoctorInfo(doctor models.SgjPatientDoctor) error{
  41. err := service.PatientWriteDB().Create(&doctor).Error
  42. return err
  43. }
  44. func AddOffEnvironment(officenviroment models.SgjPatientOffenvironment) error {
  45. err := service.PatientWriteDB().Create(&officenviroment).Error
  46. return err
  47. }
  48. func GetRationImages(orgID int64)(rot []*models.SgjPatientRotation, err error){
  49. err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Order("sort").Find(&rot).Error
  50. fmt.Println("错误是什么",err)
  51. return
  52. }
  53. func GetHospitalInfo(orgID int64)(models.SgjPatientHospital,error) {
  54. hospital := models.SgjPatientHospital{}
  55. err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&hospital).Error
  56. fmt.Println("错误是什么",err)
  57. return hospital,err
  58. }
  59. func GetOfficeInfo(orgID int64)(models.SgjPatientOffices,error) {
  60. offices := models.SgjPatientOffices{}
  61. err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&offices).Error
  62. fmt.Println("错误是什么",err)
  63. return offices,err
  64. }
  65. func GetDoctorInfo(orgID int64)(doc []*models.SgjPatientDoctor,err error) {
  66. err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Limit(2).Find(&doc).Error
  67. fmt.Println("错误是什么",err)
  68. return
  69. }
  70. func GetQueryDocInfo(orgID int64)(doc []*models.SgjUserStaffInfo,err error) {
  71. err = service.UserReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Find(&doc).Error
  72. fmt.Println("错误是什么",err)
  73. return
  74. }
  75. func GetQueryDocHead(orgID int64) (doc []*models.SgjPatientDoctor,err error) {
  76. err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Order("doc_sort").Find(&doc).Error
  77. return
  78. }
  79. func GetOffEnvironment(orgID int64)(models.SgjPatientOffenvironment,error) {
  80. offenvironment := models.SgjPatientOffenvironment{}
  81. err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&offenvironment).Error
  82. fmt.Println("错误是什么",err)
  83. return offenvironment,err
  84. }
  85. func AddWorkTime(connecmodel models.SgjPatientConnecmodel) error {
  86. err := service.PatientWriteDB().Create(&connecmodel).Error
  87. return err
  88. }
  89. func AddRideWay(connecmodel models.SgjPatientConnecmodel) error {
  90. err := service.PatientWriteDB().Create(&connecmodel).Error
  91. return err
  92. }
  93. func AddConnetion(connection models.SgjPatientConnection) error {
  94. err := service.PatientWriteDB().Create(&connection).Error
  95. return err
  96. }
  97. func GetQueryConnection( orgID int64)(conection []*models.SgjPatientConnection,err error) {
  98. err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Find(&conection).Error
  99. return
  100. }
  101. func DeleteConnecWay(orgid int64,id int64)(error){
  102. err := service.PatientWriteDB().Model(&models.SgjPatientConnection{}).Where("user_org_id =? AND id = ?", orgid, id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  103. return err
  104. }
  105. func EditConnecWay(orgid int64,id int64)(models.SgjPatientConnection,error){
  106. sgj := models.SgjPatientConnection{}
  107. err := service.PatientReadDB().Model(&sgj).Where("user_org_id = ? AND id =?", orgid, id).Find(&sgj).Error
  108. return sgj,err;
  109. }
  110. func UpadateConnec(connection *models.SgjPatientConnection,orgID int64,id int64) {
  111. service.PatientWriteDB().Model(connection).Where("user_org_id = ? AND id = ? AND status = ?",orgID,id,1).Update(map[string]interface{}{"title":connection.Title,"connecway":connection.Connecway,"content":connection.Content,})
  112. }
  113. func GetUserModel(orgid int64)(model []*models.SgjPatientConnecmodel,err error){
  114. err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Order("sort").Find(&model).Error
  115. return
  116. }
  117. func GetQueryNewModel(orgid int64)(model []*models.SgjPatientModel,err error) {
  118. err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Order("sort").Find(&model).Error
  119. fmt.Println("错误是什么",err)
  120. return
  121. }
  122. func GetEditModel(orgid int64,id int64)(models.SgjPatientConnecmodel,error){
  123. connecmodel := models.SgjPatientConnecmodel{}
  124. err := service.PatientReadDB().Model(&connecmodel).Where("user_org_id = ? AND id = ?", orgid, id).Find(&connecmodel).Error
  125. return connecmodel,err;
  126. }
  127. func UpdateWorkTime(id int64,orgID int64,connecmodel models.SgjPatientConnecmodel) {
  128. service.PatientWriteDB().Model(connecmodel).Where("id = ? AND user_org_id = ? AND status = ?",id,orgID,1).Update(map[string]interface{}{"title":connecmodel.Title,"sort":connecmodel.Sort,"worktime":connecmodel.Worktime,"mtime":time.Now().Unix()})
  129. }
  130. func UpdateRideWay(id int64,orgID int64,connecmodel models.SgjPatientConnecmodel) error {
  131. err := service.PatientWriteDB().Model(connecmodel).Where("id = ? AND user_org_id = ? AND status =?", id, orgID, 1).Update(map[string]interface{}{"title": connecmodel.Title, "sort": connecmodel.Sort, "rideway": connecmodel.Rideway, "mtime": time.Now().Unix()}).Error
  132. return err
  133. }
  134. func QueryDocById(orgID int64,id int64)(models.SgjUserStaffInfo,error) {
  135. info := models.SgjUserStaffInfo{}
  136. err := service.UserWriteDB().Model(&info).Where("user_org_id = ? AND id = ?",orgID ,id ).Find(&info).Error
  137. return info,err
  138. }
  139. func EditDoctorInfo(id int64,orgID int64)(models.SgjPatientDoctor,error) {
  140. doctor := models.SgjPatientDoctor{}
  141. err := service.PatientReadDB().Model(&doctor).Where("id = ? AND user_org_id = ?", id, orgID).Find(&doctor).Error
  142. return doctor,err
  143. }
  144. func UpdateDocInfo(id int64,orgID int64,doctor models.SgjPatientDoctor) error {
  145. err := service.PatientWriteDB().Model(doctor).Where("id = ? AND user_org_id = ? AND status = ?", id, orgID, 1).Update(map[string]interface{}{"docname": doctor.Docname, "doc_position": doctor.DocPosition, "dochead": doctor.Dochead, "doc_sort": doctor.DocSort, "docintroduction": doctor.Docintroduction, "mtime": time.Now().Unix()}).Error
  146. return err
  147. }
  148. func DeleteDoctor(id int64,orgID int64)(error) {
  149. err := service.PatientWriteDB().Model(&models.SgjPatientDoctor{}).Where("id = ? AND user_org_id = ?", id, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  150. return err
  151. }
  152. func EditHospital(mid int64,orgID int64)(models.SgjPatientHospital,error) {
  153. hospital := models.SgjPatientHospital{}
  154. err := service.PatientReadDB().Model(&hospital).Where("modleid = ? AND user_org_id = ? AND status = ?", mid, orgID, 1).Find(&hospital).Error
  155. return hospital,err
  156. }
  157. func UpdateHospital(id int64,OrgId int64,hospital models.SgjPatientHospital) error {
  158. err := service.PatientWriteDB().Model(hospital).Where("id = ? AND user_org_id = ? AND status = ?", id, OrgId, 1).Update(map[string]interface{}{"title": hospital.Title, "sort": hospital.Sort, "introduction": hospital.Introduction, "mtime": time.Now().Unix()}).Error
  159. return err
  160. }
  161. func UpdateModel(modelid int64,orgId int64 ,model models.SgjPatientModel) error {
  162. err := service.PatientWriteDB().Model(model).Where("id = ? AND user_org_id = ? AND status = ?", modelid, orgId, 1).Update(map[string]interface{}{"title": model.Title, "sort": model.Sort, "mtime": time.Now().Unix()}).Error
  163. return err
  164. }
  165. func EditOffice(mid int64,orgID int64)(models.SgjPatientOffices,error) {
  166. offices := models.SgjPatientOffices{}
  167. err := service.PatientReadDB().Model(&offices).Where("modleid = ? AND user_org_id = ? AND status = ?", mid, orgID, 1).Find(&offices).Error
  168. return offices,err
  169. }
  170. func DeletemodleById(id int64,orgID int64)(error) {
  171. err:= service.PatientWriteDB().Model(models.SgjPatientModel{}).Where("id = ? AND user_org_id = ?", id, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  172. return err
  173. }
  174. func DeleteHospitalByModelid(mid int64,orgID int64)(error) {
  175. err := service.PatientWriteDB().Model(models.SgjPatientHospital{}).Where("modleid = ? AND user_org_id = ?", mid, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  176. return err
  177. }
  178. func DeleteOfficeByModelid(mid int64,orgID int64)(error) {
  179. err := service.PatientWriteDB().Model(models.SgjPatientOffices{}).Where("modleid = ? AND user_org_id = ?", mid, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  180. return err
  181. }
  182. func UpdateOffices(id int64,orgID int64,offices models.SgjPatientOffices) error {
  183. err := service.PatientWriteDB().Model(offices).Where("id = ? AND user_org_id = ? AND status = ?", id, orgID, 1).Update(map[string]interface{}{"title": offices.Title, "sort": offices.Sort, "introduction": offices.Introduction, "mtime": time.Now().Unix()}).Error
  184. return err
  185. }
  186. func GetHospital(Orgid int64)(hostital []*models.SgjPatientHospital,err error) {
  187. err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", Orgid, 1).Order("sort").Find(&hostital).Error
  188. return
  189. }
  190. func GetData(orgid int64)(model []*models.SgjPatientModel,err error) {
  191. db := service.PatientReadDB().Table("sgj_patient_model as m").Where(" m.status = ?", 1)
  192. if(orgid > 0){
  193. db = db.Where("user_org_id = ? ", orgid)
  194. }
  195. err = db.Preload("Hospitals").Preload("Offices").Select("m.id,m.title,m.sort,m.ctime,m.mtime,m.user_org_id,m.status,m.mode_type").Order("sort").Find(&model).Error
  196. return
  197. }