manager_center_api_controller.go 48KB

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