manager_center_api_controller.go 60KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  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. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "time"
  14. )
  15. type ManagerCenterApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func ManagerCenterRegistRouters() {
  19. //药品基础库
  20. beego.Router("/api/basedruglib/create", &ManagerCenterApiController{}, "post:CreateBaseDrugLib")
  21. beego.Router("/api/basedruglib/edit", &ManagerCenterApiController{}, "post:EditBaseDrugLib")
  22. beego.Router("/api/basedruglib/get", &ManagerCenterApiController{}, "get:GetBaseDrugLib")
  23. beego.Router("/api/basedruglib/list", &ManagerCenterApiController{}, "get:GetBaseDrugLibList")
  24. beego.Router("/api/medicineinsurancepercent/create", &ManagerCenterApiController{}, "post:CreateMedicineInsurancePercent")
  25. beego.Router("/api/drugunitsafeguard/create", &ManagerCenterApiController{}, "post:CreateDrugUnitSafeguard")
  26. beego.Router("/api/medicineinsurancepercent/get", &ManagerCenterApiController{}, "get:GetMedicineInsurancePercent")
  27. //beego.Router("/api/drugunitsafeguard/get", &ManagerCenterApiController{}, "get:GetDrugUnitSafeguard")
  28. beego.Router("/api/drug/basedruglib", &ManagerCenterApiController{}, "get:DeleteBaseDrugById")
  29. //专项字典
  30. beego.Router("/api/dictionary/getconfiglist", &ManagerCenterApiController{}, "get,post:GetConfigList")
  31. beego.Router("/api/dictionary/createconfig", &ManagerCenterApiController{}, "Post:CreateConfig")
  32. beego.Router("/api/dictionary/createchildconfig", &ManagerCenterApiController{}, "Post:CreateChildConfig")
  33. beego.Router("/api/dictionary/updatechildconfig", &ManagerCenterApiController{}, "Post:UpdateChildConfig")
  34. beego.Router("/api/dictionary/deletechildconfig", &ManagerCenterApiController{}, "Post:DeleteChildConfig")
  35. beego.Router("/api/dictionary/updatetemplate", &ManagerCenterApiController{}, "Post:UpdateTemplate")
  36. //经销商
  37. beego.Router("/api/stock/dealer/create", &ManagerCenterApiController{}, "post:CreateDealer")
  38. beego.Router("/api/stock/dealer/modify", &ManagerCenterApiController{}, "post:ModifyDealer")
  39. beego.Router("/api/stock/dealer/list", &ManagerCenterApiController{}, "get:GetDealersList")
  40. beego.Router("/api/stock/dealer/delete", &ManagerCenterApiController{}, "post:DeleteDealer")
  41. beego.Router("/api/stock/dealer/get", &ManagerCenterApiController{}, "get:GetDealer")
  42. //厂商
  43. beego.Router("/api/stock/manufacturer/create", &ManagerCenterApiController{}, "post:CreateManufacturer")
  44. beego.Router("/api/stock/manufacturer/modify", &ManagerCenterApiController{}, "post:ModifyManufacturer")
  45. beego.Router("/api/stock/manufacturer/list", &ManagerCenterApiController{}, "get:GetManufacturerList")
  46. beego.Router("/api/stock/manufacturer/delete", &ManagerCenterApiController{}, "post:DeleteManufacturer")
  47. beego.Router("/api/stock/manufacturer/get", &ManagerCenterApiController{}, "get:GetManufacturer")
  48. beego.Router("/api/stock/good/info/create", &ManagerCenterApiController{}, "post:CreateGoodInfo")
  49. beego.Router("/api/stock/good/info/modify", &ManagerCenterApiController{}, "post:ModifyGoodInfo")
  50. beego.Router("/api/stock/good/info/list", &ManagerCenterApiController{}, "get:GetGoodInfoList")
  51. beego.Router("/api/info/delete", &ManagerCenterApiController{}, "post:DeleteGoodInfo")
  52. beego.Router("/api/stock/good/info/get", &ManagerCenterApiController{}, "get:GetGoodInfoByGoodId")
  53. beego.Router("/api/stock/good/info", &ManagerCenterApiController{}, "get:GetGoodInfoById")
  54. //门诊大病
  55. beego.Router("/api/mz/sick/create", &ManagerCenterApiController{}, "post:CreateMZSick")
  56. beego.Router("/api/mz/sick/modify", &ManagerCenterApiController{}, "post:ModifyMZSick")
  57. beego.Router("/api/mz/sick/list", &ManagerCenterApiController{}, "get:GetMZSickList")
  58. beego.Router("/api/mz/sick/delete", &ManagerCenterApiController{}, "post:DeleteMZSick")
  59. beego.Router("/api/mz/sick/get", &ManagerCenterApiController{}, "get:GetMZSick")
  60. beego.Router("/api/addition/create", &ManagerCenterApiController{}, "post:CreateAddition")
  61. beego.Router("/api/addition/modify", &ManagerCenterApiController{}, "post:ModifyAddition")
  62. beego.Router("/api/addition/list", &ManagerCenterApiController{}, "get:GetAdditionList")
  63. beego.Router("/api/addition/delete", &ManagerCenterApiController{}, "post:DeleteAddition")
  64. beego.Router("/api/addition/get", &ManagerCenterApiController{}, "get:GetAddition")
  65. }
  66. func (c *ManagerCenterApiController) CreateBaseDrugLib() {
  67. drug_name := c.GetString("drug_name")
  68. pinyin := c.GetString("pinyin")
  69. wubi := c.GetString("wubi")
  70. drug_alias := c.GetString("drug_alias")
  71. drug_alias_pinyin := c.GetString("drug_alias_pinyin")
  72. drug_alias_wubi := c.GetString("drug_alias_wubi")
  73. drug_category, _ := c.GetInt64("drug_category")
  74. drug_spec := c.GetString("drug_spec")
  75. drug_type, _ := c.GetInt64("drug_type")
  76. drug_stock_limit := c.GetString("drug_stock_limit")
  77. drug_origin_place := c.GetString("drug_origin_place")
  78. drug_dosage_form, _ := c.GetInt64("drug_dosage_form")
  79. medical_insurance_level, _ := c.GetInt64("medical_insurance_level")
  80. max_unit := c.GetString("max_unit")
  81. min_unit := c.GetString("min_unit")
  82. unit_matrixing := c.GetString("unit_matrixing")
  83. retail_price, _ := c.GetFloat("retail_price")
  84. last_price, _ := c.GetFloat("last_price")
  85. drug_control, _ := c.GetInt64("drug_control")
  86. number := c.GetString("number")
  87. drug_classify := c.GetString("drug_classify")
  88. drug_dose, _ := c.GetFloat("drug_dose")
  89. drug_dose_unit, _ := c.GetInt64("drug_dose_unit")
  90. medical_insurance_number := c.GetString("medical_insurance_number")
  91. manufacturer, _ := c.GetInt64("manufacturer")
  92. pharmacology_category, _ := c.GetInt64("pharmacology_category")
  93. statistics_category, _ := c.GetInt64("statistics_category")
  94. code := c.GetString("code")
  95. is_special_diseases, _ := c.GetInt64("is_special_diseases")
  96. is_record, _ := c.GetInt64("is_record")
  97. agent := c.GetString("agent")
  98. drug_status := c.GetString("drug_status")
  99. limit_remark := c.GetString("limit_remark")
  100. delivery_way := c.GetString("delivery_way")
  101. execution_frequency := c.GetString("execution_frequency")
  102. single_dose, _ := c.GetFloat("single_dose")
  103. prescribing_number, _ := c.GetFloat("prescribing_number")
  104. label, _ := c.GetInt64("label")
  105. sort, _ := c.GetInt64("sort")
  106. is_use_doctor_advice, _ := c.GetInt64("is_use_doctor_advice")
  107. is_default, _ := c.GetInt64("is_default")
  108. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  109. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  110. is_charge_use, _ := c.GetInt64("is_charge_use")
  111. adminInfo := c.GetAdminUserInfo()
  112. drugLib := &models.BaseDrugLib{
  113. DrugName: drug_name,
  114. Pinyin: pinyin,
  115. Wubi: wubi,
  116. DrugAlias: drug_alias,
  117. DrugAliasPinyin: drug_alias_pinyin,
  118. DrugAliasWubi: drug_alias_wubi,
  119. DrugCategory: drug_category,
  120. DrugSpec: drug_spec,
  121. DrugType: drug_type,
  122. DrugStockLimit: drug_stock_limit,
  123. DrugOriginPlace: drug_origin_place,
  124. MedicalInsuranceLevel: medical_insurance_level,
  125. DrugDosageForm: drug_dosage_form,
  126. MaxUnit: max_unit,
  127. MinUnit: min_unit,
  128. UnitMatrixing: unit_matrixing,
  129. RetailPrice: retail_price,
  130. LastPrice: last_price,
  131. DrugControl: drug_control,
  132. Number: number,
  133. DrugClassify: drug_classify,
  134. DrugDose: drug_dose,
  135. DrugDoseUnit: drug_dose_unit,
  136. MedicalInsuranceNumber: medical_insurance_number,
  137. Manufacturer: manufacturer,
  138. PharmacologyCategory: pharmacology_category,
  139. StatisticsCategory: statistics_category,
  140. Code: code,
  141. IsSpecialDiseases: is_special_diseases,
  142. IsRecord: is_record,
  143. Agent: agent,
  144. DrugStatus: drug_status,
  145. LimitRemark: limit_remark,
  146. DeliveryWay: delivery_way,
  147. ExecutionFrequency: execution_frequency,
  148. SingleDose: single_dose,
  149. PrescribingNumber: prescribing_number,
  150. Label: label,
  151. Sort: sort,
  152. IsUseDoctorAdvice: is_use_doctor_advice,
  153. IsDefault: is_default,
  154. IsChargePredict: is_charge_predict,
  155. IsStatisticsWork: is_statistics_work,
  156. IsChargeUse: is_charge_use,
  157. OrgId: adminInfo.CurrentOrgId,
  158. Status: 1,
  159. Ctime: time.Now().Unix(),
  160. Mtime: time.Now().Unix(),
  161. }
  162. total := service.FindAllDrugLibRecordTotal(adminInfo.CurrentOrgId)
  163. drug_code := strconv.FormatInt(total+1, 10)
  164. drug_code = "54000000" + drug_code
  165. drugLib.DrugCode = drug_code
  166. count := service.FindBaseDrugLibRecordCount(drugLib)
  167. if count == 0 {
  168. err := service.CreateBaseDrugLib(drugLib)
  169. if err == nil {
  170. c.ServeSuccessJSON(map[string]interface{}{
  171. "msg": "创建成功",
  172. })
  173. } else {
  174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  175. return
  176. }
  177. return
  178. } else {
  179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDrugRepeatDataException)
  180. return
  181. }
  182. }
  183. func (c *ManagerCenterApiController) EditBaseDrugLib() {
  184. id, _ := c.GetInt64("id")
  185. drug_name := c.GetString("drug_name")
  186. pinyin := c.GetString("pinyin")
  187. wubi := c.GetString("wubi")
  188. drug_alias := c.GetString("drug_alias")
  189. drug_alias_pinyin := c.GetString("drug_alias_pinyin")
  190. drug_alias_wubi := c.GetString("drug_alias_wubi")
  191. drug_category, _ := c.GetInt64("drug_category")
  192. drug_spec := c.GetString("drug_spec")
  193. drug_type, _ := c.GetInt64("drug_type")
  194. drug_stock_limit := c.GetString("drug_stock_limit")
  195. drug_origin_place := c.GetString("drug_origin_place")
  196. drug_dosage_form, _ := c.GetInt64("drug_dosage_form")
  197. medical_insurance_level, _ := c.GetInt64("medical_insurance_level")
  198. max_unit := c.GetString("max_unit")
  199. min_unit := c.GetString("min_unit")
  200. unit_matrixing := c.GetString("unit_matrixing")
  201. retail_price, _ := c.GetFloat("retail_price")
  202. last_price, _ := c.GetFloat("last_price")
  203. drug_control, _ := c.GetInt64("drug_control")
  204. number := c.GetString("number")
  205. drug_classify := c.GetString("drug_classify")
  206. drug_dose, _ := c.GetFloat("drug_dose")
  207. drug_dose_unit, _ := c.GetInt64("drug_dose_unit")
  208. medical_insurance_number := c.GetString("medical_insurance_number")
  209. manufacturer, _ := c.GetInt64("manufacturer")
  210. pharmacology_category, _ := c.GetInt64("pharmacology_category")
  211. statistics_category, _ := c.GetInt64("statistics_category")
  212. code := c.GetString("code")
  213. is_special_diseases, _ := c.GetInt64("is_special_diseases")
  214. is_record, _ := c.GetInt64("is_record")
  215. agent := c.GetString("agent")
  216. drug_status := c.GetString("drug_status")
  217. limit_remark := c.GetString("limit_remark")
  218. delivery_way := c.GetString("delivery_way")
  219. execution_frequency := c.GetString("execution_frequency")
  220. single_dose, _ := c.GetFloat("single_dose")
  221. prescribing_number, _ := c.GetFloat("prescribing_number")
  222. label, _ := c.GetInt64("label")
  223. sort, _ := c.GetInt64("sort")
  224. is_use_doctor_advice, _ := c.GetInt64("is_use_doctor_advice")
  225. is_default, _ := c.GetInt64("is_default")
  226. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  227. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  228. is_charge_use, _ := c.GetInt64("is_charge_use")
  229. drug_code := c.GetString("drug_code")
  230. //unit := c.GetString("unit")
  231. adminInfo := c.GetAdminUserInfo()
  232. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
  233. drugLib := &models.BaseDrugLib{
  234. ID: id,
  235. DrugName: drug_name,
  236. Pinyin: pinyin,
  237. Wubi: wubi,
  238. DrugAlias: drug_alias,
  239. DrugAliasPinyin: drug_alias_pinyin,
  240. DrugAliasWubi: drug_alias_wubi,
  241. DrugCategory: drug_category,
  242. DrugSpec: drug_spec,
  243. DrugType: drug_type,
  244. DrugStockLimit: drug_stock_limit,
  245. DrugOriginPlace: drug_origin_place,
  246. MedicalInsuranceLevel: medical_insurance_level,
  247. DrugDosageForm: drug_dosage_form,
  248. MaxUnit: max_unit,
  249. MinUnit: min_unit,
  250. UnitMatrixing: unit_matrixing,
  251. RetailPrice: retail_price,
  252. LastPrice: last_price,
  253. DrugControl: drug_control,
  254. Number: number,
  255. DrugClassify: drug_classify,
  256. DrugDose: drug_dose,
  257. DrugDoseUnit: drug_dose_unit,
  258. MedicalInsuranceNumber: medical_insurance_number,
  259. Manufacturer: manufacturer,
  260. PharmacologyCategory: pharmacology_category,
  261. StatisticsCategory: statistics_category,
  262. Code: code,
  263. IsSpecialDiseases: is_special_diseases,
  264. IsRecord: is_record,
  265. Agent: agent,
  266. DrugStatus: drug_status,
  267. LimitRemark: limit_remark,
  268. DeliveryWay: delivery_way,
  269. ExecutionFrequency: execution_frequency,
  270. SingleDose: single_dose,
  271. PrescribingNumber: prescribing_number,
  272. Label: label,
  273. Sort: sort,
  274. IsUseDoctorAdvice: is_use_doctor_advice,
  275. IsDefault: is_default,
  276. IsChargePredict: is_charge_predict,
  277. IsStatisticsWork: is_statistics_work,
  278. IsChargeUse: is_charge_use,
  279. OrgId: adminInfo.CurrentOrgId,
  280. Status: 1,
  281. Ctime: drug.Ctime,
  282. Mtime: time.Now().Unix(),
  283. DrugCode: drug_code,
  284. }
  285. err := service.UpdateBaseDrugLib(drugLib)
  286. //查询是否存在
  287. _, errOne := service.GetDrugNameIsExist(id, adminInfo.CurrentOrgId)
  288. if errOne == gorm.ErrRecordNotFound {
  289. fmt.Println("进来了吗")
  290. c.ServeSuccessJSON(map[string]interface{}{
  291. "msg": "修改成功",
  292. })
  293. return
  294. } else if errOne == nil {
  295. //修改xt_drug_name 表
  296. drugName := models.XtDrugName{
  297. DrugName: drug_name,
  298. }
  299. service.UpdatedDrugName(id, adminInfo.CurrentOrgId, &drugName)
  300. }
  301. //查询是否存在
  302. _, errTwo := service.GetStandNameIsExist(id, adminInfo.CurrentOrgId)
  303. if errTwo == gorm.ErrRecordNotFound {
  304. fmt.Println("进来了吗1")
  305. c.ServeSuccessJSON(map[string]interface{}{
  306. "msg": "修改成功",
  307. })
  308. return
  309. } else if errTwo == nil {
  310. //修改规格xt_stand_name表
  311. standName := models.XtStandName{
  312. DrugName: drug_name,
  313. DrugSpec: drug_spec,
  314. DrugStockLimit: drug_stock_limit,
  315. MinUnit: min_unit,
  316. }
  317. service.UpdateStandName(id, adminInfo.CurrentOrgId, &standName)
  318. }
  319. _, errThree := service.GetSelfMedicalIsExist(id, adminInfo.CurrentOrgId)
  320. if errThree == gorm.ErrRecordNotFound {
  321. fmt.Println("进来了吗2")
  322. c.ServeSuccessJSON(map[string]interface{}{
  323. "msg": "修改成功",
  324. })
  325. return
  326. } else if errThree == nil {
  327. //修改药品表
  328. medical := models.XtSelfMedical{
  329. DrugName: drug_name,
  330. DrugSpec: drug_spec,
  331. ExecutionFrequency: execution_frequency,
  332. PrescribingNumber: prescribing_number,
  333. DeliveryWay: delivery_way,
  334. SingleDose: single_dose,
  335. MinUnit: min_unit,
  336. }
  337. service.UpdateSelfMedical(id, adminInfo.CurrentOrgId, &medical)
  338. }
  339. _, errFour := service.GetSelfStosckIsExist(id, adminInfo.CurrentOrgId)
  340. if errFour == gorm.ErrRecordNotFound {
  341. fmt.Println("进来了吗3")
  342. c.ServeSuccessJSON(map[string]interface{}{
  343. "msg": "修改成功",
  344. })
  345. return
  346. } else if errFour == nil {
  347. stock := models.XtSelfStock{
  348. DrugSpec: drug_spec,
  349. DrugName: drug_name,
  350. MinUnit: min_unit,
  351. }
  352. service.UpdatedSelfStock(&stock, id, adminInfo.CurrentOrgId)
  353. }
  354. _, errFive := service.GetOutSelfOutStockIsExist(id, adminInfo.CurrentOrgId)
  355. if errFive == gorm.ErrRecordNotFound {
  356. fmt.Println("进来了吗4")
  357. c.ServeSuccessJSON(map[string]interface{}{
  358. "msg": "修改成功",
  359. })
  360. return
  361. } else if errFive == nil {
  362. outStock := models.XtSelfOutStock{
  363. DrugName: drug_name,
  364. DrugSpec: drug_spec,
  365. }
  366. //修改出库表
  367. service.UpdatedOutSelfStock(&outStock, id, adminInfo.CurrentOrgId)
  368. }
  369. _, errSix := service.GetDoctorAdviceIsExist(id, adminInfo.CurrentOrgId)
  370. if errSix == gorm.ErrRecordNotFound {
  371. fmt.Println("进来了吗5")
  372. c.ServeSuccessJSON(map[string]interface{}{
  373. "msg": "修改成功",
  374. })
  375. return
  376. } else if errSix == nil {
  377. //查询未执行的医嘱
  378. advice := models.DoctorAdvice{
  379. AdviceName: drug_name,
  380. AdviceDesc: drug_spec,
  381. DeliveryWay: delivery_way,
  382. ExecutionFrequency: execution_frequency,
  383. SingleDose: single_dose,
  384. SingleDoseUnit: min_unit,
  385. }
  386. service.UpdateNoExcuteDoctorAdvice(id, adminInfo.CurrentOrgId, &advice)
  387. }
  388. _, errSeven := service.GetDoctorAdviceTemplateIsExist(id, adminInfo.CurrentOrgId)
  389. if errSeven == gorm.ErrRecordNotFound {
  390. fmt.Println("进来了吗6")
  391. c.ServeSuccessJSON(map[string]interface{}{
  392. "msg": "修改成功",
  393. })
  394. return
  395. } else if errSeven == nil {
  396. //修改医嘱模板
  397. template := models.DoctorAdviceTemplate{
  398. AdviceName: drug_name,
  399. AdviceDesc: drug_spec,
  400. DeliveryWay: delivery_way,
  401. ExecutionFrequency: execution_frequency,
  402. SingleDose: single_dose,
  403. SingleDoseUnit: min_unit,
  404. }
  405. service.UpdatedDoctorAdviceTemplate(id, adminInfo.CurrentOrgId, &template)
  406. }
  407. if err == nil {
  408. c.ServeSuccessJSON(map[string]interface{}{
  409. "msg": "修改成功",
  410. })
  411. return
  412. } else {
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  414. return
  415. }
  416. }
  417. func (c *ManagerCenterApiController) GetBaseDrugLib() {
  418. id, _ := c.GetInt64("id")
  419. adminInfo := c.GetAdminUserInfo()
  420. drug, err := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
  421. if err == nil {
  422. c.ServeSuccessJSON(map[string]interface{}{
  423. "drug": drug,
  424. })
  425. return
  426. } else {
  427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  428. return
  429. }
  430. }
  431. func (c *ManagerCenterApiController) GetBaseDrugLibList() {
  432. page, _ := c.GetInt64("page", 1)
  433. limit, _ := c.GetInt64("limit", 10)
  434. is_use, _ := c.GetInt64("is_use", 0)
  435. is_charge, _ := c.GetInt64("is_charge", 0)
  436. is_inject, _ := c.GetInt64("is_inject", 0)
  437. keyword := c.GetString("keyword")
  438. adminInfo := c.GetAdminUserInfo()
  439. if page <= 0 {
  440. page = 1
  441. }
  442. if limit <= 0 {
  443. limit = 10
  444. }
  445. list, total, _ := service.GetBaseDrugLibList(adminInfo.CurrentOrgId, keyword, page, limit, is_use, is_charge, is_inject)
  446. c.ServeSuccessJSON(map[string]interface{}{
  447. "list": list,
  448. "total": total,
  449. })
  450. return
  451. }
  452. func (c *ManagerCenterApiController) CreateMedicineInsurancePercent() {
  453. module, _ := c.GetInt64("module", 0)
  454. adminInfo := c.GetAdminUserInfo()
  455. dataBody := make(map[string]interface{}, 0)
  456. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  457. if err != nil {
  458. utils.ErrorLog(err.Error())
  459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  460. return
  461. }
  462. var mips []*models.MedicineInsurancePercentage
  463. var errs error
  464. record_time := time.Now().Unix()
  465. if dataBody["mip"] != nil && reflect.TypeOf(dataBody["mip"]).String() == "[]interface {}" {
  466. mip_map, _ := dataBody["mip"].([]interface{})
  467. if len(mip_map) > 0 {
  468. for _, item := range mip_map {
  469. items := item.(map[string]interface{})
  470. if items["type_id"] == nil || reflect.TypeOf(items["type_id"]).String() != "float64" {
  471. utils.ErrorLog("type_id")
  472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  473. return
  474. }
  475. type_id := int64(items["type_id"].(float64))
  476. if items["medicine_insurance_type"] == nil || reflect.TypeOf(items["medicine_insurance_type"]).String() != "float64" {
  477. utils.ErrorLog("medicine_insurance_type")
  478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  479. return
  480. }
  481. types := int64(items["medicine_insurance_type"].(float64))
  482. if items["percent"] == nil || reflect.TypeOf(items["percent"]).String() != "string" {
  483. utils.ErrorLog("percent")
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. return
  486. }
  487. percent, _ := strconv.ParseFloat(items["percent"].(string), 64)
  488. //percent := items["percent"].(float64)
  489. mip_temp := &models.MedicineInsurancePercentage{
  490. TypeId: type_id,
  491. Status: 1,
  492. Ctime: time.Now().Unix(),
  493. Mtime: time.Now().Unix(),
  494. RecordTime: record_time,
  495. MedicineInsuranceType: types,
  496. UserOrgId: adminInfo.CurrentOrgId,
  497. Percent: percent,
  498. Module: module,
  499. GoodId: 0,
  500. }
  501. mips = append(mips, mip_temp)
  502. }
  503. }
  504. for _, item := range mips {
  505. errs = service.CreateMedicineInsurancePercentage(item)
  506. }
  507. }
  508. if errs == nil {
  509. c.ServeSuccessJSON(map[string]interface{}{
  510. "msg": "添加成功",
  511. })
  512. return
  513. } else {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  515. return
  516. }
  517. }
  518. func (c *ManagerCenterApiController) CreateDrugUnitSafeguard() {
  519. }
  520. //GetPatientsList 取配置信息列表
  521. func (c *ManagerCenterApiController) GetConfigList() {
  522. adminUserInfo := c.GetAdminUserInfo()
  523. configList, _ := service.GetDictionaryConfigList(adminUserInfo.CurrentOrgId)
  524. c.ServeSuccessJSON(map[string]interface{}{
  525. "configlist": configList,
  526. })
  527. return
  528. }
  529. //CreateConfig 创建配置信息
  530. func (c *ManagerCenterApiController) CreateConfig() {
  531. adminUserInfo := c.GetAdminUserInfo()
  532. var dataconfig models.DictionaryDataconfig
  533. var resultConfig models.DictionaryConfigViewModel
  534. code := dictionaryConfigFormData(&dataconfig, c.Ctx.Input.RequestBody)
  535. if code > 0 {
  536. c.ServeFailJSONWithSGJErrorCode(code)
  537. return
  538. }
  539. // 验证关键字段的值是否重复
  540. thisConfig, _ := service.FindDictionaryConfigByTitle(dataconfig.Module, dataconfig.FieldName, adminUserInfo.CurrentOrgId)
  541. if thisConfig.ID > 0 {
  542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  543. return
  544. }
  545. fieldValue := service.GetDictionaryChildValue(dataconfig.Module, dataconfig.ParentId, adminUserInfo.CurrentOrgId)
  546. dataconfig.Value = fieldValue + 1
  547. dataBody := make(map[string]interface{}, 0)
  548. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  549. if err != nil {
  550. utils.ErrorLog(err.Error())
  551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  555. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  556. dataconfig.Status = 1
  557. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  558. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  559. dataconfig.Remark = string(dataBody["remark"].(string))
  560. if dataBody["order"] != nil {
  561. dataconfig.Order = int64(dataBody["order"].(float64))
  562. } else {
  563. dataconfig.Order = 0
  564. }
  565. err = service.CreateDictionaryConfig(&dataconfig)
  566. if err != nil {
  567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  568. return
  569. } else {
  570. resultConfig.ID = dataconfig.ID
  571. resultConfig.Module = dataconfig.Module
  572. resultConfig.Name = dataconfig.Name
  573. resultConfig.OrgId = dataconfig.OrgId
  574. resultConfig.ParentId = dataconfig.ParentId
  575. resultConfig.FieldName = dataconfig.FieldName
  576. resultConfig.CreateUserId = dataconfig.CreateUserId
  577. resultConfig.Title = dataconfig.Title
  578. resultConfig.Content = dataconfig.Content
  579. }
  580. c.ServeSuccessJSON(map[string]interface{}{
  581. "dataconfig": resultConfig,
  582. "msg": "ok",
  583. })
  584. return
  585. }
  586. func (c *ManagerCenterApiController) UpdateTemplate() {
  587. adminUserInfo := c.GetAdminUserInfo()
  588. var dataconfig models.DictionaryDataconfig
  589. code := dictionaryConfigFormData(&dataconfig, c.Ctx.Input.RequestBody)
  590. if code > 0 {
  591. c.ServeFailJSONWithSGJErrorCode(code)
  592. return
  593. }
  594. dataBody := make(map[string]interface{}, 0)
  595. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  596. if err != nil {
  597. utils.ErrorLog(err.Error())
  598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  599. return
  600. }
  601. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  602. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  603. dataconfig.Status = 1
  604. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  605. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  606. dataconfig.Remark = string(dataBody["remark"].(string))
  607. if dataBody["order"] != nil {
  608. dataconfig.Order = int64(dataBody["order"].(float64))
  609. } else {
  610. dataconfig.Order = 0
  611. }
  612. // 验证关键字段的值是否重复
  613. // cur_id := int64(dataBody["id"].(float64))
  614. // thisConfig,_:=service.FindConfigByTitleForUpdate(dataconfig.Module, dataconfig.Title,dataconfig.OrgId,cur_id)
  615. // if thisConfig.ID >0 {
  616. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  617. // return
  618. // }
  619. configOrgId := int64(dataBody["org_id"].(float64))
  620. if configOrgId == 0 {
  621. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  622. err := service.CreateDictionaryConfig(&dataconfig)
  623. if err != nil {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  625. return
  626. }
  627. } else {
  628. dataconfig.ID = int64(dataBody["id"].(float64))
  629. err = service.UpdateDictionaryTemplate(&dataconfig)
  630. if err != nil {
  631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  632. return
  633. }
  634. }
  635. c.ServeSuccessJSON(map[string]interface{}{
  636. "dataconfig": dataconfig,
  637. "msg": "ok",
  638. })
  639. return
  640. }
  641. func (c *ManagerCenterApiController) UpdateChildConfig() {
  642. adminUserInfo := c.GetAdminUserInfo()
  643. var dataconfig models.DictionaryDataconfig
  644. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  645. if code > 0 {
  646. c.ServeFailJSONWithSGJErrorCode(code)
  647. return
  648. }
  649. dataBody := make(map[string]interface{}, 0)
  650. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  651. if err != nil {
  652. utils.ErrorLog(err.Error())
  653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  654. return
  655. }
  656. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  657. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  658. dataconfig.Status = 1
  659. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  660. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  661. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  662. dataconfig.Remark = string(dataBody["remark"].(string))
  663. dataconfig.Order = int64(dataBody["orders"].(float64))
  664. fmt.Println("dataconfitg------", dataconfig.Order)
  665. //if dataBody["orders"] != nil {
  666. // dataconfig.Order = int64(dataBody["orders"].(float64))
  667. // fmt.Println("dataconfig",dataconfig.Order)
  668. //} else {
  669. // dataconfig.Order = 0
  670. //}
  671. configOrgId := int64(dataBody["org_id"].(float64))
  672. // 验证关键字段的值是否重复
  673. // configId := int64(dataBody["id"].(float64))
  674. // thisConfig,_:=service.FindConfigByNameForUpdate(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId,configId)
  675. // if thisConfig.ID >0 {
  676. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  677. // return
  678. // }
  679. if configOrgId == 0 {
  680. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  681. err := service.CreateDictionaryConfig(&dataconfig)
  682. if err != nil {
  683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  684. return
  685. }
  686. } else {
  687. dataconfig.ID = int64(dataBody["id"].(float64))
  688. err = service.UpdateDictionaryChildConfig(&dataconfig)
  689. if err != nil {
  690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  691. return
  692. }
  693. }
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "dataconfig": dataconfig,
  696. "msg": "ok",
  697. })
  698. return
  699. }
  700. func (c *ManagerCenterApiController) DeleteChildConfig() {
  701. adminUserInfo := c.GetAdminUserInfo()
  702. var dataconfig models.DictionaryDataconfig
  703. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  704. if code > 0 {
  705. c.ServeFailJSONWithSGJErrorCode(code)
  706. return
  707. }
  708. dataBody := make(map[string]interface{}, 0)
  709. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  710. if err != nil {
  711. utils.ErrorLog(err.Error())
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  713. return
  714. }
  715. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  716. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  717. dataconfig.Status = 0
  718. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  719. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  720. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  721. dataconfig.Remark = string(dataBody["remark"].(string))
  722. if dataBody["order"] != nil {
  723. dataconfig.Order = int64(dataBody["order"].(float64))
  724. } else {
  725. dataconfig.Order = 0
  726. }
  727. configOrgId := int64(dataBody["org_id"].(float64))
  728. if configOrgId == 0 {
  729. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  730. err := service.CreateDictionaryConfig(&dataconfig)
  731. if err != nil {
  732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  733. return
  734. }
  735. } else {
  736. dataconfig.ID = int64(dataBody["id"].(float64))
  737. err := service.DeleteDictionaryChildConfig(&dataconfig)
  738. if err != nil {
  739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  740. return
  741. }
  742. }
  743. c.ServeSuccessJSON(map[string]interface{}{
  744. "dataconfig": dataconfig,
  745. "msg": "ok",
  746. })
  747. return
  748. }
  749. //CreateChildConfig 创建子配置信息
  750. func (c *ManagerCenterApiController) CreateChildConfig() {
  751. adminUserInfo := c.GetAdminUserInfo()
  752. var dataconfig models.DictionaryDataconfig
  753. code := dictionaryConfigChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  754. if code > 0 {
  755. c.ServeFailJSONWithSGJErrorCode(code)
  756. return
  757. }
  758. dataBody := make(map[string]interface{}, 0)
  759. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  760. if err != nil {
  761. utils.ErrorLog(err.Error())
  762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  763. return
  764. }
  765. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  766. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  767. dataconfig.Status = 1
  768. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  769. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  770. dataconfig.Remark = string(dataBody["remark"].(string))
  771. if dataBody["order"] != nil {
  772. dataconfig.Order = int64(dataBody["order"].(float64))
  773. } else {
  774. dataconfig.Order = 0
  775. }
  776. // 验证关键字段的值是否重复
  777. // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
  778. // if thisConfig.ID >0 {
  779. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  780. // return
  781. // }
  782. fieldValue := service.GetDictionaryChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
  783. dataconfig.Value = fieldValue + 1
  784. err = service.CreateDictionaryConfig(&dataconfig)
  785. if err != nil {
  786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  787. return
  788. }
  789. c.ServeSuccessJSON(map[string]interface{}{
  790. "dataconfig": dataconfig,
  791. "msg": "ok",
  792. })
  793. return
  794. }
  795. func dictionaryConfigFormData(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" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" {
  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["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  843. utils.ErrorLog("name")
  844. code = enums.ErrorCodeParamWrong
  845. return
  846. }
  847. name, _ := configBody["name"].(string)
  848. if len(name) == 0 {
  849. utils.ErrorLog("len(name) == 0")
  850. code = enums.ErrorCodeParamWrong
  851. return
  852. }
  853. dataconfig.Name = name
  854. if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
  855. utils.ErrorLog("field_name")
  856. code = enums.ErrorCodeParamWrong
  857. return
  858. }
  859. field_name, _ := configBody["field_name"].(string)
  860. if len(field_name) == 0 {
  861. utils.ErrorLog("len(field_name) == 0")
  862. code = enums.ErrorCodeParamWrong
  863. return
  864. }
  865. dataconfig.FieldName = field_name
  866. }
  867. return
  868. }
  869. func dictionaryConfigChildFormData(dataconfig *models.DictionaryDataconfig, data []byte) (code int) {
  870. configBody := make(map[string]interface{}, 0)
  871. err := json.Unmarshal(data, &configBody)
  872. utils.InfoLog(string(data))
  873. if err != nil {
  874. utils.ErrorLog(err.Error())
  875. code = enums.ErrorCodeParamWrong
  876. return
  877. }
  878. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  879. utils.ErrorLog("module")
  880. code = enums.ErrorCodeParamWrong
  881. return
  882. }
  883. module, _ := configBody["module"].(string)
  884. if len(module) == 0 {
  885. utils.ErrorLog("len(module) == 0")
  886. code = enums.ErrorCodeParamWrong
  887. return
  888. }
  889. dataconfig.Module = module
  890. if module == "education" || module == "summary" {
  891. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  892. utils.ErrorLog("title")
  893. code = enums.ErrorCodeParamWrong
  894. return
  895. }
  896. title, _ := configBody["title"].(string)
  897. if len(title) == 0 {
  898. utils.ErrorLog("len(title) == 0")
  899. code = enums.ErrorCodeParamWrong
  900. return
  901. }
  902. dataconfig.Title = title
  903. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  904. utils.ErrorLog("content")
  905. code = enums.ErrorCodeParamWrong
  906. return
  907. }
  908. content, _ := configBody["content"].(string)
  909. if len(content) == 0 {
  910. utils.ErrorLog("len(content) == 0")
  911. code = enums.ErrorCodeParamWrong
  912. return
  913. }
  914. dataconfig.Content = content
  915. } else {
  916. if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
  917. utils.ErrorLog("module")
  918. code = enums.ErrorCodeParamWrong
  919. return
  920. }
  921. parent_id := int64(configBody["parent_id"].(float64))
  922. if parent_id <= 0 {
  923. utils.ErrorLog("parent_id <= 0")
  924. code = enums.ErrorCodeParamWrong
  925. return
  926. }
  927. dataconfig.ParentId = parent_id
  928. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  929. utils.ErrorLog("name")
  930. code = enums.ErrorCodeParamWrong
  931. return
  932. }
  933. name, _ := configBody["name"].(string)
  934. if len(name) == 0 {
  935. utils.ErrorLog("len(name) == 0")
  936. code = enums.ErrorCodeParamWrong
  937. return
  938. }
  939. dataconfig.Name = name
  940. }
  941. return
  942. }
  943. func (c *ManagerCenterApiController) CreateDealer() {
  944. dealer_name := c.GetString("dealer_name")
  945. contact := c.GetString("contact")
  946. contact_phone := c.GetString("contact_phone")
  947. platform_number := c.GetString("platform_number")
  948. email := c.GetString("email")
  949. contact_address := c.GetString("contact_address")
  950. remark := c.GetString("remark")
  951. pinyin := c.GetString("pinyin")
  952. wubi := c.GetString("wubi")
  953. if len(dealer_name) <= 0 {
  954. utils.ErrorLog("len(dealer_name) == 0")
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. adminUserInfo := c.GetAdminUserInfo()
  959. total := service.FindAllDealerTotal(adminUserInfo.CurrentOrgId)
  960. totalStr := strconv.FormatInt(total+1, 10)
  961. code := "1000" + totalStr
  962. dealer := models.Dealer{
  963. DealerName: dealer_name,
  964. Contact: contact,
  965. ContactPhone: contact_phone,
  966. ContactAddress: contact_address,
  967. DealerCode: code,
  968. Ctime: time.Now().Unix(),
  969. Mtime: time.Now().Unix(),
  970. Remark: remark,
  971. Creater: adminUserInfo.AdminUser.Id,
  972. Email: email,
  973. PlatformNumber: platform_number,
  974. OrgId: adminUserInfo.CurrentOrgId,
  975. Status: 1,
  976. PinYin: pinyin,
  977. WuBi: wubi,
  978. }
  979. err, dealers := service.AddSigleDealer(&dealer)
  980. if err == nil {
  981. c.ServeSuccessJSON(map[string]interface{}{
  982. "dealer": dealers,
  983. })
  984. } else {
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  986. }
  987. }
  988. func (c *ManagerCenterApiController) ModifyDealer() {
  989. id, _ := c.GetInt64("id", 0)
  990. dealer_name := c.GetString("dealer_name")
  991. contact := c.GetString("contact")
  992. contact_phone := c.GetString("contact_phone")
  993. platform_number := c.GetString("platform_number")
  994. dealer_code := c.GetString("dealer_code")
  995. email := c.GetString("email")
  996. contact_address := c.GetString("contact_address")
  997. remark := c.GetString("remark")
  998. pinyin := c.GetString("pinyin")
  999. wubi := c.GetString("wubi")
  1000. if id <= 0 {
  1001. utils.ErrorLog("id == 0")
  1002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1003. return
  1004. }
  1005. if len(dealer_name) <= 0 {
  1006. utils.ErrorLog("len(dealer_name) == 0")
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1008. return
  1009. }
  1010. adminUserInfo := c.GetAdminUserInfo()
  1011. dealer := models.Dealer{
  1012. ID: id,
  1013. DealerName: dealer_name,
  1014. Contact: contact,
  1015. ContactPhone: contact_phone,
  1016. ContactAddress: contact_address,
  1017. Mtime: time.Now().Unix(),
  1018. DealerCode: dealer_code,
  1019. Remark: remark,
  1020. Creater: adminUserInfo.AdminUser.Id,
  1021. Email: email,
  1022. PlatformNumber: platform_number,
  1023. Modifier: adminUserInfo.AdminUser.Id,
  1024. OrgId: adminUserInfo.CurrentOrgId,
  1025. Status: 1,
  1026. PinYin: pinyin,
  1027. WuBi: wubi,
  1028. }
  1029. err := service.ModifyDealer(&dealer)
  1030. if err == nil {
  1031. c.ServeSuccessJSON(map[string]interface{}{
  1032. "dealer": dealer,
  1033. })
  1034. } else {
  1035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1036. }
  1037. }
  1038. func (c *ManagerCenterApiController) GetDealersList() {
  1039. page, _ := c.GetInt64("page", 1)
  1040. limit, _ := c.GetInt64("limit", 7)
  1041. adminUserInfo := c.GetAdminUserInfo()
  1042. deales, total, err := service.FindAllDealerList(adminUserInfo.CurrentOrgId, page, limit)
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "dealer": deales,
  1046. "total": total,
  1047. })
  1048. } else {
  1049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1050. }
  1051. }
  1052. func (c *ManagerCenterApiController) DeleteDealer() {
  1053. id, _ := c.GetInt64("id", 0)
  1054. total, _ := service.FindStockInByDealerId(id)
  1055. if total > 0 {
  1056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteDealerWrong)
  1057. return
  1058. }
  1059. err := service.DeleteDealerById(id)
  1060. if err == nil {
  1061. c.ServeSuccessJSON(map[string]interface{}{
  1062. "msg": "删除成功",
  1063. })
  1064. } else {
  1065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1066. }
  1067. }
  1068. func (c *ManagerCenterApiController) GetDealer() {
  1069. id, _ := c.GetInt64("id", 0)
  1070. dealer, err := service.FindDealerById(id)
  1071. if err == nil {
  1072. c.ServeSuccessJSON(map[string]interface{}{
  1073. "dealer": dealer,
  1074. })
  1075. } else {
  1076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1077. }
  1078. }
  1079. func (c *ManagerCenterApiController) CreateManufacturer() {
  1080. manufacturer_name := c.GetString("manufacturer_name")
  1081. contact := c.GetString("contact")
  1082. contact_phone := c.GetString("contact_phone")
  1083. platform_number := c.GetString("platform_number")
  1084. email := c.GetString("email")
  1085. contact_address := c.GetString("contact_address")
  1086. remark := c.GetString("remark")
  1087. pinyin := c.GetString("pinyin")
  1088. wubi := c.GetString("wubi")
  1089. if len(manufacturer_name) <= 0 {
  1090. utils.ErrorLog("len(manufacturer_name) == 0")
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1092. return
  1093. }
  1094. adminUserInfo := c.GetAdminUserInfo()
  1095. total := service.FindManufacturerTotal(adminUserInfo.CurrentOrgId)
  1096. totalStr := strconv.FormatInt(total+1, 10)
  1097. code := "2000" + totalStr
  1098. manufacturer := models.Manufacturer{
  1099. ManufacturerName: manufacturer_name,
  1100. Contact: contact,
  1101. ContactPhone: contact_phone,
  1102. ContactAddress: contact_address,
  1103. Ctime: time.Now().Unix(),
  1104. Mtime: time.Now().Unix(),
  1105. Remark: remark,
  1106. Creater: adminUserInfo.AdminUser.Id,
  1107. Email: email,
  1108. PlatformNumber: platform_number,
  1109. OrgId: adminUserInfo.CurrentOrgId,
  1110. Status: 1,
  1111. ManufacturerCode: code,
  1112. PinYin: pinyin,
  1113. WuBi: wubi,
  1114. }
  1115. err, manufacturers := service.AddSigleManufacturer(&manufacturer)
  1116. if err == nil {
  1117. c.ServeSuccessJSON(map[string]interface{}{
  1118. "manufacturer": manufacturers,
  1119. })
  1120. } else {
  1121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1122. }
  1123. }
  1124. func (c *ManagerCenterApiController) ModifyManufacturer() {
  1125. id, _ := c.GetInt64("id", 0)
  1126. manufacturer_name := c.GetString("manufacturer_name")
  1127. contact := c.GetString("contact")
  1128. contact_phone := c.GetString("contact_phone")
  1129. platform_number := c.GetString("platform_number")
  1130. email := c.GetString("email")
  1131. contact_address := c.GetString("contact_address")
  1132. remark := c.GetString("remark")
  1133. manufacturer_code := c.GetString("manufacturer_code")
  1134. pinyin := c.GetString("pinyin")
  1135. wubi := c.GetString("wubi")
  1136. if id <= 0 {
  1137. utils.ErrorLog("id == 0")
  1138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1139. return
  1140. }
  1141. if len(manufacturer_name) <= 0 {
  1142. utils.ErrorLog("len(manufacturer_name) == 0")
  1143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1144. return
  1145. }
  1146. adminUserInfo := c.GetAdminUserInfo()
  1147. manufacturer := models.Manufacturer{
  1148. ID: id,
  1149. ManufacturerName: manufacturer_name,
  1150. Contact: contact,
  1151. ContactPhone: contact_phone,
  1152. ContactAddress: contact_address,
  1153. Mtime: time.Now().Unix(),
  1154. Remark: remark,
  1155. Creater: adminUserInfo.AdminUser.Id,
  1156. Email: email,
  1157. PlatformNumber: platform_number,
  1158. Modifier: adminUserInfo.AdminUser.Id,
  1159. OrgId: adminUserInfo.CurrentOrgId,
  1160. ManufacturerCode: manufacturer_code,
  1161. Status: 1,
  1162. PinYin: pinyin,
  1163. WuBi: wubi,
  1164. }
  1165. err := service.ModifyManufacturer(&manufacturer)
  1166. if err == nil {
  1167. c.ServeSuccessJSON(map[string]interface{}{
  1168. "manufacturer": manufacturer,
  1169. })
  1170. } else {
  1171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1172. }
  1173. }
  1174. func (c *ManagerCenterApiController) GetManufacturerList() {
  1175. page, _ := c.GetInt64("page", 1)
  1176. limit, _ := c.GetInt64("limit", 10)
  1177. adminUserInfo := c.GetAdminUserInfo()
  1178. manufacturer, total, err := service.FindAllManufacturerList(adminUserInfo.CurrentOrgId, page, limit)
  1179. if err == nil {
  1180. c.ServeSuccessJSON(map[string]interface{}{
  1181. "manufacturer": manufacturer,
  1182. "total": total,
  1183. })
  1184. } else {
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1186. }
  1187. }
  1188. func (c *ManagerCenterApiController) DeleteManufacturer() {
  1189. id, _ := c.GetInt64("id", 0)
  1190. total, _ := service.FindStockInByManufacturerId(id)
  1191. if total > 0 {
  1192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteManufacturerWrong)
  1193. return
  1194. }
  1195. err := service.DeleteManufacturerById(id)
  1196. if err == nil {
  1197. c.ServeSuccessJSON(map[string]interface{}{
  1198. "msg": "删除成功",
  1199. })
  1200. } else {
  1201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1202. }
  1203. }
  1204. func (c *ManagerCenterApiController) GetManufacturer() {
  1205. id, _ := c.GetInt64("id", 0)
  1206. manufacturer, err := service.FindManufacturerById(id)
  1207. if err == nil {
  1208. c.ServeSuccessJSON(map[string]interface{}{
  1209. "manufacturer": manufacturer,
  1210. })
  1211. } else {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1213. }
  1214. }
  1215. func (c *ManagerCenterApiController) GetAllDealer() {
  1216. adminUserInfo := c.GetAdminUserInfo()
  1217. dealer, err := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1218. if err == nil {
  1219. c.ServeSuccessJSON(map[string]interface{}{
  1220. "dealer": dealer,
  1221. })
  1222. } else {
  1223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1224. }
  1225. }
  1226. func (c *ManagerCenterApiController) GetAllManufacturer() {
  1227. adminUserInfo := c.GetAdminUserInfo()
  1228. manufacturer, err := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1229. if err == nil {
  1230. c.ServeSuccessJSON(map[string]interface{}{
  1231. "manufacturer": manufacturer,
  1232. })
  1233. } else {
  1234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1235. }
  1236. }
  1237. func (c *ManagerCenterApiController) CreateGoodInfo() {
  1238. good_id, _ := c.GetInt64("good_id", 0)
  1239. specification_name := c.GetString("specification_name")
  1240. good_unit, _ := c.GetInt64("good_unit", -1)
  1241. buy_price, _ := c.GetFloat("buy_price", 0)
  1242. sell_price, _ := c.GetFloat("sell_price", 0)
  1243. remark := c.GetString("remark")
  1244. manufacturer, _ := c.GetInt64("manufacturer", 0)
  1245. dealer, _ := c.GetInt64("dealer", 0)
  1246. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  1247. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  1248. is_reuse, _ := c.GetInt64("is_reuse", 0)
  1249. good_name := c.GetString("good_name")
  1250. pinyin := c.GetString("pinyin")
  1251. wubi := c.GetString("wubi")
  1252. good_kind, _ := c.GetInt64("good_kind", 0)
  1253. medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
  1254. retail_price, _ := c.GetFloat("retail_price", 0)
  1255. medical_insurance_number := c.GetString("medical_insurance_number")
  1256. is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
  1257. is_record, _ := c.GetInt64("is_record")
  1258. statistics_category, _ := c.GetInt64("statistics_category")
  1259. good_status := c.GetString("good_status")
  1260. default_count, _ := c.GetInt64("default_count")
  1261. sign, _ := c.GetInt64("sign")
  1262. is_default, _ := c.GetInt64("is_default")
  1263. is_charge_use, _ := c.GetInt64("is_charge_use")
  1264. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  1265. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  1266. sort, _ := c.GetInt64("sort")
  1267. is_doctor_use, _ := c.GetInt64("is_doctor_use")
  1268. agent := c.GetString("agent")
  1269. good_number := c.GetString("good_number")
  1270. adminUserInfo := c.GetAdminUserInfo()
  1271. totals := service.FindGoodInfoByName(specification_name, adminUserInfo.CurrentOrgId, good_id)
  1272. if totals > 0 {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  1274. return
  1275. }
  1276. total := service.FindAllGoodInfoTotal(adminUserInfo.CurrentOrgId)
  1277. code := strconv.FormatInt(total+1, 10)
  1278. code = "24000000" + code
  1279. goodInfo := models.GoodInfo{
  1280. GoodCode: code,
  1281. SpecificationName: specification_name,
  1282. GoodTypeId: good_id,
  1283. GoodUnit: good_unit,
  1284. BuyPrice: buy_price,
  1285. SellPrice: sell_price,
  1286. Remark: remark,
  1287. Ctime: time.Now().Unix(),
  1288. Manufacturer: manufacturer,
  1289. Dealer: dealer,
  1290. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  1291. StockWarnCount: stock_warn_count,
  1292. IsReuse: is_reuse,
  1293. Status: 1,
  1294. OrgId: adminUserInfo.CurrentOrgId,
  1295. Creater: adminUserInfo.AdminUser.Id,
  1296. GoodName: good_name,
  1297. Pinyin: pinyin,
  1298. Wubi: wubi,
  1299. GoodKind: good_kind,
  1300. MedicalInsuranceNumber: medical_insurance_number,
  1301. IsSpecialDiseases: is_special_diseases,
  1302. IsRecord: is_record,
  1303. StatisticsCategory: statistics_category,
  1304. GoodStatus: good_status,
  1305. DefaultCount: default_count,
  1306. Sign: sign,
  1307. IsDefault: is_default,
  1308. IsChargeUse: is_charge_use,
  1309. IsChargePredict: is_charge_predict,
  1310. IsStatisticsWork: is_statistics_work,
  1311. Sort: sort,
  1312. IsDoctorUse: is_doctor_use,
  1313. Agent: agent,
  1314. GoodNumber: good_number,
  1315. MedicalInsuranceLevel: medical_insurance_level,
  1316. RetailPrice: retail_price,
  1317. }
  1318. err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
  1319. if err == nil {
  1320. c.ServeSuccessJSON(map[string]interface{}{
  1321. "goodInfo": goodInfos,
  1322. })
  1323. } else {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1325. }
  1326. }
  1327. func (c *ManagerCenterApiController) ModifyGoodInfo() {
  1328. id, _ := c.GetInt64("id", 0)
  1329. good_id, _ := c.GetInt64("good_id", 0)
  1330. specification_name := c.GetString("specification_name")
  1331. good_unit, _ := c.GetInt64("good_unit", -1)
  1332. buy_price, _ := c.GetFloat("buy_price", 0)
  1333. sell_price, _ := c.GetFloat("sell_price", 0)
  1334. remark := c.GetString("remark")
  1335. manufacturer, _ := c.GetInt64("manufacturer", 0)
  1336. dealer, _ := c.GetInt64("dealer", 0)
  1337. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  1338. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  1339. is_reuse, _ := c.GetInt64("is_reuse", 0)
  1340. code := c.GetString("good_code")
  1341. good_name := c.GetString("good_name")
  1342. pinyin := c.GetString("pinyin")
  1343. wubi := c.GetString("wubi")
  1344. good_kind, _ := c.GetInt64("good_kind", 0)
  1345. medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
  1346. retail_price, _ := c.GetFloat("retail_price", 0)
  1347. medical_insurance_number := c.GetString("medical_insurance_number")
  1348. is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
  1349. is_record, _ := c.GetInt64("is_record")
  1350. statistics_category, _ := c.GetInt64("statistics_category")
  1351. good_status := c.GetString("good_status")
  1352. default_count, _ := c.GetInt64("default_count")
  1353. sign, _ := c.GetInt64("sign")
  1354. is_default, _ := c.GetInt64("is_default")
  1355. is_charge_use, _ := c.GetInt64("is_charge_use")
  1356. is_charge_predict, _ := c.GetInt64("is_charge_predict")
  1357. is_statistics_work, _ := c.GetInt64("is_statistics_work")
  1358. sort, _ := c.GetInt64("sort")
  1359. is_doctor_use, _ := c.GetInt64("is_doctor_use")
  1360. agent := c.GetString("agent")
  1361. good_number := c.GetString("good_number")
  1362. adminUserInfo := c.GetAdminUserInfo()
  1363. goodInfo := models.GoodInfo{
  1364. ID: id,
  1365. GoodCode: code,
  1366. SpecificationName: specification_name,
  1367. GoodTypeId: good_id,
  1368. GoodUnit: good_unit,
  1369. BuyPrice: buy_price,
  1370. SellPrice: sell_price,
  1371. Remark: remark,
  1372. Mtime: time.Now().Unix(),
  1373. Manufacturer: manufacturer,
  1374. Dealer: dealer,
  1375. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  1376. StockWarnCount: stock_warn_count,
  1377. IsReuse: is_reuse,
  1378. Status: 1,
  1379. OrgId: adminUserInfo.CurrentOrgId,
  1380. Modifier: adminUserInfo.AdminUser.Id,
  1381. GoodName: good_name,
  1382. Pinyin: pinyin,
  1383. Wubi: wubi,
  1384. GoodKind: good_kind,
  1385. MedicalInsuranceNumber: medical_insurance_number,
  1386. IsSpecialDiseases: is_special_diseases,
  1387. IsRecord: is_record,
  1388. StatisticsCategory: statistics_category,
  1389. GoodStatus: good_status,
  1390. DefaultCount: default_count,
  1391. Sign: sign,
  1392. IsDefault: is_default,
  1393. IsChargeUse: is_charge_use,
  1394. IsChargePredict: is_charge_predict,
  1395. IsStatisticsWork: is_statistics_work,
  1396. Sort: sort,
  1397. IsDoctorUse: is_doctor_use,
  1398. Agent: agent,
  1399. GoodNumber: good_number,
  1400. MedicalInsuranceLevel: medical_insurance_level,
  1401. RetailPrice: retail_price,
  1402. }
  1403. err, goodInfos := service.ModifyGoodInfo(&goodInfo)
  1404. if err == nil {
  1405. c.ServeSuccessJSON(map[string]interface{}{
  1406. "goodInfo": goodInfos,
  1407. })
  1408. } else {
  1409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1410. }
  1411. }
  1412. func (c *ManagerCenterApiController) GetGoodInfoList() {
  1413. page, _ := c.GetInt64("page", 1)
  1414. limit, _ := c.GetInt64("limit", 7)
  1415. keyword := c.GetString("keyword")
  1416. is_use, _ := c.GetInt64("is_use")
  1417. is_charge, _ := c.GetInt64("is_charge")
  1418. good_kind, _ := c.GetInt64("good_kind")
  1419. adminUserInfo := c.GetAdminUserInfo()
  1420. goodInfos, total, err := service.FindGoodInfoList(adminUserInfo.CurrentOrgId, page, limit, keyword, is_use, is_charge, good_kind)
  1421. if err == nil {
  1422. c.ServeSuccessJSON(map[string]interface{}{
  1423. "list": goodInfos,
  1424. "total": total,
  1425. })
  1426. } else {
  1427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1428. }
  1429. }
  1430. func (c *ManagerCenterApiController) DeleteGoodInfo() {
  1431. id, _ := c.GetInt64("id", 0)
  1432. adminUserInfo := c.GetAdminUserInfo()
  1433. total, _ := service.FindWarehouseInfoTotalByGoodId(id)
  1434. total2, _ := service.FindWarehouseOutInfoTotalByGoodId(id)
  1435. if total > 0 {
  1436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  1437. return
  1438. }
  1439. if total2 > 0 {
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  1441. return
  1442. }
  1443. err := service.DeleteGoodInfoById(id, adminUserInfo.AdminUser.Id)
  1444. if err == nil {
  1445. c.ServeSuccessJSON(map[string]interface{}{
  1446. "msg": "删除成功",
  1447. })
  1448. } else {
  1449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1450. }
  1451. }
  1452. func (c *ManagerCenterApiController) GetGoodInfoByGoodId() {
  1453. id, _ := c.GetInt64("id", 0)
  1454. goodInfo, err := service.FindGoodInfoByGoodId(id)
  1455. if err == nil {
  1456. c.ServeSuccessJSON(map[string]interface{}{
  1457. "list": goodInfo,
  1458. })
  1459. } else {
  1460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1461. }
  1462. }
  1463. func (c *ManagerCenterApiController) GetGoodInfoById() {
  1464. id, _ := c.GetInt64("id", 0)
  1465. goodInfo, err := service.FindGoodInfoById(id)
  1466. if err == nil {
  1467. c.ServeSuccessJSON(map[string]interface{}{
  1468. "goodInfo": goodInfo,
  1469. })
  1470. } else {
  1471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1472. }
  1473. }
  1474. func (c *ManagerCenterApiController) GetMedicineInsurancePercent() {
  1475. adminUser := c.GetAdminUserInfo()
  1476. type_id, _ := c.GetInt64("type_id", 0)
  1477. module, _ := c.GetInt64("module", 0)
  1478. mip, err := service.GetLastMedicineInsurance(adminUser.CurrentOrgId, type_id, module)
  1479. if err == nil {
  1480. c.ServeSuccessJSON(map[string]interface{}{
  1481. "mip": mip,
  1482. })
  1483. } else {
  1484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1485. }
  1486. }
  1487. func (c *ManagerCenterApiController) CreateMZSick() {
  1488. class_name := c.GetString("class_name")
  1489. content_code := c.GetString("content_code")
  1490. country_code := c.GetString("country_code")
  1491. country_content_name := c.GetString("country_content_name")
  1492. remark := c.GetString("remark")
  1493. pinyin := c.GetString("pinyin")
  1494. wubi := c.GetString("wubi")
  1495. if len(class_name) <= 0 {
  1496. utils.ErrorLog("len(class_name) == 0")
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1498. return
  1499. }
  1500. if len(content_code) <= 0 {
  1501. utils.ErrorLog("len(content_code) == 0")
  1502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1503. return
  1504. }
  1505. adminUserInfo := c.GetAdminUserInfo()
  1506. dealer := models.OutpatientServiceSick{
  1507. ClassName: class_name,
  1508. ContentCode: content_code,
  1509. CountryCode: country_code,
  1510. CountryContentName: country_content_name,
  1511. Ctime: time.Now().Unix(),
  1512. Mtime: time.Now().Unix(),
  1513. Remark: remark,
  1514. UserOrgId: adminUserInfo.CurrentOrgId,
  1515. Status: 1,
  1516. Pinyin: pinyin,
  1517. Wubi: wubi,
  1518. }
  1519. err, dealers := service.AddSigleMZSick(&dealer)
  1520. if err == nil {
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "sick": dealers,
  1523. })
  1524. } else {
  1525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1526. }
  1527. }
  1528. func (c *ManagerCenterApiController) ModifyMZSick() {
  1529. id, _ := c.GetInt64("id", 0)
  1530. class_name := c.GetString("class_name")
  1531. content_code := c.GetString("content_code")
  1532. country_code := c.GetString("country_code")
  1533. country_content_name := c.GetString("country_content_name")
  1534. remark := c.GetString("remark")
  1535. pinyin := c.GetString("pinyin")
  1536. wubi := c.GetString("wubi")
  1537. if id <= 0 {
  1538. utils.ErrorLog("id == 0")
  1539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1540. return
  1541. }
  1542. if len(class_name) <= 0 {
  1543. utils.ErrorLog("len(class_name) == 0")
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1545. return
  1546. }
  1547. if len(content_code) <= 0 {
  1548. utils.ErrorLog("len(content_code) == 0")
  1549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1550. return
  1551. }
  1552. adminUserInfo := c.GetAdminUserInfo()
  1553. dealer := models.OutpatientServiceSick{
  1554. ID: id,
  1555. ClassName: class_name,
  1556. ContentCode: content_code,
  1557. CountryCode: country_code,
  1558. CountryContentName: country_content_name,
  1559. Ctime: time.Now().Unix(),
  1560. Mtime: time.Now().Unix(),
  1561. Remark: remark,
  1562. UserOrgId: adminUserInfo.CurrentOrgId,
  1563. Pinyin: pinyin,
  1564. Wubi: wubi,
  1565. Status: 1,
  1566. }
  1567. err := service.ModifyMZSick(&dealer)
  1568. if err == nil {
  1569. c.ServeSuccessJSON(map[string]interface{}{
  1570. "sick": dealer,
  1571. })
  1572. } else {
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1574. }
  1575. }
  1576. func (c *ManagerCenterApiController) GetMZSickList() {
  1577. page, _ := c.GetInt64("page", 1)
  1578. limit, _ := c.GetInt64("limit", 7)
  1579. adminUserInfo := c.GetAdminUserInfo()
  1580. mzSick, total, err := service.FindAllMZSickList(adminUserInfo.CurrentOrgId, page, limit)
  1581. if err == nil {
  1582. c.ServeSuccessJSON(map[string]interface{}{
  1583. "sick": mzSick,
  1584. "total": total,
  1585. })
  1586. } else {
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1588. }
  1589. }
  1590. func (c *ManagerCenterApiController) DeleteMZSick() {
  1591. id, _ := c.GetInt64("id", 0)
  1592. err := service.DeleteMZSickById(id)
  1593. if err == nil {
  1594. c.ServeSuccessJSON(map[string]interface{}{
  1595. "msg": "删除成功",
  1596. })
  1597. } else {
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1599. }
  1600. }
  1601. func (c *ManagerCenterApiController) GetMZSick() {
  1602. id, _ := c.GetInt64("id", 0)
  1603. mzSick, err := service.FindMZSickById(id)
  1604. if err == nil {
  1605. c.ServeSuccessJSON(map[string]interface{}{
  1606. "sick": mzSick,
  1607. })
  1608. } else {
  1609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1610. }
  1611. }
  1612. func (c *ManagerCenterApiController) DeleteBaseDrugById() {
  1613. id, _ := c.GetInt64("id")
  1614. //查询入库单
  1615. _, errcode := service.GetDrugWareoutInfo(id)
  1616. if errcode == gorm.ErrRecordNotFound {
  1617. //查询出库单
  1618. _, errcodes := service.GetDrugWareOutById(id)
  1619. if errcodes == gorm.ErrRecordNotFound {
  1620. //删除
  1621. service.DeleteBaseDrugById(id)
  1622. returnData := make(map[string]interface{}, 0)
  1623. returnData["msg"] = "ok"
  1624. c.ServeSuccessJSON(returnData)
  1625. return
  1626. } else if errcodes == nil {
  1627. c.ServeFailJsonSend(enums.ErrorCodeDataException, "已出库")
  1628. return
  1629. }
  1630. } else if errcode == nil {
  1631. c.ServeFailJsonSend(enums.ErrorCodeDataException, "已入库")
  1632. return
  1633. }
  1634. }
  1635. func (c *ManagerCenterApiController) CreateAddition() {
  1636. name := c.GetString("name")
  1637. code := c.GetString("code")
  1638. price, _ := c.GetFloat("price")
  1639. if len(name) <= 0 {
  1640. utils.ErrorLog("len(name) == 0")
  1641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1642. return
  1643. }
  1644. if len(code) <= 0 {
  1645. utils.ErrorLog("len(code) == 0")
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1647. return
  1648. }
  1649. adminUserInfo := c.GetAdminUserInfo()
  1650. addition := models.XtHisAddtionConfig{
  1651. Name: name,
  1652. Code: code,
  1653. Status: 1,
  1654. Price: price,
  1655. Ctime: time.Now().Unix(),
  1656. Mtime: time.Now().Unix(),
  1657. UserOrgId: adminUserInfo.CurrentOrgId,
  1658. }
  1659. err, additions := service.AddSigleAddition(&addition)
  1660. if err == nil {
  1661. c.ServeSuccessJSON(map[string]interface{}{
  1662. "addition": additions,
  1663. })
  1664. } else {
  1665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1666. }
  1667. }
  1668. func (c *ManagerCenterApiController) ModifyAddition() {
  1669. id, _ := c.GetInt64("id", 0)
  1670. name := c.GetString("name")
  1671. code := c.GetString("code")
  1672. price, _ := c.GetFloat("price")
  1673. if id <= 0 {
  1674. utils.ErrorLog("id == 0")
  1675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1676. return
  1677. }
  1678. if len(name) <= 0 {
  1679. utils.ErrorLog("len(class_name) == 0")
  1680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1681. return
  1682. }
  1683. if len(code) <= 0 {
  1684. utils.ErrorLog("len(content_code) == 0")
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1686. return
  1687. }
  1688. adminUserInfo := c.GetAdminUserInfo()
  1689. addition := models.XtHisAddtionConfig{
  1690. ID: id,
  1691. Name: name,
  1692. Code: code,
  1693. Ctime: time.Now().Unix(),
  1694. Mtime: time.Now().Unix(),
  1695. UserOrgId: adminUserInfo.CurrentOrgId,
  1696. Price: price,
  1697. Status: 1,
  1698. }
  1699. err := service.ModifyAddition(&addition)
  1700. if err == nil {
  1701. c.ServeSuccessJSON(map[string]interface{}{
  1702. "addition": addition,
  1703. })
  1704. } else {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1706. }
  1707. }
  1708. func (c *ManagerCenterApiController) GetAdditionList() {
  1709. page, _ := c.GetInt64("page", 1)
  1710. limit, _ := c.GetInt64("limit", 7)
  1711. adminUserInfo := c.GetAdminUserInfo()
  1712. addition, total, err := service.FindAllAdditionList(adminUserInfo.CurrentOrgId, page, limit)
  1713. if err == nil {
  1714. c.ServeSuccessJSON(map[string]interface{}{
  1715. "addition": addition,
  1716. "total": total,
  1717. })
  1718. } else {
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1720. }
  1721. }
  1722. func (c *ManagerCenterApiController) DeleteAddition() {
  1723. id, _ := c.GetInt64("id", 0)
  1724. err := service.DeleteAdditionById(id)
  1725. if err == nil {
  1726. c.ServeSuccessJSON(map[string]interface{}{
  1727. "msg": "删除成功",
  1728. })
  1729. } else {
  1730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1731. }
  1732. }
  1733. func (c *ManagerCenterApiController) GetAddition() {
  1734. id, _ := c.GetInt64("id", 0)
  1735. addition, err := service.FindAdditionById(id)
  1736. if err == nil {
  1737. c.ServeSuccessJSON(map[string]interface{}{
  1738. "addition": addition,
  1739. })
  1740. } else {
  1741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1742. }
  1743. }