manager_center_api_controller.go 48KB

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