manager_center_api_controller.go 50KB

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