manager_center_api_controller.go 50KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "reflect"
  11. "strconv"
  12. "time"
  13. )
  14. type ManagerCenterApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func ManagerCenterRegistRouters() {
  18. //药品基础库
  19. beego.Router("/api/basedruglib/create", &ManagerCenterApiController{}, "post:CreateBaseDrugLib")
  20. beego.Router("/api/basedruglib/edit", &ManagerCenterApiController{}, "post:EditBaseDrugLib")
  21. beego.Router("/api/basedruglib/get", &ManagerCenterApiController{}, "get:GetBaseDrugLib")
  22. beego.Router("/api/basedruglib/list", &ManagerCenterApiController{}, "get:GetBaseDrugLibList")
  23. beego.Router("/api/medicineinsurancepercent/create", &ManagerCenterApiController{}, "post:CreateMedicineInsurancePercent")
  24. beego.Router("/api/drugunitsafeguard/create", &ManagerCenterApiController{}, "post:CreateDrugUnitSafeguard")
  25. beego.Router("/api/medicineinsurancepercent/get", &ManagerCenterApiController{}, "get:GetMedicineInsurancePercent")
  26. //beego.Router("/api/drugunitsafeguard/get", &ManagerCenterApiController{}, "get:GetDrugUnitSafeguard")
  27. //专项字典
  28. beego.Router("/api/dictionary/getconfiglist", &ManagerCenterApiController{}, "get,post:GetConfigList")
  29. beego.Router("/api/dictionary/createconfig", &ManagerCenterApiController{}, "Post:CreateConfig")
  30. beego.Router("/api/dictionary/createchildconfig", &ManagerCenterApiController{}, "Post:CreateChildConfig")
  31. beego.Router("/api/dictionary/updatechildconfig", &ManagerCenterApiController{}, "Post:UpdateChildConfig")
  32. beego.Router("/api/dictionary/deletechildconfig", &ManagerCenterApiController{}, "Post:DeleteChildConfig")
  33. beego.Router("/api/dictionary/updatetemplate", &ManagerCenterApiController{}, "Post:UpdateTemplate")
  34. //经销商
  35. beego.Router("/api/stock/dealer/create", &ManagerCenterApiController{}, "post:CreateDealer")
  36. beego.Router("/api/stock/dealer/modify", &ManagerCenterApiController{}, "post:ModifyDealer")
  37. beego.Router("/api/stock/dealer/list", &ManagerCenterApiController{}, "get:GetDealersList")
  38. beego.Router("/api/stock/dealer/delete", &ManagerCenterApiController{}, "post:DeleteDealer")
  39. beego.Router("/api/stock/dealer/get", &ManagerCenterApiController{}, "get:GetDealer")
  40. //厂商
  41. beego.Router("/api/stock/manufacturer/create", &ManagerCenterApiController{}, "post:CreateManufacturer")
  42. beego.Router("/api/stock/manufacturer/modify", &ManagerCenterApiController{}, "post:ModifyManufacturer")
  43. beego.Router("/api/stock/manufacturer/list", &ManagerCenterApiController{}, "get:GetManufacturerList")
  44. beego.Router("/api/stock/manufacturer/delete", &ManagerCenterApiController{}, "post:DeleteManufacturer")
  45. beego.Router("/api/stock/manufacturer/get", &ManagerCenterApiController{}, "get:GetManufacturer")
  46. beego.Router("/api/stock/good/info/create", &ManagerCenterApiController{}, "post:CreateGoodInfo")
  47. beego.Router("/api/stock/good/info/modify", &ManagerCenterApiController{}, "post:ModifyGoodInfo")
  48. beego.Router("/api/stock/good/info/list", &ManagerCenterApiController{}, "get:GetGoodInfoList")
  49. beego.Router("/api/info/delete", &ManagerCenterApiController{}, "post:DeleteGoodInfo")
  50. beego.Router("/api/stock/good/info/get", &ManagerCenterApiController{}, "get:GetGoodInfoByGoodId")
  51. beego.Router("/api/stock/good/info", &ManagerCenterApiController{}, "get:GetGoodInfoById")
  52. }
  53. func (c *ManagerCenterApiController) CreateBaseDrugLib() {
  54. drug_name := c.GetString("drug_name")
  55. fmt.Println("0000000")
  56. fmt.Println(drug_name)
  57. pinyin := c.GetString("pinyin")
  58. wubi := c.GetString("wubi")
  59. drug_alias := c.GetString("drug_alias")
  60. drug_alias_pinyin := c.GetString("drug_alias_pinyin")
  61. drug_alias_wubi := c.GetString("drug_alias_wubi")
  62. drug_category, _ := c.GetInt64("drug_category")
  63. drug_spec := c.GetString("drug_spec")
  64. drug_type, _ := c.GetInt64("drug_type")
  65. drug_stock_limit := c.GetString("drug_stock_limit")
  66. drug_origin_place := c.GetString("drug_origin_place")
  67. drug_dosage_form, _ := c.GetInt64("drug_dosage_form")
  68. medical_insurance_level, _ := c.GetInt64("medical_insurance_level")
  69. max_unit := c.GetString("max_unit")
  70. min_unit := c.GetString("min_unit")
  71. unit_matrixing := c.GetString("unit_matrixing")
  72. retail_price, _ := c.GetFloat("retail_price")
  73. last_price, _ := c.GetFloat("last_price")
  74. drug_control, _ := c.GetInt64("drug_control")
  75. number := c.GetString("number")
  76. drug_classify := c.GetString("drug_classify")
  77. drug_dose, _ := c.GetFloat("drug_dose")
  78. drug_dose_unit, _ := c.GetInt64("drug_dose_unit")
  79. medical_insurance_number := c.GetString("medical_insurance_number")
  80. manufacturer, _ := c.GetInt64("manufacturer")
  81. pharmacology_category, _ := c.GetInt64("pharmacology_category")
  82. statistics_category, _ := c.GetInt64("statistics_category")
  83. code := c.GetString("code")
  84. is_special_diseases, _ := c.GetInt64("is_special_diseases")
  85. is_record, _ := c.GetInt64("is_record")
  86. agent := c.GetString("agent")
  87. drug_status := c.GetString("drug_status")
  88. limit_remark := c.GetString("limit_remark")
  89. delivery_way := c.GetString("delivery_way")
  90. execution_frequency := c.GetString("execution_frequency")
  91. single_dose, _ := c.GetFloat("single_dose")
  92. prescribing_number, _ := c.GetFloat("prescribing_number")
  93. label, _ := c.GetInt64("label")
  94. sort, _ := c.GetInt64("sort")
  95. is_use_doctor_advice, _ := c.GetInt64("is_use_doctor_advice")
  96. is_default, _ := c.GetInt64("is_default")
  97. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  98. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  99. is_charge_use, _ := c.GetInt64("is_charge_use")
  100. adminInfo := c.GetAdminUserInfo()
  101. drugLib := &models.BaseDrugLib{
  102. DrugName: drug_name,
  103. Pinyin: pinyin,
  104. Wubi: wubi,
  105. DrugAlias: drug_alias,
  106. DrugAliasPinyin: drug_alias_pinyin,
  107. DrugAliasWubi: drug_alias_wubi,
  108. DrugCategory: drug_category,
  109. DrugSpec: drug_spec,
  110. DrugType: drug_type,
  111. DrugStockLimit: drug_stock_limit,
  112. DrugOriginPlace: drug_origin_place,
  113. MedicalInsuranceLevel: medical_insurance_level,
  114. DrugDosageForm: drug_dosage_form,
  115. MaxUnit: max_unit,
  116. MinUnit: min_unit,
  117. UnitMatrixing: unit_matrixing,
  118. RetailPrice: retail_price,
  119. LastPrice: last_price,
  120. DrugControl: drug_control,
  121. Number: number,
  122. DrugClassify: drug_classify,
  123. DrugDose: drug_dose,
  124. DrugDoseUnit: drug_dose_unit,
  125. MedicalInsuranceNumber: medical_insurance_number,
  126. Manufacturer: manufacturer,
  127. PharmacologyCategory: pharmacology_category,
  128. StatisticsCategory: statistics_category,
  129. Code: code,
  130. IsSpecialDiseases: is_special_diseases,
  131. IsRecord: is_record,
  132. Agent: agent,
  133. DrugStatus: drug_status,
  134. LimitRemark: limit_remark,
  135. DeliveryWay: delivery_way,
  136. ExecutionFrequency: execution_frequency,
  137. SingleDose: single_dose,
  138. PrescribingNumber: prescribing_number,
  139. Label: label,
  140. Sort: sort,
  141. IsUseDoctorAdvice: is_use_doctor_advice,
  142. IsDefault: is_default,
  143. IsChargePredict: is_charge_predict,
  144. IsStatisticsWork: is_statistics_work,
  145. IsChargeUse: is_charge_use,
  146. OrgId: adminInfo.CurrentOrgId,
  147. Status: 1,
  148. Ctime: time.Now().Unix(),
  149. Mtime: time.Now().Unix(),
  150. }
  151. total := service.FindAllDrugLibRecordTotal(adminInfo.CurrentOrgId)
  152. drug_code := strconv.FormatInt(total+1, 10)
  153. drug_code = "54000000" + drug_code
  154. drugLib.DrugCode = drug_code
  155. count := service.FindBaseDrugLibRecordCount(drugLib)
  156. if count == 0 {
  157. err := service.CreateBaseDrugLib(drugLib)
  158. if err == nil {
  159. c.ServeSuccessJSON(map[string]interface{}{
  160. "msg": "创建成功",
  161. })
  162. } else {
  163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  164. return
  165. }
  166. return
  167. } else {
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDrugRepeatDataException)
  169. return
  170. }
  171. }
  172. func (c *ManagerCenterApiController) EditBaseDrugLib() {
  173. id, _ := c.GetInt64("id")
  174. drug_name := c.GetString("drug_name")
  175. fmt.Println("drug_name--------", drug_name)
  176. pinyin := c.GetString("pinyin")
  177. wubi := c.GetString("wubi")
  178. drug_alias := c.GetString("drug_alias")
  179. drug_alias_pinyin := c.GetString("drug_alias_pinyin")
  180. drug_alias_wubi := c.GetString("drug_alias_wubi")
  181. drug_category, _ := c.GetInt64("drug_category")
  182. drug_spec := c.GetString("drug_spec")
  183. drug_type, _ := c.GetInt64("drug_type")
  184. drug_stock_limit := c.GetString("drug_stock_limit")
  185. drug_origin_place := c.GetString("drug_origin_place")
  186. drug_dosage_form, _ := c.GetInt64("drug_dosage_form")
  187. medical_insurance_level, _ := c.GetInt64("medical_insurance_level")
  188. max_unit := c.GetString("max_unit")
  189. min_unit := c.GetString("min_unit")
  190. unit_matrixing := c.GetString("unit_matrixing")
  191. retail_price, _ := c.GetFloat("retail_price")
  192. last_price, _ := c.GetFloat("last_price")
  193. drug_control, _ := c.GetInt64("drug_control")
  194. number := c.GetString("number")
  195. drug_classify := c.GetString("drug_classify")
  196. drug_dose, _ := c.GetFloat("drug_dose")
  197. drug_dose_unit, _ := c.GetInt64("drug_dose_unit")
  198. medical_insurance_number := c.GetString("medical_insurance_number")
  199. manufacturer, _ := c.GetInt64("manufacturer")
  200. pharmacology_category, _ := c.GetInt64("pharmacology_category")
  201. statistics_category, _ := c.GetInt64("statistics_category")
  202. code := c.GetString("code")
  203. is_special_diseases, _ := c.GetInt64("is_special_diseases")
  204. is_record, _ := c.GetInt64("is_record")
  205. agent := c.GetString("agent")
  206. drug_status := c.GetString("drug_status")
  207. limit_remark := c.GetString("limit_remark")
  208. delivery_way := c.GetString("delivery_way")
  209. execution_frequency := c.GetString("execution_frequency")
  210. single_dose, _ := c.GetFloat("single_dose")
  211. prescribing_number, _ := c.GetFloat("prescribing_number")
  212. label, _ := c.GetInt64("label")
  213. sort, _ := c.GetInt64("sort")
  214. is_use_doctor_advice, _ := c.GetInt64("is_use_doctor_advice")
  215. is_default, _ := c.GetInt64("is_default")
  216. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  217. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  218. is_charge_use, _ := c.GetInt64("is_charge_use")
  219. drug_code := c.GetString("drug_code")
  220. unit := c.GetString("unit")
  221. adminInfo := c.GetAdminUserInfo()
  222. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
  223. drugLib := &models.BaseDrugLib{
  224. ID: id,
  225. DrugName: drug_name,
  226. Pinyin: pinyin,
  227. Wubi: wubi,
  228. DrugAlias: drug_alias,
  229. DrugAliasPinyin: drug_alias_pinyin,
  230. DrugAliasWubi: drug_alias_wubi,
  231. DrugCategory: drug_category,
  232. DrugSpec: drug_spec,
  233. DrugType: drug_type,
  234. DrugStockLimit: drug_stock_limit,
  235. DrugOriginPlace: drug_origin_place,
  236. MedicalInsuranceLevel: medical_insurance_level,
  237. DrugDosageForm: drug_dosage_form,
  238. MaxUnit: max_unit,
  239. MinUnit: min_unit,
  240. UnitMatrixing: unit_matrixing,
  241. RetailPrice: retail_price,
  242. LastPrice: last_price,
  243. DrugControl: drug_control,
  244. Number: number,
  245. DrugClassify: drug_classify,
  246. DrugDose: drug_dose,
  247. DrugDoseUnit: drug_dose_unit,
  248. MedicalInsuranceNumber: medical_insurance_number,
  249. Manufacturer: manufacturer,
  250. PharmacologyCategory: pharmacology_category,
  251. StatisticsCategory: statistics_category,
  252. Code: code,
  253. IsSpecialDiseases: is_special_diseases,
  254. IsRecord: is_record,
  255. Agent: agent,
  256. DrugStatus: drug_status,
  257. LimitRemark: limit_remark,
  258. DeliveryWay: delivery_way,
  259. ExecutionFrequency: execution_frequency,
  260. SingleDose: single_dose,
  261. PrescribingNumber: prescribing_number,
  262. Label: label,
  263. Sort: sort,
  264. IsUseDoctorAdvice: is_use_doctor_advice,
  265. IsDefault: is_default,
  266. IsChargePredict: is_charge_predict,
  267. IsStatisticsWork: is_statistics_work,
  268. IsChargeUse: is_charge_use,
  269. OrgId: adminInfo.CurrentOrgId,
  270. Status: 1,
  271. Ctime: drug.Ctime,
  272. Mtime: time.Now().Unix(),
  273. DrugCode: drug_code,
  274. }
  275. err := service.UpdateBaseDrugLib(drugLib)
  276. //修改xt_drug_name 表
  277. drugName := models.XtDrugName{
  278. DrugName: drug_name,
  279. }
  280. service.UpdatedDrugName(id, adminInfo.CurrentOrgId, &drugName)
  281. //修改规格xt_stand_name表
  282. standName := models.XtStandName{
  283. DrugName: drug_name,
  284. DrugSpec: drug_spec,
  285. DrugStockLimit: drug_stock_limit,
  286. MinUnit: unit,
  287. }
  288. service.UpdateStandName(id, adminInfo.CurrentOrgId, &standName)
  289. //修改药品表
  290. medical := models.XtSelfMedical{
  291. DrugName: drug_name,
  292. DrugSpec: drug_spec,
  293. ExecutionFrequency: execution_frequency,
  294. PrescribingNumber: prescribing_number,
  295. DeliveryWay: delivery_way,
  296. SingleDose: single_dose,
  297. MinUnit: unit,
  298. }
  299. service.UpdateSelfMedical(id, adminInfo.CurrentOrgId, &medical)
  300. //修改入库表
  301. nameId, err := service.GetDrugNameId(id, adminInfo.CurrentOrgId)
  302. stock := models.XtSelfStock{
  303. DrugSpec: drug_spec,
  304. DrugName: drug_name,
  305. MinUnit: unit,
  306. }
  307. service.UpdatedSelfStock(&stock, nameId.ID, adminInfo.CurrentOrgId)
  308. outStock := models.XtSelfOutStock{
  309. DrugName: drug_name,
  310. DrugSpec: drug_spec,
  311. }
  312. //修改出库表
  313. service.UpdatedOutSelfStock(&outStock, nameId.ID, adminInfo.CurrentOrgId)
  314. //查询未执行的医嘱
  315. advice := models.DoctorAdvice{
  316. AdviceName: drug_name,
  317. AdviceDesc: drug_spec,
  318. DeliveryWay: delivery_way,
  319. ExecutionFrequency: execution_frequency,
  320. SingleDose: single_dose,
  321. SingleDoseUnit: unit,
  322. }
  323. service.UpdateNoExcuteDoctorAdvice(nameId.ID, adminInfo.CurrentOrgId, &advice)
  324. if err == nil {
  325. c.ServeSuccessJSON(map[string]interface{}{
  326. "msg": "修改成功",
  327. })
  328. return
  329. } else {
  330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  331. return
  332. }
  333. }
  334. func (c *ManagerCenterApiController) GetBaseDrugLib() {
  335. id, _ := c.GetInt64("id")
  336. adminInfo := c.GetAdminUserInfo()
  337. drug, err := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
  338. if err == nil {
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "drug": drug,
  341. })
  342. return
  343. } else {
  344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  345. return
  346. }
  347. }
  348. func (c *ManagerCenterApiController) GetBaseDrugLibList() {
  349. page, _ := c.GetInt64("page", 1)
  350. limit, _ := c.GetInt64("limit", 10)
  351. is_use, _ := c.GetInt64("is_use", 0)
  352. is_charge, _ := c.GetInt64("is_charge", 0)
  353. is_inject, _ := c.GetInt64("is_inject", 0)
  354. keyword := c.GetString("keyword")
  355. adminInfo := c.GetAdminUserInfo()
  356. if page <= 0 {
  357. page = 1
  358. }
  359. if limit <= 0 {
  360. limit = 10
  361. }
  362. list, total, _ := service.GetBaseDrugLibList(adminInfo.CurrentOrgId, keyword, page, limit, is_use, is_charge, is_inject)
  363. c.ServeSuccessJSON(map[string]interface{}{
  364. "list": list,
  365. "total": total,
  366. })
  367. return
  368. }
  369. func (c *ManagerCenterApiController) CreateMedicineInsurancePercent() {
  370. module, _ := c.GetInt64("module", 0)
  371. adminInfo := c.GetAdminUserInfo()
  372. dataBody := make(map[string]interface{}, 0)
  373. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  374. if err != nil {
  375. utils.ErrorLog(err.Error())
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  377. return
  378. }
  379. var mips []*models.MedicineInsurancePercentage
  380. var errs error
  381. record_time := time.Now().Unix()
  382. if dataBody["mip"] != nil && reflect.TypeOf(dataBody["mip"]).String() == "[]interface {}" {
  383. mip_map, _ := dataBody["mip"].([]interface{})
  384. if len(mip_map) > 0 {
  385. for _, item := range mip_map {
  386. items := item.(map[string]interface{})
  387. if items["type_id"] == nil || reflect.TypeOf(items["type_id"]).String() != "float64" {
  388. utils.ErrorLog("type_id")
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  390. return
  391. }
  392. type_id := int64(items["type_id"].(float64))
  393. if items["medicine_insurance_type"] == nil || reflect.TypeOf(items["medicine_insurance_type"]).String() != "float64" {
  394. utils.ErrorLog("medicine_insurance_type")
  395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  396. return
  397. }
  398. types := int64(items["medicine_insurance_type"].(float64))
  399. if items["percent"] == nil || reflect.TypeOf(items["percent"]).String() != "string" {
  400. utils.ErrorLog("percent")
  401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  402. return
  403. }
  404. percent, _ := strconv.ParseFloat(items["percent"].(string), 64)
  405. //percent := items["percent"].(float64)
  406. mip_temp := &models.MedicineInsurancePercentage{
  407. TypeId: type_id,
  408. Status: 1,
  409. Ctime: time.Now().Unix(),
  410. Mtime: time.Now().Unix(),
  411. RecordTime: record_time,
  412. MedicineInsuranceType: types,
  413. UserOrgId: adminInfo.CurrentOrgId,
  414. Percent: percent,
  415. Module: module,
  416. GoodId: 0,
  417. }
  418. mips = append(mips, mip_temp)
  419. }
  420. }
  421. for _, item := range mips {
  422. errs = service.CreateMedicineInsurancePercentage(item)
  423. }
  424. }
  425. if errs == nil {
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "msg": "添加成功",
  428. })
  429. return
  430. } else {
  431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  432. return
  433. }
  434. }
  435. func (c *ManagerCenterApiController) CreateDrugUnitSafeguard() {
  436. }
  437. //GetPatientsList 取配置信息列表
  438. func (c *ManagerCenterApiController) GetConfigList() {
  439. adminUserInfo := c.GetAdminUserInfo()
  440. configList, _ := service.GetDictionaryConfigList(adminUserInfo.CurrentOrgId)
  441. c.ServeSuccessJSON(map[string]interface{}{
  442. "configlist": configList,
  443. })
  444. return
  445. }
  446. //CreateConfig 创建配置信息
  447. func (c *ManagerCenterApiController) CreateConfig() {
  448. adminUserInfo := c.GetAdminUserInfo()
  449. var dataconfig models.DictionaryDataconfig
  450. var resultConfig models.DictionaryConfigViewModel
  451. code := dictionaryConfigFormData(&dataconfig, c.Ctx.Input.RequestBody)
  452. if code > 0 {
  453. c.ServeFailJSONWithSGJErrorCode(code)
  454. return
  455. }
  456. // 验证关键字段的值是否重复
  457. thisConfig, _ := service.FindDictionaryConfigByTitle(dataconfig.Module, dataconfig.FieldName, adminUserInfo.CurrentOrgId)
  458. if thisConfig.ID > 0 {
  459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  460. return
  461. }
  462. fieldValue := service.GetDictionaryChildValue(dataconfig.Module, dataconfig.ParentId, adminUserInfo.CurrentOrgId)
  463. dataconfig.Value = fieldValue + 1
  464. dataBody := make(map[string]interface{}, 0)
  465. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  466. if err != nil {
  467. utils.ErrorLog(err.Error())
  468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  469. return
  470. }
  471. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  472. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  473. dataconfig.Status = 1
  474. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  475. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  476. dataconfig.Remark = string(dataBody["remark"].(string))
  477. if dataBody["order"] != nil {
  478. dataconfig.Order = int64(dataBody["order"].(float64))
  479. } else {
  480. dataconfig.Order = 0
  481. }
  482. err = service.CreateDictionaryConfig(&dataconfig)
  483. if err != nil {
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  485. return
  486. } else {
  487. resultConfig.ID = dataconfig.ID
  488. resultConfig.Module = dataconfig.Module
  489. resultConfig.Name = dataconfig.Name
  490. resultConfig.OrgId = dataconfig.OrgId
  491. resultConfig.ParentId = dataconfig.ParentId
  492. resultConfig.FieldName = dataconfig.FieldName
  493. resultConfig.CreateUserId = dataconfig.CreateUserId
  494. resultConfig.Title = dataconfig.Title
  495. resultConfig.Content = dataconfig.Content
  496. }
  497. c.ServeSuccessJSON(map[string]interface{}{
  498. "dataconfig": resultConfig,
  499. "msg": "ok",
  500. })
  501. return
  502. }
  503. func (c *ManagerCenterApiController) UpdateTemplate() {
  504. adminUserInfo := c.GetAdminUserInfo()
  505. var dataconfig models.DictionaryDataconfig
  506. code := dictionaryConfigFormData(&dataconfig, c.Ctx.Input.RequestBody)
  507. if code > 0 {
  508. c.ServeFailJSONWithSGJErrorCode(code)
  509. return
  510. }
  511. dataBody := make(map[string]interface{}, 0)
  512. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  513. if err != nil {
  514. utils.ErrorLog(err.Error())
  515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  516. return
  517. }
  518. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  519. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  520. dataconfig.Status = 1
  521. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  522. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  523. dataconfig.Remark = string(dataBody["remark"].(string))
  524. if dataBody["order"] != nil {
  525. dataconfig.Order = int64(dataBody["order"].(float64))
  526. } else {
  527. dataconfig.Order = 0
  528. }
  529. // 验证关键字段的值是否重复
  530. // cur_id := int64(dataBody["id"].(float64))
  531. // thisConfig,_:=service.FindConfigByTitleForUpdate(dataconfig.Module, dataconfig.Title,dataconfig.OrgId,cur_id)
  532. // if thisConfig.ID >0 {
  533. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  534. // return
  535. // }
  536. configOrgId := int64(dataBody["org_id"].(float64))
  537. if configOrgId == 0 {
  538. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  539. err := service.CreateDictionaryConfig(&dataconfig)
  540. if err != nil {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  542. return
  543. }
  544. } else {
  545. dataconfig.ID = int64(dataBody["id"].(float64))
  546. err = service.UpdateDictionaryTemplate(&dataconfig)
  547. if err != nil {
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  549. return
  550. }
  551. }
  552. c.ServeSuccessJSON(map[string]interface{}{
  553. "dataconfig": dataconfig,
  554. "msg": "ok",
  555. })
  556. return
  557. }
  558. func (c *ManagerCenterApiController) UpdateChildConfig() {
  559. adminUserInfo := c.GetAdminUserInfo()
  560. var dataconfig models.DictionaryDataconfig
  561. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  562. if code > 0 {
  563. c.ServeFailJSONWithSGJErrorCode(code)
  564. return
  565. }
  566. dataBody := make(map[string]interface{}, 0)
  567. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  568. if err != nil {
  569. utils.ErrorLog(err.Error())
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  571. return
  572. }
  573. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  574. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  575. dataconfig.Status = 1
  576. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  577. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  578. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  579. dataconfig.Remark = string(dataBody["remark"].(string))
  580. dataconfig.Order = int64(dataBody["orders"].(float64))
  581. fmt.Println("dataconfitg------", dataconfig.Order)
  582. //if dataBody["orders"] != nil {
  583. // dataconfig.Order = int64(dataBody["orders"].(float64))
  584. // fmt.Println("dataconfig",dataconfig.Order)
  585. //} else {
  586. // dataconfig.Order = 0
  587. //}
  588. configOrgId := int64(dataBody["org_id"].(float64))
  589. // 验证关键字段的值是否重复
  590. // configId := int64(dataBody["id"].(float64))
  591. // thisConfig,_:=service.FindConfigByNameForUpdate(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId,configId)
  592. // if thisConfig.ID >0 {
  593. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  594. // return
  595. // }
  596. if configOrgId == 0 {
  597. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  598. err := service.CreateDictionaryConfig(&dataconfig)
  599. if err != nil {
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  601. return
  602. }
  603. } else {
  604. dataconfig.ID = int64(dataBody["id"].(float64))
  605. err = service.UpdateDictionaryChildConfig(&dataconfig)
  606. if err != nil {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  608. return
  609. }
  610. }
  611. c.ServeSuccessJSON(map[string]interface{}{
  612. "dataconfig": dataconfig,
  613. "msg": "ok",
  614. })
  615. return
  616. }
  617. func (c *ManagerCenterApiController) DeleteChildConfig() {
  618. adminUserInfo := c.GetAdminUserInfo()
  619. var dataconfig models.DictionaryDataconfig
  620. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  621. if code > 0 {
  622. c.ServeFailJSONWithSGJErrorCode(code)
  623. return
  624. }
  625. dataBody := make(map[string]interface{}, 0)
  626. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  627. if err != nil {
  628. utils.ErrorLog(err.Error())
  629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  630. return
  631. }
  632. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  633. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  634. dataconfig.Status = 0
  635. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  636. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  637. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  638. dataconfig.Remark = string(dataBody["remark"].(string))
  639. if dataBody["order"] != nil {
  640. dataconfig.Order = int64(dataBody["order"].(float64))
  641. } else {
  642. dataconfig.Order = 0
  643. }
  644. configOrgId := int64(dataBody["org_id"].(float64))
  645. if configOrgId == 0 {
  646. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  647. err := service.CreateDictionaryConfig(&dataconfig)
  648. if err != nil {
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  650. return
  651. }
  652. } else {
  653. dataconfig.ID = int64(dataBody["id"].(float64))
  654. err := service.DeleteDictionaryChildConfig(&dataconfig)
  655. if err != nil {
  656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  657. return
  658. }
  659. }
  660. c.ServeSuccessJSON(map[string]interface{}{
  661. "dataconfig": dataconfig,
  662. "msg": "ok",
  663. })
  664. return
  665. }
  666. //CreateChildConfig 创建子配置信息
  667. func (c *ManagerCenterApiController) CreateChildConfig() {
  668. adminUserInfo := c.GetAdminUserInfo()
  669. var dataconfig models.DictionaryDataconfig
  670. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  671. if code > 0 {
  672. c.ServeFailJSONWithSGJErrorCode(code)
  673. return
  674. }
  675. dataBody := make(map[string]interface{}, 0)
  676. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  677. if err != nil {
  678. utils.ErrorLog(err.Error())
  679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  680. return
  681. }
  682. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  683. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  684. dataconfig.Status = 1
  685. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  686. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  687. dataconfig.Remark = string(dataBody["remark"].(string))
  688. if dataBody["order"] != nil {
  689. dataconfig.Order = int64(dataBody["order"].(float64))
  690. } else {
  691. dataconfig.Order = 0
  692. }
  693. // 验证关键字段的值是否重复
  694. // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
  695. // if thisConfig.ID >0 {
  696. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  697. // return
  698. // }
  699. fieldValue := service.GetDictionaryChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
  700. dataconfig.Value = fieldValue + 1
  701. err = service.CreateDictionaryConfig(&dataconfig)
  702. if err != nil {
  703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  704. return
  705. }
  706. c.ServeSuccessJSON(map[string]interface{}{
  707. "dataconfig": dataconfig,
  708. "msg": "ok",
  709. })
  710. return
  711. }
  712. func dictionaryConfigFormData(dataconfig *models.DictionaryDataconfig, data []byte) (code int) {
  713. configBody := make(map[string]interface{}, 0)
  714. err := json.Unmarshal(data, &configBody)
  715. utils.InfoLog(string(data))
  716. if err != nil {
  717. utils.ErrorLog(err.Error())
  718. code = enums.ErrorCodeParamWrong
  719. return
  720. }
  721. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  722. utils.ErrorLog("module")
  723. code = enums.ErrorCodeParamWrong
  724. return
  725. }
  726. module, _ := configBody["module"].(string)
  727. if len(module) == 0 {
  728. utils.ErrorLog("len(module) == 0")
  729. code = enums.ErrorCodeParamWrong
  730. return
  731. }
  732. dataconfig.Module = module
  733. if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" {
  734. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  735. utils.ErrorLog("title")
  736. code = enums.ErrorCodeParamWrong
  737. return
  738. }
  739. title, _ := configBody["title"].(string)
  740. if len(title) == 0 {
  741. utils.ErrorLog("len(title) == 0")
  742. code = enums.ErrorCodeParamWrong
  743. return
  744. }
  745. dataconfig.Title = title
  746. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  747. utils.ErrorLog("content")
  748. code = enums.ErrorCodeParamWrong
  749. return
  750. }
  751. content, _ := configBody["content"].(string)
  752. if len(content) == 0 {
  753. utils.ErrorLog("len(content) == 0")
  754. code = enums.ErrorCodeParamWrong
  755. return
  756. }
  757. dataconfig.Content = content
  758. } else {
  759. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  760. utils.ErrorLog("name")
  761. code = enums.ErrorCodeParamWrong
  762. return
  763. }
  764. name, _ := configBody["name"].(string)
  765. if len(name) == 0 {
  766. utils.ErrorLog("len(name) == 0")
  767. code = enums.ErrorCodeParamWrong
  768. return
  769. }
  770. dataconfig.Name = name
  771. if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
  772. utils.ErrorLog("field_name")
  773. code = enums.ErrorCodeParamWrong
  774. return
  775. }
  776. field_name, _ := configBody["field_name"].(string)
  777. if len(field_name) == 0 {
  778. utils.ErrorLog("len(field_name) == 0")
  779. code = enums.ErrorCodeParamWrong
  780. return
  781. }
  782. dataconfig.FieldName = field_name
  783. }
  784. return
  785. }
  786. func dictionaryConfigChildFormData(dataconfig *models.DictionaryDataconfig, data []byte) (code int) {
  787. configBody := make(map[string]interface{}, 0)
  788. err := json.Unmarshal(data, &configBody)
  789. utils.InfoLog(string(data))
  790. if err != nil {
  791. utils.ErrorLog(err.Error())
  792. code = enums.ErrorCodeParamWrong
  793. return
  794. }
  795. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  796. utils.ErrorLog("module")
  797. code = enums.ErrorCodeParamWrong
  798. return
  799. }
  800. module, _ := configBody["module"].(string)
  801. if len(module) == 0 {
  802. utils.ErrorLog("len(module) == 0")
  803. code = enums.ErrorCodeParamWrong
  804. return
  805. }
  806. dataconfig.Module = module
  807. if module == "education" || module == "summary" {
  808. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  809. utils.ErrorLog("title")
  810. code = enums.ErrorCodeParamWrong
  811. return
  812. }
  813. title, _ := configBody["title"].(string)
  814. if len(title) == 0 {
  815. utils.ErrorLog("len(title) == 0")
  816. code = enums.ErrorCodeParamWrong
  817. return
  818. }
  819. dataconfig.Title = title
  820. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  821. utils.ErrorLog("content")
  822. code = enums.ErrorCodeParamWrong
  823. return
  824. }
  825. content, _ := configBody["content"].(string)
  826. if len(content) == 0 {
  827. utils.ErrorLog("len(content) == 0")
  828. code = enums.ErrorCodeParamWrong
  829. return
  830. }
  831. dataconfig.Content = content
  832. } else {
  833. if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
  834. utils.ErrorLog("module")
  835. code = enums.ErrorCodeParamWrong
  836. return
  837. }
  838. parent_id := int64(configBody["parent_id"].(float64))
  839. if parent_id <= 0 {
  840. utils.ErrorLog("parent_id <= 0")
  841. code = enums.ErrorCodeParamWrong
  842. return
  843. }
  844. dataconfig.ParentId = parent_id
  845. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  846. utils.ErrorLog("name")
  847. code = enums.ErrorCodeParamWrong
  848. return
  849. }
  850. name, _ := configBody["name"].(string)
  851. if len(name) == 0 {
  852. utils.ErrorLog("len(name) == 0")
  853. code = enums.ErrorCodeParamWrong
  854. return
  855. }
  856. dataconfig.Name = name
  857. }
  858. return
  859. }
  860. func (c *ManagerCenterApiController) CreateDealer() {
  861. dealer_name := c.GetString("dealer_name")
  862. contact := c.GetString("contact")
  863. contact_phone := c.GetString("contact_phone")
  864. platform_number := c.GetString("platform_number")
  865. email := c.GetString("email")
  866. contact_address := c.GetString("contact_address")
  867. remark := c.GetString("remark")
  868. pinyin := c.GetString("pinyin")
  869. wubi := c.GetString("wubi")
  870. if len(dealer_name) <= 0 {
  871. utils.ErrorLog("len(dealer_name) == 0")
  872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. return
  874. }
  875. adminUserInfo := c.GetAdminUserInfo()
  876. total := service.FindAllDealerTotal(adminUserInfo.CurrentOrgId)
  877. totalStr := strconv.FormatInt(total+1, 10)
  878. code := "1000" + totalStr
  879. dealer := models.Dealer{
  880. DealerName: dealer_name,
  881. Contact: contact,
  882. ContactPhone: contact_phone,
  883. ContactAddress: contact_address,
  884. DealerCode: code,
  885. Ctime: time.Now().Unix(),
  886. Mtime: time.Now().Unix(),
  887. Remark: remark,
  888. Creater: adminUserInfo.AdminUser.Id,
  889. Email: email,
  890. PlatformNumber: platform_number,
  891. OrgId: adminUserInfo.CurrentOrgId,
  892. Status: 1,
  893. PinYin: pinyin,
  894. WuBi: wubi,
  895. }
  896. err, dealers := service.AddSigleDealer(&dealer)
  897. if err == nil {
  898. c.ServeSuccessJSON(map[string]interface{}{
  899. "dealer": dealers,
  900. })
  901. } else {
  902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  903. }
  904. }
  905. func (c *ManagerCenterApiController) ModifyDealer() {
  906. id, _ := c.GetInt64("id", 0)
  907. dealer_name := c.GetString("dealer_name")
  908. contact := c.GetString("contact")
  909. contact_phone := c.GetString("contact_phone")
  910. platform_number := c.GetString("platform_number")
  911. dealer_code := c.GetString("dealer_code")
  912. email := c.GetString("email")
  913. contact_address := c.GetString("contact_address")
  914. remark := c.GetString("remark")
  915. pinyin := c.GetString("pinyin")
  916. wubi := c.GetString("wubi")
  917. if id <= 0 {
  918. utils.ErrorLog("id == 0")
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. if len(dealer_name) <= 0 {
  923. utils.ErrorLog("len(dealer_name) == 0")
  924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  925. return
  926. }
  927. adminUserInfo := c.GetAdminUserInfo()
  928. dealer := models.Dealer{
  929. ID: id,
  930. DealerName: dealer_name,
  931. Contact: contact,
  932. ContactPhone: contact_phone,
  933. ContactAddress: contact_address,
  934. Mtime: time.Now().Unix(),
  935. DealerCode: dealer_code,
  936. Remark: remark,
  937. Creater: adminUserInfo.AdminUser.Id,
  938. Email: email,
  939. PlatformNumber: platform_number,
  940. Modifier: adminUserInfo.AdminUser.Id,
  941. OrgId: adminUserInfo.CurrentOrgId,
  942. Status: 1,
  943. PinYin: pinyin,
  944. WuBi: wubi,
  945. }
  946. err := service.ModifyDealer(&dealer)
  947. if err == nil {
  948. c.ServeSuccessJSON(map[string]interface{}{
  949. "dealer": dealer,
  950. })
  951. } else {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  953. }
  954. }
  955. func (c *ManagerCenterApiController) GetDealersList() {
  956. page, _ := c.GetInt64("page", 1)
  957. limit, _ := c.GetInt64("limit", 7)
  958. adminUserInfo := c.GetAdminUserInfo()
  959. deales, total, err := service.FindAllDealerList(adminUserInfo.CurrentOrgId, page, limit)
  960. if err == nil {
  961. c.ServeSuccessJSON(map[string]interface{}{
  962. "dealer": deales,
  963. "total": total,
  964. })
  965. } else {
  966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  967. }
  968. }
  969. func (c *ManagerCenterApiController) DeleteDealer() {
  970. id, _ := c.GetInt64("id", 0)
  971. total, _ := service.FindStockInByDealerId(id)
  972. if total > 0 {
  973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteDealerWrong)
  974. return
  975. }
  976. err := service.DeleteDealerById(id)
  977. if err == nil {
  978. c.ServeSuccessJSON(map[string]interface{}{
  979. "msg": "删除成功",
  980. })
  981. } else {
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  983. }
  984. }
  985. func (c *ManagerCenterApiController) GetDealer() {
  986. id, _ := c.GetInt64("id", 0)
  987. dealer, err := service.FindDealerById(id)
  988. if err == nil {
  989. c.ServeSuccessJSON(map[string]interface{}{
  990. "dealer": dealer,
  991. })
  992. } else {
  993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  994. }
  995. }
  996. func (c *ManagerCenterApiController) CreateManufacturer() {
  997. manufacturer_name := c.GetString("manufacturer_name")
  998. contact := c.GetString("contact")
  999. contact_phone := c.GetString("contact_phone")
  1000. platform_number := c.GetString("platform_number")
  1001. email := c.GetString("email")
  1002. contact_address := c.GetString("contact_address")
  1003. remark := c.GetString("remark")
  1004. pinyin := c.GetString("pinyin")
  1005. wubi := c.GetString("wubi")
  1006. if len(manufacturer_name) <= 0 {
  1007. utils.ErrorLog("len(manufacturer_name) == 0")
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. adminUserInfo := c.GetAdminUserInfo()
  1012. total := service.FindManufacturerTotal(adminUserInfo.CurrentOrgId)
  1013. totalStr := strconv.FormatInt(total+1, 10)
  1014. code := "2000" + totalStr
  1015. manufacturer := models.Manufacturer{
  1016. ManufacturerName: manufacturer_name,
  1017. Contact: contact,
  1018. ContactPhone: contact_phone,
  1019. ContactAddress: contact_address,
  1020. Ctime: time.Now().Unix(),
  1021. Mtime: time.Now().Unix(),
  1022. Remark: remark,
  1023. Creater: adminUserInfo.AdminUser.Id,
  1024. Email: email,
  1025. PlatformNumber: platform_number,
  1026. OrgId: adminUserInfo.CurrentOrgId,
  1027. Status: 1,
  1028. ManufacturerCode: code,
  1029. PinYin: pinyin,
  1030. WuBi: wubi,
  1031. }
  1032. err, manufacturers := service.AddSigleManufacturer(&manufacturer)
  1033. if err == nil {
  1034. c.ServeSuccessJSON(map[string]interface{}{
  1035. "manufacturer": manufacturers,
  1036. })
  1037. } else {
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1039. }
  1040. }
  1041. func (c *ManagerCenterApiController) ModifyManufacturer() {
  1042. id, _ := c.GetInt64("id", 0)
  1043. manufacturer_name := c.GetString("manufacturer_name")
  1044. contact := c.GetString("contact")
  1045. contact_phone := c.GetString("contact_phone")
  1046. platform_number := c.GetString("platform_number")
  1047. email := c.GetString("email")
  1048. contact_address := c.GetString("contact_address")
  1049. remark := c.GetString("remark")
  1050. manufacturer_code := c.GetString("manufacturer_code")
  1051. pinyin := c.GetString("pinyin")
  1052. wubi := c.GetString("wubi")
  1053. if id <= 0 {
  1054. utils.ErrorLog("id == 0")
  1055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1056. return
  1057. }
  1058. if len(manufacturer_name) <= 0 {
  1059. utils.ErrorLog("len(manufacturer_name) == 0")
  1060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1061. return
  1062. }
  1063. adminUserInfo := c.GetAdminUserInfo()
  1064. manufacturer := models.Manufacturer{
  1065. ID: id,
  1066. ManufacturerName: manufacturer_name,
  1067. Contact: contact,
  1068. ContactPhone: contact_phone,
  1069. ContactAddress: contact_address,
  1070. Mtime: time.Now().Unix(),
  1071. Remark: remark,
  1072. Creater: adminUserInfo.AdminUser.Id,
  1073. Email: email,
  1074. PlatformNumber: platform_number,
  1075. Modifier: adminUserInfo.AdminUser.Id,
  1076. OrgId: adminUserInfo.CurrentOrgId,
  1077. ManufacturerCode: manufacturer_code,
  1078. Status: 1,
  1079. PinYin: pinyin,
  1080. WuBi: wubi,
  1081. }
  1082. err := service.ModifyManufacturer(&manufacturer)
  1083. if err == nil {
  1084. c.ServeSuccessJSON(map[string]interface{}{
  1085. "manufacturer": manufacturer,
  1086. })
  1087. } else {
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1089. }
  1090. }
  1091. func (c *ManagerCenterApiController) GetManufacturerList() {
  1092. page, _ := c.GetInt64("page", 1)
  1093. limit, _ := c.GetInt64("limit", 10)
  1094. adminUserInfo := c.GetAdminUserInfo()
  1095. manufacturer, total, err := service.FindAllManufacturerList(adminUserInfo.CurrentOrgId, page, limit)
  1096. if err == nil {
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "manufacturer": manufacturer,
  1099. "total": total,
  1100. })
  1101. } else {
  1102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1103. }
  1104. }
  1105. func (c *ManagerCenterApiController) DeleteManufacturer() {
  1106. id, _ := c.GetInt64("id", 0)
  1107. total, _ := service.FindStockInByManufacturerId(id)
  1108. if total > 0 {
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteManufacturerWrong)
  1110. return
  1111. }
  1112. err := service.DeleteManufacturerById(id)
  1113. if err == nil {
  1114. c.ServeSuccessJSON(map[string]interface{}{
  1115. "msg": "删除成功",
  1116. })
  1117. } else {
  1118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1119. }
  1120. }
  1121. func (c *ManagerCenterApiController) GetManufacturer() {
  1122. id, _ := c.GetInt64("id", 0)
  1123. manufacturer, err := service.FindManufacturerById(id)
  1124. if err == nil {
  1125. c.ServeSuccessJSON(map[string]interface{}{
  1126. "manufacturer": manufacturer,
  1127. })
  1128. } else {
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1130. }
  1131. }
  1132. func (c *ManagerCenterApiController) GetAllDealer() {
  1133. adminUserInfo := c.GetAdminUserInfo()
  1134. dealer, err := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1135. if err == nil {
  1136. c.ServeSuccessJSON(map[string]interface{}{
  1137. "dealer": dealer,
  1138. })
  1139. } else {
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1141. }
  1142. }
  1143. func (c *ManagerCenterApiController) GetAllManufacturer() {
  1144. adminUserInfo := c.GetAdminUserInfo()
  1145. manufacturer, err := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1146. if err == nil {
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "manufacturer": manufacturer,
  1149. })
  1150. } else {
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1152. }
  1153. }
  1154. func (c *ManagerCenterApiController) CreateGoodInfo() {
  1155. good_id, _ := c.GetInt64("good_id", 0)
  1156. specification_name := c.GetString("specification_name")
  1157. good_unit, _ := c.GetInt64("good_unit", -1)
  1158. buy_price, _ := c.GetFloat("buy_price", 0)
  1159. sell_price, _ := c.GetFloat("sell_price", 0)
  1160. remark := c.GetString("remark")
  1161. manufacturer, _ := c.GetInt64("manufacturer", 0)
  1162. dealer, _ := c.GetInt64("dealer", 0)
  1163. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  1164. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  1165. is_reuse, _ := c.GetInt64("is_reuse", 0)
  1166. good_name := c.GetString("good_name")
  1167. pinyin := c.GetString("pinyin")
  1168. wubi := c.GetString("wubi")
  1169. good_kind, _ := c.GetInt64("good_kind", 0)
  1170. medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
  1171. retail_price, _ := c.GetFloat("retail_price", 0)
  1172. medical_insurance_number := c.GetString("medical_insurance_number")
  1173. is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
  1174. is_record, _ := c.GetInt64("is_record")
  1175. statistics_category, _ := c.GetInt64("statistics_category")
  1176. good_status := c.GetString("good_status")
  1177. default_count, _ := c.GetInt64("default_count")
  1178. sign, _ := c.GetInt64("sign")
  1179. is_default, _ := c.GetInt64("is_default")
  1180. is_charge_use, _ := c.GetInt64("is_charge_use")
  1181. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  1182. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  1183. sort, _ := c.GetInt64("sort")
  1184. is_doctor_use, _ := c.GetInt64("is_doctor_use")
  1185. agent := c.GetString("agent")
  1186. good_number := c.GetString("good_number")
  1187. adminUserInfo := c.GetAdminUserInfo()
  1188. totals := service.FindGoodInfoByName(specification_name, adminUserInfo.CurrentOrgId)
  1189. if totals > 0 {
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  1191. return
  1192. }
  1193. total := service.FindAllGoodInfoTotal(adminUserInfo.CurrentOrgId)
  1194. code := strconv.FormatInt(total+1, 10)
  1195. code = "24000000" + code
  1196. goodInfo := models.GoodInfo{
  1197. GoodCode: code,
  1198. SpecificationName: specification_name,
  1199. GoodTypeId: good_id,
  1200. GoodUnit: good_unit,
  1201. BuyPrice: buy_price,
  1202. SellPrice: sell_price,
  1203. Remark: remark,
  1204. Ctime: time.Now().Unix(),
  1205. Manufacturer: manufacturer,
  1206. Dealer: dealer,
  1207. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  1208. StockWarnCount: stock_warn_count,
  1209. IsReuse: is_reuse,
  1210. Status: 1,
  1211. OrgId: adminUserInfo.CurrentOrgId,
  1212. Creater: adminUserInfo.AdminUser.Id,
  1213. GoodName: good_name,
  1214. Pinyin: pinyin,
  1215. Wubi: wubi,
  1216. GoodKind: good_kind,
  1217. MedicalInsuranceNumber: medical_insurance_number,
  1218. IsSpecialDiseases: is_special_diseases,
  1219. IsRecord: is_record,
  1220. StatisticsCategory: statistics_category,
  1221. GoodStatus: good_status,
  1222. DefaultCount: default_count,
  1223. Sign: sign,
  1224. IsDefault: is_default,
  1225. IsChargeUse: is_charge_use,
  1226. IsChargePredict: is_charge_predict,
  1227. IsStatisticsWork: is_statistics_work,
  1228. Sort: sort,
  1229. IsDoctorUse: is_doctor_use,
  1230. Agent: agent,
  1231. GoodNumber: good_number,
  1232. MedicalInsuranceLevel: medical_insurance_level,
  1233. RetailPrice: retail_price,
  1234. }
  1235. err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
  1236. if err == nil {
  1237. c.ServeSuccessJSON(map[string]interface{}{
  1238. "goodInfo": goodInfos,
  1239. })
  1240. } else {
  1241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1242. }
  1243. }
  1244. func (c *ManagerCenterApiController) ModifyGoodInfo() {
  1245. id, _ := c.GetInt64("id", 0)
  1246. good_id, _ := c.GetInt64("good_id", 0)
  1247. specification_name := c.GetString("specification_name")
  1248. good_unit, _ := c.GetInt64("good_unit", -1)
  1249. buy_price, _ := c.GetFloat("buy_price", 0)
  1250. sell_price, _ := c.GetFloat("sell_price", 0)
  1251. remark := c.GetString("remark")
  1252. manufacturer, _ := c.GetInt64("manufacturer", 0)
  1253. dealer, _ := c.GetInt64("dealer", 0)
  1254. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  1255. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  1256. is_reuse, _ := c.GetInt64("is_reuse", 0)
  1257. code := c.GetString("good_code")
  1258. good_name := c.GetString("good_name")
  1259. pinyin := c.GetString("pinyin")
  1260. wubi := c.GetString("wubi")
  1261. good_kind, _ := c.GetInt64("good_kind", 0)
  1262. medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
  1263. retail_price, _ := c.GetFloat("retail_price", 0)
  1264. medical_insurance_number := c.GetString("medical_insurance_number")
  1265. is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
  1266. is_record, _ := c.GetInt64("is_record")
  1267. statistics_category, _ := c.GetInt64("statistics_category")
  1268. good_status := c.GetString("good_status")
  1269. default_count, _ := c.GetInt64("default_count")
  1270. sign, _ := c.GetInt64("sign")
  1271. is_default, _ := c.GetInt64("is_default")
  1272. is_charge_use, _ := c.GetInt64("is_charge_use")
  1273. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  1274. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  1275. sort, _ := c.GetInt64("sort")
  1276. is_doctor_use, _ := c.GetInt64("is_doctor_use")
  1277. agent := c.GetString("agent")
  1278. good_number := c.GetString("good_number")
  1279. adminUserInfo := c.GetAdminUserInfo()
  1280. goodInfo := models.GoodInfo{
  1281. ID: id,
  1282. GoodCode: code,
  1283. SpecificationName: specification_name,
  1284. GoodTypeId: good_id,
  1285. GoodUnit: good_unit,
  1286. BuyPrice: buy_price,
  1287. SellPrice: sell_price,
  1288. Remark: remark,
  1289. Mtime: time.Now().Unix(),
  1290. Manufacturer: manufacturer,
  1291. Dealer: dealer,
  1292. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  1293. StockWarnCount: stock_warn_count,
  1294. IsReuse: is_reuse,
  1295. Status: 1,
  1296. OrgId: adminUserInfo.CurrentOrgId,
  1297. Modifier: adminUserInfo.AdminUser.Id,
  1298. GoodName: good_name,
  1299. Pinyin: pinyin,
  1300. Wubi: wubi,
  1301. GoodKind: good_kind,
  1302. MedicalInsuranceNumber: medical_insurance_number,
  1303. IsSpecialDiseases: is_special_diseases,
  1304. IsRecord: is_record,
  1305. StatisticsCategory: statistics_category,
  1306. GoodStatus: good_status,
  1307. DefaultCount: default_count,
  1308. Sign: sign,
  1309. IsDefault: is_default,
  1310. IsChargeUse: is_charge_use,
  1311. IsChargePredict: is_charge_predict,
  1312. IsStatisticsWork: is_statistics_work,
  1313. Sort: sort,
  1314. IsDoctorUse: is_doctor_use,
  1315. Agent: agent,
  1316. GoodNumber: good_number,
  1317. MedicalInsuranceLevel: medical_insurance_level,
  1318. RetailPrice: retail_price,
  1319. }
  1320. err, goodInfos := service.ModifyGoodInfo(&goodInfo)
  1321. if err == nil {
  1322. c.ServeSuccessJSON(map[string]interface{}{
  1323. "goodInfo": goodInfos,
  1324. })
  1325. } else {
  1326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1327. }
  1328. }
  1329. func (c *ManagerCenterApiController) GetGoodInfoList() {
  1330. page, _ := c.GetInt64("page", 1)
  1331. limit, _ := c.GetInt64("limit", 7)
  1332. keyword := c.GetString("keyword")
  1333. is_use, _ := c.GetInt64("is_use")
  1334. is_charge, _ := c.GetInt64("is_charge")
  1335. good_kind, _ := c.GetInt64("good_kind")
  1336. adminUserInfo := c.GetAdminUserInfo()
  1337. goodInfos, total, err := service.FindGoodInfoList(adminUserInfo.CurrentOrgId, page, limit, keyword, is_use, is_charge, good_kind)
  1338. if err == nil {
  1339. c.ServeSuccessJSON(map[string]interface{}{
  1340. "list": goodInfos,
  1341. "total": total,
  1342. })
  1343. } else {
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1345. }
  1346. }
  1347. func (c *ManagerCenterApiController) DeleteGoodInfo() {
  1348. id, _ := c.GetInt64("id", 0)
  1349. adminUserInfo := c.GetAdminUserInfo()
  1350. total, _ := service.FindWarehouseInfoTotalByGoodId(id)
  1351. total2, _ := service.FindWarehouseOutInfoTotalByGoodId(id)
  1352. if total > 0 {
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  1354. return
  1355. }
  1356. if total2 > 0 {
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  1358. return
  1359. }
  1360. err := service.DeleteGoodInfoById(id, adminUserInfo.AdminUser.Id)
  1361. if err == nil {
  1362. c.ServeSuccessJSON(map[string]interface{}{
  1363. "msg": "删除成功",
  1364. })
  1365. } else {
  1366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1367. }
  1368. }
  1369. func (c *ManagerCenterApiController) GetGoodInfoByGoodId() {
  1370. id, _ := c.GetInt64("id", 0)
  1371. goodInfo, err := service.FindGoodInfoByGoodId(id)
  1372. if err == nil {
  1373. c.ServeSuccessJSON(map[string]interface{}{
  1374. "list": goodInfo,
  1375. })
  1376. } else {
  1377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1378. }
  1379. }
  1380. func (c *ManagerCenterApiController) GetGoodInfoById() {
  1381. id, _ := c.GetInt64("id", 0)
  1382. goodInfo, err := service.FindGoodInfoById(id)
  1383. if err == nil {
  1384. c.ServeSuccessJSON(map[string]interface{}{
  1385. "goodInfo": goodInfo,
  1386. })
  1387. } else {
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1389. }
  1390. }
  1391. func (c *ManagerCenterApiController) GetMedicineInsurancePercent() {
  1392. adminUser := c.GetAdminUserInfo()
  1393. type_id, _ := c.GetInt64("type_id", 0)
  1394. module, _ := c.GetInt64("module", 0)
  1395. mip, err := service.GetLastMedicineInsurance(adminUser.CurrentOrgId, type_id, module)
  1396. if err == nil {
  1397. c.ServeSuccessJSON(map[string]interface{}{
  1398. "mip": mip,
  1399. })
  1400. } else {
  1401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1402. }
  1403. }