manager_center_api_controller.go 48KB

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