stock_in_api_controller.go 62KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979
  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. "strings"
  13. "time"
  14. )
  15. type StockManagerApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func StockManagerApiRegistRouters() {
  19. //入库管理和其他入库管理相关接口
  20. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  21. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  22. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  23. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  24. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  25. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  26. //退货管理和其他退货管理相关接口
  27. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  28. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  29. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  30. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  31. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  32. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  33. //出库管理和其他出库管理相关接口
  34. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  35. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  36. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  37. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  38. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  39. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  40. //出库退库管理和其他出库退库管理相关接口
  41. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  42. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  43. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  44. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  45. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  46. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  47. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  48. //库存相关全局配置
  49. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  50. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  51. //库存查询
  52. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  53. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  54. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  55. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  56. }
  57. func (c *StockManagerApiController) CreateWarehouse() {
  58. warehousing_time := c.GetString("warehousing_time")
  59. dealer_id, _ := c.GetInt64("dealer_id", 0)
  60. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  61. types, _ := c.GetInt64("type", 0)
  62. ctime := time.Now().Unix()
  63. adminUserInfo := c.GetAdminUserInfo()
  64. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  65. if parseDateErr != nil {
  66. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  67. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  68. return
  69. }
  70. timeStr := time.Now().Format("2006-01-02")
  71. timeArr := strings.Split(timeStr, "-")
  72. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  73. total = total + 1
  74. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  75. operation_time := time.Now().Unix()
  76. creater := adminUserInfo.AdminUser.Id
  77. warehousing := models.Warehousing{
  78. WarehousingOrder: warehousing_order,
  79. OperationTime: operation_time,
  80. OrgId: adminUserInfo.CurrentOrgId,
  81. Creater: creater,
  82. Ctime: ctime,
  83. Status: 1,
  84. WarehousingTime: warehousingDate.Unix(),
  85. Dealer: dealer_id,
  86. Manufacturer: manufacturer_id,
  87. Type: types,
  88. }
  89. service.AddSigleWarehouse(&warehousing)
  90. dataBody := make(map[string]interface{}, 0)
  91. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  92. if err != nil {
  93. utils.ErrorLog(err.Error())
  94. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  95. return
  96. }
  97. var warehousingInfo []*models.WarehousingInfo
  98. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  99. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  100. if len(thisStockIn) > 0 {
  101. for _, item := range thisStockIn {
  102. items := item.(map[string]interface{})
  103. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  104. utils.ErrorLog("good_id")
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. good_id := int64(items["good_id"].(float64))
  109. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  110. utils.ErrorLog("good_type_id")
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. good_type_id := int64(items["good_type_id"].(float64))
  115. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  116. utils.ErrorLog("warehousing_count")
  117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  118. return
  119. }
  120. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  121. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  122. utils.ErrorLog("price")
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  127. total := float64(warehousing_count) * price
  128. var productDates int64
  129. var expiryDates int64
  130. fmt.Println()
  131. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  132. expiryDates = 0
  133. } else {
  134. if len(items["expiry_date"].(string)) == 0 {
  135. expiryDates = 0
  136. } else {
  137. expiryDate, _ := items["expiry_date"].(string)
  138. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  139. expiryDates = expiry_date.Unix()
  140. }
  141. }
  142. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  143. productDates = 0
  144. } else {
  145. if len(items["product_date"].(string)) == 0 {
  146. productDates = 0
  147. } else {
  148. productDate, _ := items["product_date"].(string)
  149. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  150. productDates = product_date.Unix()
  151. }
  152. }
  153. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  154. utils.ErrorLog("number")
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  156. return
  157. }
  158. number, _ := items["number"].(string)
  159. var remark string
  160. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  161. remark = ""
  162. } else {
  163. remark = items["remark"].(string)
  164. }
  165. warehouseInfo := &models.WarehousingInfo{
  166. WarehousingOrder: warehousing.WarehousingOrder,
  167. WarehousingId: warehousing.ID,
  168. GoodId: good_id,
  169. Number: number,
  170. GoodTypeId: good_type_id,
  171. ProductDate: productDates,
  172. ExpiryDate: expiryDates,
  173. WarehousingCount: warehousing_count,
  174. Price: price,
  175. TotalPrice: total,
  176. Status: 1,
  177. Ctime: ctime,
  178. Remark: remark,
  179. OrgId: adminUserInfo.CurrentOrgId,
  180. Type: types,
  181. Manufacturer: manufacturer_id,
  182. Dealer: dealer_id,
  183. }
  184. warehousingInfo = append(warehousingInfo, warehouseInfo)
  185. }
  186. }
  187. }
  188. errs := service.CreateWarehousingInfo(warehousingInfo)
  189. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  190. if errs != nil {
  191. utils.ErrorLog(errs.Error())
  192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  193. return
  194. }
  195. c.ServeSuccessJSON(map[string]interface{}{
  196. "msg": "入库成功",
  197. "warehousing_order": warehousing_order,
  198. "info": info,
  199. })
  200. //}
  201. //else {
  202. // warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
  203. // if (err1 != nil) {
  204. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  205. // return
  206. // }
  207. //
  208. // dataBody := make(map[string]interface{}, 0)
  209. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  210. // if err != nil {
  211. // utils.ErrorLog(err.Error())
  212. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  213. // return
  214. // }
  215. //
  216. // var warehousingInfo []*models.WarehousingInfo
  217. //
  218. // if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  219. // thisStockIn, _ := dataBody["stockIn"].([]interface{})
  220. // if len(thisStockIn) > 0 {
  221. // for _, item := range thisStockIn {
  222. // items := item.(map[string]interface{})
  223. //
  224. // if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  225. // utils.ErrorLog("good_id")
  226. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  227. // return
  228. // }
  229. // good_id := int64(items["good_id"].(float64))
  230. //
  231. // if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  232. // utils.ErrorLog("good_type_id")
  233. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  234. // return
  235. // }
  236. // good_type_id := int64(items["good_type_id"].(float64))
  237. //
  238. // if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  239. // utils.ErrorLog("warehousing_count")
  240. // c.ServeFailJSONWithSGJErrorCod Fe(enums.ErrorCodeParamWrong)
  241. // return
  242. // }
  243. //
  244. // warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  245. //
  246. // if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  247. // utils.ErrorLog("price")
  248. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  249. // return
  250. // }
  251. // price, _ := strconv.ParseFloat(items["price"].(string), 64)
  252. // total := float64(warehousing_count) * price
  253. //
  254. // if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  255. // utils.ErrorLog("expiry_date")
  256. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. // return
  258. // }
  259. //
  260. // expiryDate, _ := items["expiry_date"].(string)
  261. // if len(expiryDate) == 0 {
  262. // utils.ErrorLog("len(expiry_date) == 0")
  263. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  264. //
  265. // return
  266. // }
  267. //
  268. // expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  269. // if parseDateErr != nil {
  270. // c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
  271. // }
  272. //
  273. // var productDates int64
  274. //
  275. // if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  276. // productDates = 0;
  277. // } else {
  278. // productDate, _ := items["product_date"].(string)
  279. // product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  280. // productDates = product_date.Unix()
  281. //
  282. // }
  283. //
  284. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  285. // utils.ErrorLog("number")
  286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  287. // return
  288. // }
  289. // number, _ := items["number"].(string)
  290. //
  291. // var remark string
  292. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  293. // remark = ""
  294. // } else {
  295. // remark = items["remark"].(string)
  296. // }
  297. //
  298. // warehouseInfo := &models.WarehousingInfo{
  299. // WarehousingOrder: warehousing_order,
  300. // WarehousingId: warehouse.ID,
  301. // GoodId: good_id,
  302. // Number: number,
  303. // GoodTypeId: good_type_id,
  304. // ProductDate: productDates,
  305. // ExpiryDate: expiry_date.Unix(),
  306. // WarehousingCount: warehousing_count,
  307. // Price: price,
  308. // TotalPrice: total,
  309. // Status: 1,
  310. // Ctime: ctime,
  311. // Remark: remark,
  312. // OrgId: adminUserInfo.CurrentOrgId,
  313. // }
  314. // warehousingInfo = append(warehousingInfo, warehouseInfo)
  315. //
  316. // }
  317. // }
  318. // }
  319. // errs := service.CreateWarehousingInfo(warehousingInfo)
  320. // info, _ := service.FindLastWarehousingInfo(warehousing_order)
  321. //
  322. // if (errs != nil) {
  323. // utils.ErrorLog(errs.Error())
  324. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  325. // return
  326. // }
  327. //
  328. // c.ServeSuccessJSON(map[string]interface{}{
  329. // "msg": "入库成功",
  330. // "info": info,
  331. // })
  332. //
  333. //}
  334. }
  335. func (c *StockManagerApiController) GetWarehouseList() {
  336. page, _ := c.GetInt64("page", -1)
  337. limit, _ := c.GetInt64("limit", -1)
  338. start_time := c.GetString("start_time")
  339. end_time := c.GetString("end_time")
  340. types, _ := c.GetInt64("type", 0)
  341. keywords := c.GetString("keywords")
  342. fmt.Println(start_time)
  343. fmt.Println(end_time)
  344. timeLayout := "2006-01-02"
  345. loc, _ := time.LoadLocation("Local")
  346. var startTime int64
  347. if len(start_time) > 0 {
  348. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  349. if err != nil {
  350. fmt.Println(err)
  351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  352. return
  353. }
  354. startTime = theTime.Unix()
  355. }
  356. var endTime int64
  357. if len(end_time) > 0 {
  358. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  359. if err != nil {
  360. utils.ErrorLog(err.Error())
  361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  362. return
  363. }
  364. endTime = theTime.Unix()
  365. }
  366. adminUserInfo := c.GetAdminUserInfo()
  367. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  368. if err == nil {
  369. c.ServeSuccessJSON(map[string]interface{}{
  370. "list": warehouseList,
  371. "total": total,
  372. })
  373. } else {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  375. }
  376. }
  377. func (c *StockManagerApiController) GetWarehouseInfoList() {
  378. id, _ := c.GetInt64("id", 0)
  379. if id <= 0 {
  380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  381. return
  382. }
  383. warehousing, err := service.FindWarehousingById(id)
  384. if err != nil {
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  386. return
  387. }
  388. if warehousing.ID <= 0 {
  389. return
  390. }
  391. warehousingInfo, err := service.FindWarehousingInfoById(id)
  392. if err == nil {
  393. c.ServeSuccessJSON(map[string]interface{}{
  394. "info": warehousingInfo,
  395. "warehousing": warehousing,
  396. })
  397. } else {
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  399. }
  400. }
  401. func (c *StockManagerApiController) EditWarehouse() {
  402. warehousing_time := c.GetString("warehousing_time")
  403. id, _ := c.GetInt64("id", 0)
  404. types, _ := c.GetInt64("type", 0)
  405. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  406. dealer_id, _ := c.GetInt64("dealer_id", 0)
  407. if id == 0 {
  408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  409. return
  410. }
  411. ctime := time.Now().Unix()
  412. mtime := time.Now().Unix()
  413. adminUserInfo := c.GetAdminUserInfo()
  414. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  415. if parseDateErr != nil {
  416. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. return
  419. }
  420. warehouse, _ := service.FindWarehousingById(id)
  421. warehousing := models.Warehousing{
  422. WarehousingOrder: warehouse.WarehousingOrder,
  423. OrgId: adminUserInfo.CurrentOrgId,
  424. Modifier: adminUserInfo.AdminUser.Id,
  425. Mtime: mtime,
  426. Status: 1,
  427. WarehousingTime: warehousingDate.Unix(),
  428. Type: warehouse.Type,
  429. Dealer: dealer_id,
  430. Manufacturer: manufacturer_id,
  431. }
  432. service.EditWarehousing(warehousing)
  433. dataBody := make(map[string]interface{}, 0)
  434. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  435. if err != nil {
  436. utils.ErrorLog(err.Error())
  437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  438. return
  439. }
  440. var warehousingInfo []*models.WarehousingInfo
  441. var upDateWarehousingInfo []*models.WarehousingInfo
  442. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  443. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  444. if len(thisStockIn) > 0 {
  445. for _, item := range thisStockIn {
  446. items := item.(map[string]interface{})
  447. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  448. utils.ErrorLog("good_id")
  449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  450. return
  451. }
  452. good_id := int64(items["good_id"].(float64))
  453. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  454. utils.ErrorLog("good_type_id")
  455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  456. return
  457. }
  458. good_type_id := int64(items["good_type_id"].(float64))
  459. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  460. utils.ErrorLog("warehousing_count")
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  462. return
  463. }
  464. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  465. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  466. utils.ErrorLog("price")
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  468. return
  469. }
  470. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  471. total := float64(warehousing_count) * price
  472. var productDates int64
  473. var expiryDates int64
  474. fmt.Println()
  475. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  476. expiryDates = 0
  477. } else {
  478. if len(items["expiry_date"].(string)) == 0 {
  479. expiryDates = 0
  480. } else {
  481. expiryDate, _ := items["expiry_date"].(string)
  482. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  483. expiryDates = expiry_date.Unix()
  484. }
  485. }
  486. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  487. productDates = 0
  488. } else {
  489. if len(items["product_date"].(string)) == 0 {
  490. productDates = 0
  491. } else {
  492. productDate, _ := items["product_date"].(string)
  493. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  494. productDates = product_date.Unix()
  495. }
  496. }
  497. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  498. utils.ErrorLog("number")
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  500. return
  501. }
  502. number, _ := items["number"].(string)
  503. var remark string
  504. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  505. remark = ""
  506. } else {
  507. remark = items["remark"].(string)
  508. }
  509. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  510. utils.ErrorLog("id")
  511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  512. return
  513. }
  514. id := int64(items["id"].(float64))
  515. if id == 0 {
  516. warehouseInfo := &models.WarehousingInfo{
  517. WarehousingOrder: warehouse.WarehousingOrder,
  518. WarehousingId: warehouse.ID,
  519. GoodId: good_id,
  520. Number: number,
  521. GoodTypeId: good_type_id,
  522. ProductDate: productDates,
  523. ExpiryDate: expiryDates,
  524. WarehousingCount: warehousing_count,
  525. Price: price,
  526. TotalPrice: total,
  527. Status: 1,
  528. Ctime: ctime,
  529. Remark: remark,
  530. OrgId: adminUserInfo.CurrentOrgId,
  531. Type: types,
  532. Manufacturer: manufacturer_id,
  533. Dealer: dealer_id,
  534. }
  535. warehousingInfo = append(warehousingInfo, warehouseInfo)
  536. } else {
  537. warehouseInfo := &models.WarehousingInfo{
  538. ID: id,
  539. WarehousingOrder: warehouse.WarehousingOrder,
  540. WarehousingId: warehouse.ID,
  541. GoodId: good_id,
  542. Number: number,
  543. GoodTypeId: good_type_id,
  544. ProductDate: productDates,
  545. ExpiryDate: expiryDates,
  546. WarehousingCount: warehousing_count,
  547. Price: price,
  548. TotalPrice: total,
  549. Status: 1,
  550. Ctime: ctime,
  551. Remark: remark,
  552. OrgId: adminUserInfo.CurrentOrgId,
  553. Type: types,
  554. Manufacturer: manufacturer_id,
  555. Dealer: dealer_id,
  556. }
  557. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  558. }
  559. }
  560. }
  561. }
  562. var errs error
  563. if len(warehousingInfo) > 0 {
  564. errs = service.CreateWarehousingInfo(warehousingInfo)
  565. }
  566. if len(upDateWarehousingInfo) > 0 {
  567. for _, item := range upDateWarehousingInfo {
  568. errs = service.UpDateWarehousingInfo(item)
  569. }
  570. }
  571. if errs != nil {
  572. utils.ErrorLog(errs.Error())
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  574. return
  575. }
  576. c.ServeSuccessJSON(map[string]interface{}{
  577. "msg": "编辑成功",
  578. })
  579. }
  580. func (c *StockManagerApiController) DeleteWarehouse() {
  581. ids := c.GetString("ids")
  582. if len(ids) == 0 {
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  584. return
  585. }
  586. idArray := strings.Split(ids, ",")
  587. err := service.DeleteWarehouse(idArray)
  588. if err != nil {
  589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  590. } else {
  591. c.ServeSuccessJSON(map[string]interface{}{
  592. "msg": "删除成功",
  593. })
  594. }
  595. }
  596. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  597. id, _ := c.GetInt64("id", 0)
  598. if id == 0 {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  600. return
  601. }
  602. err := service.UpDateWarehouseStatus(id)
  603. if err != nil {
  604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  605. } else {
  606. c.ServeSuccessJSON(map[string]interface{}{
  607. "msg": "删除成功",
  608. })
  609. }
  610. }
  611. func (c *StockManagerApiController) CreateSalesReturn() {
  612. dealer_id, _ := c.GetInt64("dealer_id", 0)
  613. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  614. sales_return_time := c.GetString("time")
  615. types, _ := c.GetInt64("type", 0)
  616. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  617. if parseDateErr != nil {
  618. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. adminUserInfo := c.GetAdminUserInfo()
  623. operation_time := time.Now().Unix()
  624. creater := adminUserInfo.AdminUser.Id
  625. ctime := time.Now().Unix()
  626. timeStr := time.Now().Format("2006-01-02")
  627. timeArr := strings.Split(timeStr, "-")
  628. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  629. total = total + 1
  630. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  631. salesReturn := models.SalesReturn{
  632. OrderNumber: orderNumber,
  633. OperaTime: operation_time,
  634. OrgId: adminUserInfo.CurrentOrgId,
  635. Creater: creater,
  636. Ctime: ctime,
  637. Status: 1,
  638. ReturnTime: salesReturnDate.Unix(),
  639. Dealer: dealer_id,
  640. Manufacturer: manufacturer_id,
  641. Type: types,
  642. }
  643. service.AddSigleSalesReturn(&salesReturn)
  644. dataBody := make(map[string]interface{}, 0)
  645. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  646. if err != nil {
  647. utils.ErrorLog(err.Error())
  648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  649. return
  650. }
  651. var salesReturnInfos []*models.SalesReturnInfo
  652. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  653. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  654. if len(thisStockIn) > 0 {
  655. for _, item := range thisStockIn {
  656. items := item.(map[string]interface{})
  657. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  658. utils.ErrorLog("good_id")
  659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  660. return
  661. }
  662. good_id := int64(items["good_id"].(float64))
  663. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  664. utils.ErrorLog("good_type_id")
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. return
  667. }
  668. good_type_id := int64(items["good_type_id"].(float64))
  669. return_count, _ := items["return_count"].(string)
  670. if len(return_count) == 0 {
  671. utils.ErrorLog("len(return_count) == 0")
  672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  673. return
  674. }
  675. count, _ := strconv.ParseInt(return_count, 10, 64)
  676. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  677. total := float64(count) * price
  678. salesReturnInfo := &models.SalesReturnInfo{
  679. OrderNumber: salesReturn.OrderNumber,
  680. SalesReturnId: salesReturn.ID,
  681. GoodId: good_id,
  682. GoodTypeId: good_type_id,
  683. Count: count,
  684. Price: price,
  685. Total: total,
  686. Status: 1,
  687. Ctime: ctime,
  688. OrgId: adminUserInfo.CurrentOrgId,
  689. Type: types,
  690. Manufacturer: manufacturer_id,
  691. Dealer: dealer_id,
  692. }
  693. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  694. }
  695. }
  696. }
  697. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  698. if errs != nil {
  699. utils.ErrorLog(errs.Error())
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  701. return
  702. }
  703. c.ServeSuccessJSON(map[string]interface{}{
  704. "msg": "退货成功",
  705. })
  706. }
  707. func (c *StockManagerApiController) GetSalesReturnList() {
  708. page, _ := c.GetInt64("page", -1)
  709. limit, _ := c.GetInt64("limit", -1)
  710. start_time := c.GetString("start_time")
  711. end_time := c.GetString("end_time")
  712. types, _ := c.GetInt64("type", 0)
  713. keywords := c.GetString("keywords")
  714. timeLayout := "2006-01-02"
  715. loc, _ := time.LoadLocation("Local")
  716. var startTime int64
  717. if len(start_time) > 0 {
  718. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  719. if err != nil {
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  721. return
  722. }
  723. startTime = theTime.Unix()
  724. }
  725. var endTime int64
  726. if len(end_time) > 0 {
  727. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  728. if err != nil {
  729. utils.ErrorLog(err.Error())
  730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  731. return
  732. }
  733. endTime = theTime.Unix()
  734. }
  735. adminUserInfo := c.GetAdminUserInfo()
  736. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  737. if err == nil {
  738. c.ServeSuccessJSON(map[string]interface{}{
  739. "list": returnList,
  740. "total": total,
  741. })
  742. } else {
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  744. }
  745. }
  746. func (this *StockManagerApiController) DeleteSalesReturn() {
  747. ids := this.GetString("ids")
  748. if len(ids) == 0 {
  749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  750. return
  751. }
  752. idArray := strings.Split(ids, ",")
  753. err := service.DeleteSalesReturn(idArray)
  754. if err != nil {
  755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  756. } else {
  757. this.ServeSuccessJSON(map[string]interface{}{
  758. "msg": "删除成功",
  759. })
  760. }
  761. }
  762. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  763. id, _ := this.GetInt64("id", 0)
  764. fmt.Println(id)
  765. if id == 0 {
  766. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  767. return
  768. }
  769. err := service.UpDateSaleReturnStatus(id)
  770. if err != nil {
  771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  772. } else {
  773. this.ServeSuccessJSON(map[string]interface{}{
  774. "msg": "删除成功",
  775. })
  776. }
  777. }
  778. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  779. id, _ := this.GetInt64("id", 0)
  780. list, _ := service.FindAllSalesReturnInfoById(id)
  781. salesReturn, _ := service.FindAllSalesReturnById(id)
  782. this.ServeSuccessJSON(map[string]interface{}{
  783. "list": list,
  784. "salesReturn": salesReturn,
  785. })
  786. }
  787. func (c *StockManagerApiController) EditReturnInfo() {
  788. return_time := c.GetString("return_time")
  789. id, _ := c.GetInt64("id", 0)
  790. types, _ := c.GetInt64("type", 0)
  791. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  792. dealer_id, _ := c.GetInt64("dealer_id", 0)
  793. if id == 0 {
  794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  795. return
  796. }
  797. ctime := time.Now().Unix()
  798. mtime := time.Now().Unix()
  799. adminUserInfo := c.GetAdminUserInfo()
  800. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  801. if parseDateErr != nil {
  802. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  804. return
  805. }
  806. salesReturns, _ := service.FindSalesReturnById(id)
  807. sales := models.SalesReturn{
  808. ID: salesReturns.ID,
  809. Mtime: mtime,
  810. ReturnTime: returnDate.Unix(),
  811. Manufacturer: manufacturer_id,
  812. Dealer: dealer_id,
  813. }
  814. service.EditSaleReturn(sales)
  815. dataBody := make(map[string]interface{}, 0)
  816. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  817. if err != nil {
  818. utils.ErrorLog(err.Error())
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  820. return
  821. }
  822. var returnInfos []*models.SalesReturnInfo
  823. var upDateReturnInfos []*models.SalesReturnInfo
  824. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  825. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  826. if len(thisStockIn) > 0 {
  827. for _, item := range thisStockIn {
  828. items := item.(map[string]interface{})
  829. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  830. utils.ErrorLog("good_id")
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. good_id := int64(items["good_id"].(float64))
  835. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  836. utils.ErrorLog("good_type_id")
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. good_type_id := int64(items["good_type_id"].(float64))
  841. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  842. utils.ErrorLog("count")
  843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  844. return
  845. }
  846. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  847. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  848. utils.ErrorLog("id")
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  850. return
  851. }
  852. id := int64(items["id"].(float64))
  853. if id == 0 {
  854. returnInfo := &models.SalesReturnInfo{
  855. GoodId: good_id,
  856. GoodTypeId: good_type_id,
  857. Count: count,
  858. Status: 1,
  859. Ctime: ctime,
  860. OrgId: adminUserInfo.CurrentOrgId,
  861. OrderNumber: sales.OrderNumber,
  862. SalesReturnId: sales.ID,
  863. Mtime: time.Now().Unix(),
  864. Type: types,
  865. Manufacturer: manufacturer_id,
  866. Dealer: dealer_id,
  867. }
  868. returnInfos = append(returnInfos, returnInfo)
  869. } else {
  870. returnInfo := &models.SalesReturnInfo{
  871. ID: id,
  872. GoodId: good_id,
  873. GoodTypeId: good_type_id,
  874. Count: count,
  875. Status: 1,
  876. Ctime: ctime,
  877. OrgId: adminUserInfo.CurrentOrgId,
  878. OrderNumber: sales.OrderNumber,
  879. SalesReturnId: sales.ID,
  880. Mtime: time.Now().Unix(),
  881. Type: types,
  882. Manufacturer: manufacturer_id,
  883. Dealer: dealer_id,
  884. }
  885. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  886. }
  887. }
  888. }
  889. }
  890. var errs error
  891. if len(returnInfos) > 0 {
  892. errs = service.CreateSalesReturnInfo(returnInfos)
  893. }
  894. if len(upDateReturnInfos) > 0 {
  895. for _, item := range upDateReturnInfos {
  896. errs = service.UpDateSalesReturnInfo(item)
  897. }
  898. }
  899. if errs != nil {
  900. utils.ErrorLog(errs.Error())
  901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  902. return
  903. }
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "编辑成功",
  906. })
  907. }
  908. func (c *StockManagerApiController) CreateWarehouseOut() {
  909. dealer_id, _ := c.GetInt64("dealer_id", 0)
  910. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  911. types, _ := c.GetInt64("type", 0)
  912. ctime := time.Now().Unix()
  913. adminUserInfo := c.GetAdminUserInfo()
  914. warehousing_out_time := c.GetString("warehousing_out_time")
  915. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  916. if parseDateErr != nil {
  917. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  919. return
  920. }
  921. timeStr := time.Now().Format("2006-01-02")
  922. timeArr := strings.Split(timeStr, "-")
  923. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  924. total = total + 1
  925. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  926. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  927. number = number + total
  928. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  929. operation_time := time.Now().Unix()
  930. creater := adminUserInfo.AdminUser.Id
  931. warehouseOut := models.WarehouseOut{
  932. WarehouseOutOrderNumber: warehousing_out_order,
  933. OperationTime: operation_time,
  934. OrgId: adminUserInfo.CurrentOrgId,
  935. Creater: creater,
  936. Ctime: ctime,
  937. Status: 1,
  938. WarehouseOutTime: warehousingOutDate.Unix(),
  939. Dealer: dealer_id,
  940. Manufacturer: manufacturer_id,
  941. Type: types,
  942. }
  943. service.AddSigleWarehouseOut(&warehouseOut)
  944. dataBody := make(map[string]interface{}, 0)
  945. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  946. if err != nil {
  947. utils.ErrorLog(err.Error())
  948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  949. return
  950. }
  951. var warehousingOutInfo []*models.WarehouseOutInfo
  952. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  953. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  954. if len(thisStockIn) > 0 {
  955. for _, item := range thisStockIn {
  956. items := item.(map[string]interface{})
  957. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  958. utils.ErrorLog("good_id")
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. good_id := int64(items["good_id"].(float64))
  963. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  964. utils.ErrorLog("good_type_id")
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. good_type_id := int64(items["good_type_id"].(float64))
  969. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  970. utils.ErrorLog("count")
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  972. return
  973. }
  974. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  975. utils.ErrorLog("price")
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  977. return
  978. }
  979. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  980. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  981. total := float64(count) * price
  982. remark := items["remark"].(string)
  983. warehouseOutInfo := &models.WarehouseOutInfo{
  984. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  985. WarehouseOutId: warehouseOut.ID,
  986. GoodId: good_id,
  987. GoodTypeId: good_type_id,
  988. Count: count,
  989. Price: price,
  990. TotalPrice: total,
  991. Status: 1,
  992. Ctime: ctime,
  993. Remark: remark,
  994. OrgId: adminUserInfo.CurrentOrgId,
  995. Type: types,
  996. Manufacturer: manufacturer_id,
  997. Dealer: dealer_id,
  998. }
  999. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1000. }
  1001. }
  1002. }
  1003. errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1004. info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1005. if errs != nil {
  1006. utils.ErrorLog(errs.Error())
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1008. return
  1009. }
  1010. c.ServeSuccessJSON(map[string]interface{}{
  1011. "msg": "出库成功",
  1012. "info": info,
  1013. "warehousing_out_order": warehousing_out_order,
  1014. })
  1015. }
  1016. func (c *StockManagerApiController) GetWarehouseOutList() {
  1017. page, _ := c.GetInt64("page", -1)
  1018. limit, _ := c.GetInt64("limit", -1)
  1019. start_time := c.GetString("start_time")
  1020. end_time := c.GetString("end_time")
  1021. types, _ := c.GetInt64("type", 0)
  1022. keywords := c.GetString("keywords")
  1023. timeLayout := "2006-01-02"
  1024. loc, _ := time.LoadLocation("Local")
  1025. var startTime int64
  1026. if len(start_time) > 0 {
  1027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1028. if err != nil {
  1029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1030. return
  1031. }
  1032. startTime = theTime.Unix()
  1033. }
  1034. var endTime int64
  1035. if len(end_time) > 0 {
  1036. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1037. if err != nil {
  1038. utils.ErrorLog(err.Error())
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1040. return
  1041. }
  1042. endTime = theTime.Unix()
  1043. }
  1044. adminUserInfo := c.GetAdminUserInfo()
  1045. warehouseOutList, total, err := service.FindAllWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1046. fmt.Println(err)
  1047. if err == nil {
  1048. c.ServeSuccessJSON(map[string]interface{}{
  1049. "list": warehouseOutList,
  1050. "total": total,
  1051. })
  1052. } else {
  1053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1054. }
  1055. }
  1056. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1057. ids := c.GetString("ids")
  1058. if len(ids) == 0 {
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. idArray := strings.Split(ids, ",")
  1063. err := service.DeleteWarehouseOut(idArray)
  1064. if err != nil {
  1065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1066. } else {
  1067. c.ServeSuccessJSON(map[string]interface{}{
  1068. "msg": "删除成功",
  1069. })
  1070. }
  1071. }
  1072. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1073. id, _ := this.GetInt64("id", 0)
  1074. fmt.Println(id)
  1075. if id == 0 {
  1076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1077. return
  1078. }
  1079. err := service.UpDateWarehouseOutStatus(id)
  1080. if err != nil {
  1081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1082. } else {
  1083. this.ServeSuccessJSON(map[string]interface{}{
  1084. "msg": "删除成功",
  1085. })
  1086. }
  1087. }
  1088. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1089. id, _ := c.GetInt64("id", 0)
  1090. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1091. warehouseOut, _ := service.FindWareHouseOutById(id)
  1092. c.ServeSuccessJSON(map[string]interface{}{
  1093. "list": warehouseOutInfo,
  1094. "info": warehouseOut,
  1095. })
  1096. }
  1097. func (c *StockManagerApiController) EditWarehouseOut() {
  1098. warehouse_out_time := c.GetString("warehouse_out_time")
  1099. id, _ := c.GetInt64("id", 0)
  1100. types, _ := c.GetInt64("type", 0)
  1101. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1102. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1103. if id == 0 {
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1105. return
  1106. }
  1107. ctime := time.Now().Unix()
  1108. mtime := time.Now().Unix()
  1109. adminUserInfo := c.GetAdminUserInfo()
  1110. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1111. if parseDateErr != nil {
  1112. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1114. return
  1115. }
  1116. warehouseOut, _ := service.FindWareHouseOutById(id)
  1117. tempWarehouseOut := models.WarehouseOut{
  1118. ID: warehouseOut.ID,
  1119. Mtime: mtime,
  1120. WarehouseOutTime: warehouseOutDate.Unix(),
  1121. Manufacturer: manufacturer_id,
  1122. Dealer: dealer_id,
  1123. }
  1124. service.EditWarehouseOut(tempWarehouseOut)
  1125. dataBody := make(map[string]interface{}, 0)
  1126. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1127. if err != nil {
  1128. utils.ErrorLog(err.Error())
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1130. return
  1131. }
  1132. var warehousingOutInfo []*models.WarehouseOutInfo
  1133. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1134. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1135. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1136. if len(thisStockOut) > 0 {
  1137. for _, item := range thisStockOut {
  1138. items := item.(map[string]interface{})
  1139. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1140. utils.ErrorLog("good_id")
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1142. return
  1143. }
  1144. good_id := int64(items["good_id"].(float64))
  1145. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1146. utils.ErrorLog("good_type_id")
  1147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1148. return
  1149. }
  1150. good_type_id := int64(items["good_type_id"].(float64))
  1151. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1152. utils.ErrorLog("count")
  1153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1154. return
  1155. }
  1156. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1157. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1158. utils.ErrorLog("price")
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1160. return
  1161. }
  1162. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1163. total := float64(count) * price
  1164. remark := items["remark"].(string)
  1165. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1166. utils.ErrorLog("id")
  1167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1168. return
  1169. }
  1170. id := int64(items["id"].(float64))
  1171. if id == 0 {
  1172. warehouseOutInfo := &models.WarehouseOutInfo{
  1173. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1174. WarehouseOutId: warehouseOut.ID,
  1175. GoodId: good_id,
  1176. GoodTypeId: good_type_id,
  1177. Count: count,
  1178. Price: price,
  1179. TotalPrice: total,
  1180. Status: 1,
  1181. Ctime: ctime,
  1182. Remark: remark,
  1183. OrgId: adminUserInfo.CurrentOrgId,
  1184. Type: types,
  1185. Manufacturer: manufacturer_id,
  1186. Dealer: dealer_id,
  1187. IsSys: 0,
  1188. SysRecordTime: 0,
  1189. }
  1190. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1191. } else {
  1192. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1193. utils.ErrorLog("is_sys")
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1195. return
  1196. }
  1197. is_sys := int64(items["is_sys"].(float64))
  1198. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1199. utils.ErrorLog("sys_record_time")
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1201. return
  1202. }
  1203. sys_record_time := int64(items["sys_record_time"].(float64))
  1204. warehouseOutInfo := &models.WarehouseOutInfo{
  1205. ID: id,
  1206. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1207. WarehouseOutId: warehouseOut.ID,
  1208. GoodId: good_id,
  1209. GoodTypeId: good_type_id,
  1210. Count: count,
  1211. Price: price,
  1212. TotalPrice: total,
  1213. Status: 1,
  1214. Ctime: ctime,
  1215. Remark: remark,
  1216. OrgId: adminUserInfo.CurrentOrgId,
  1217. Mtime: time.Now().Unix(),
  1218. Type: types,
  1219. Manufacturer: manufacturer_id,
  1220. Dealer: dealer_id,
  1221. IsSys: is_sys,
  1222. SysRecordTime: sys_record_time,
  1223. }
  1224. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1225. }
  1226. }
  1227. }
  1228. }
  1229. var errs error
  1230. if len(warehousingOutInfo) > 0 {
  1231. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1232. }
  1233. if len(upDateWarehouseOutInfos) > 0 {
  1234. for _, item := range upDateWarehouseOutInfos {
  1235. errs = service.UpDateWarehouseOutInfo(item)
  1236. }
  1237. }
  1238. if errs != nil {
  1239. utils.ErrorLog(errs.Error())
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1241. return
  1242. }
  1243. c.ServeSuccessJSON(map[string]interface{}{
  1244. "msg": "编辑成功",
  1245. })
  1246. }
  1247. func (c *StockManagerApiController) CreateCancelStock() {
  1248. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1249. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1250. cancel_stock_time := c.GetString("time")
  1251. types, _ := c.GetInt64("type", 0)
  1252. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1253. if parseDateErr != nil {
  1254. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. adminUserInfo := c.GetAdminUserInfo()
  1259. operation_time := time.Now().Unix()
  1260. creater := adminUserInfo.AdminUser.Id
  1261. ctime := time.Now().Unix()
  1262. timeStr := time.Now().Format("2006-01-02")
  1263. timeArr := strings.Split(timeStr, "-")
  1264. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1265. total = total + 1
  1266. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1267. cancelStock := models.CancelStock{
  1268. OrderNumber: orderNumber,
  1269. OperaTime: operation_time,
  1270. OrgId: adminUserInfo.CurrentOrgId,
  1271. Creater: creater,
  1272. Ctime: ctime,
  1273. Status: 1,
  1274. ReturnTime: cancelStockDate.Unix(),
  1275. Dealer: dealer_id,
  1276. Manufacturer: manufacturer_id,
  1277. Type: types,
  1278. }
  1279. service.AddSigleCancelStock(&cancelStock)
  1280. dataBody := make(map[string]interface{}, 0)
  1281. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1282. if err != nil {
  1283. utils.ErrorLog(err.Error())
  1284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1285. return
  1286. }
  1287. var cancelStockInfos []*models.CancelStockInfo
  1288. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1289. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1290. if len(thisStockIn) > 0 {
  1291. for _, item := range thisStockIn {
  1292. items := item.(map[string]interface{})
  1293. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1294. utils.ErrorLog("good_id")
  1295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1296. return
  1297. }
  1298. good_id := int64(items["good_id"].(float64))
  1299. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1300. utils.ErrorLog("good_type_id")
  1301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1302. return
  1303. }
  1304. good_type_id := int64(items["good_type_id"].(float64))
  1305. return_count, _ := items["return_count"].(string)
  1306. if len(return_count) == 0 {
  1307. utils.ErrorLog("len(return_count) == 0")
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1309. return
  1310. }
  1311. count, _ := strconv.ParseInt(return_count, 10, 64)
  1312. cancelStockInfo := &models.CancelStockInfo{
  1313. OrderNumber: cancelStock.OrderNumber,
  1314. CancelStockId: cancelStock.ID,
  1315. GoodId: good_id,
  1316. GoodTypeId: good_type_id,
  1317. Count: count,
  1318. Status: 1,
  1319. Ctime: ctime,
  1320. OrgId: adminUserInfo.CurrentOrgId,
  1321. Type: types,
  1322. Manufacturer: manufacturer_id,
  1323. Dealer: dealer_id,
  1324. }
  1325. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1326. }
  1327. }
  1328. }
  1329. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1330. if errs != nil {
  1331. utils.ErrorLog(errs.Error())
  1332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1333. return
  1334. }
  1335. c.ServeSuccessJSON(map[string]interface{}{
  1336. "msg": "退库成功",
  1337. })
  1338. }
  1339. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1340. id, _ := c.GetInt64("id", 0)
  1341. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1342. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1343. c.ServeSuccessJSON(map[string]interface{}{
  1344. "list": cancelStockInfoList,
  1345. "info": info,
  1346. })
  1347. }
  1348. func (c *StockManagerApiController) GetCancelStockList() {
  1349. page, _ := c.GetInt64("page", -1)
  1350. limit, _ := c.GetInt64("limit", -1)
  1351. start_time := c.GetString("start_time")
  1352. end_time := c.GetString("end_time")
  1353. types, _ := c.GetInt64("type", 0)
  1354. keywords := c.GetString("keywords")
  1355. timeLayout := "2006-01-02"
  1356. loc, _ := time.LoadLocation("Local")
  1357. var startTime int64
  1358. if len(start_time) > 0 {
  1359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1360. if err != nil {
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. startTime = theTime.Unix()
  1365. }
  1366. var endTime int64
  1367. if len(end_time) > 0 {
  1368. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1369. if err != nil {
  1370. utils.ErrorLog(err.Error())
  1371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1372. return
  1373. }
  1374. endTime = theTime.Unix()
  1375. }
  1376. adminUserInfo := c.GetAdminUserInfo()
  1377. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1378. if err == nil {
  1379. c.ServeSuccessJSON(map[string]interface{}{
  1380. "list": returnList,
  1381. "total": total,
  1382. })
  1383. } else {
  1384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1385. }
  1386. }
  1387. func (this *StockManagerApiController) DeleteCancelStock() {
  1388. ids := this.GetString("ids")
  1389. if len(ids) == 0 {
  1390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1391. return
  1392. }
  1393. idArray := strings.Split(ids, ",")
  1394. err := service.DeleteCancelStock(idArray)
  1395. if err != nil {
  1396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1397. } else {
  1398. this.ServeSuccessJSON(map[string]interface{}{
  1399. "msg": "删除成功",
  1400. })
  1401. }
  1402. }
  1403. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1404. id, _ := this.GetInt64("id", 0)
  1405. fmt.Println(id)
  1406. if id == 0 {
  1407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1408. return
  1409. }
  1410. err := service.UpDateCancleStockStatus(id)
  1411. if err != nil {
  1412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1413. } else {
  1414. this.ServeSuccessJSON(map[string]interface{}{
  1415. "msg": "删除成功",
  1416. })
  1417. }
  1418. }
  1419. func (c *StockManagerApiController) EditCancelStock() {
  1420. cancel_time := c.GetString("cancel_time")
  1421. id, _ := c.GetInt64("id", 0)
  1422. types, _ := c.GetInt64("type", 0)
  1423. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1424. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1425. if id == 0 {
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. ctime := time.Now().Unix()
  1430. mtime := time.Now().Unix()
  1431. adminUserInfo := c.GetAdminUserInfo()
  1432. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1433. if parseDateErr != nil {
  1434. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1436. return
  1437. }
  1438. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1439. tempCancelStock := models.CancelStock{
  1440. ID: cancelStock.ID,
  1441. Mtime: mtime,
  1442. ReturnTime: cancelDate.Unix(),
  1443. Manufacturer: manufacturer_id,
  1444. Dealer: dealer_id,
  1445. }
  1446. service.EditCancelStock(tempCancelStock)
  1447. dataBody := make(map[string]interface{}, 0)
  1448. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1449. if err != nil {
  1450. utils.ErrorLog(err.Error())
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1452. return
  1453. }
  1454. var cancelStockInfos []*models.CancelStockInfo
  1455. var upDateCancelStockInfos []*models.CancelStockInfo
  1456. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1457. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1458. if len(thisCancelStock) > 0 {
  1459. for _, item := range thisCancelStock {
  1460. items := item.(map[string]interface{})
  1461. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1462. utils.ErrorLog("good_id")
  1463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1464. return
  1465. }
  1466. good_id := int64(items["good_id"].(float64))
  1467. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1468. utils.ErrorLog("good_type_id")
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. good_type_id := int64(items["good_type_id"].(float64))
  1473. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1474. utils.ErrorLog("count")
  1475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1476. return
  1477. }
  1478. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1479. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1480. utils.ErrorLog("id")
  1481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1482. return
  1483. }
  1484. id := int64(items["id"].(float64))
  1485. if id == 0 {
  1486. cancelStockInfo := &models.CancelStockInfo{
  1487. GoodId: good_id,
  1488. GoodTypeId: good_type_id,
  1489. Count: count,
  1490. Status: 1,
  1491. Ctime: ctime,
  1492. OrgId: adminUserInfo.CurrentOrgId,
  1493. OrderNumber: cancelStock.OrderNumber,
  1494. CancelStockId: cancelStock.ID,
  1495. Mtime: time.Now().Unix(),
  1496. Type: types,
  1497. Manufacturer: manufacturer_id,
  1498. Dealer: dealer_id,
  1499. }
  1500. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1501. } else {
  1502. cancelStockInfo := &models.CancelStockInfo{
  1503. ID: id,
  1504. GoodId: good_id,
  1505. GoodTypeId: good_type_id,
  1506. Count: count,
  1507. Status: 1,
  1508. Ctime: ctime,
  1509. OrgId: adminUserInfo.CurrentOrgId,
  1510. OrderNumber: cancelStock.OrderNumber,
  1511. CancelStockId: cancelStock.ID,
  1512. Mtime: time.Now().Unix(),
  1513. Type: types,
  1514. Manufacturer: manufacturer_id,
  1515. Dealer: dealer_id,
  1516. }
  1517. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1518. }
  1519. }
  1520. }
  1521. }
  1522. var errs error
  1523. if len(cancelStockInfos) > 0 {
  1524. errs = service.CreateCancelStockInfo(cancelStockInfos)
  1525. }
  1526. if len(upDateCancelStockInfos) > 0 {
  1527. for _, item := range upDateCancelStockInfos {
  1528. errs = service.UpDateCancelStockInfo(item)
  1529. }
  1530. }
  1531. if errs != nil {
  1532. utils.ErrorLog(errs.Error())
  1533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1534. return
  1535. }
  1536. c.ServeSuccessJSON(map[string]interface{}{
  1537. "msg": "编辑成功",
  1538. })
  1539. }
  1540. func (this *StockManagerApiController) GetCancelStockConfig() {
  1541. types, _ := this.GetInt64("type", 0)
  1542. adminUserInfo := this.GetAdminUserInfo()
  1543. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  1544. this.ServeSuccessJSON(map[string]interface{}{
  1545. "warehouseOutInfoList": warehouseOutInfoList,
  1546. })
  1547. }
  1548. func (c *StockManagerApiController) GetQueryInfo() {
  1549. page, _ := c.GetInt64("page", -1)
  1550. limit, _ := c.GetInt64("limit", -1)
  1551. keyword := c.GetString("keyword")
  1552. start_time := c.GetString("start_time")
  1553. end_time := c.GetString("end_time")
  1554. type_name, _ := c.GetInt64("type_name")
  1555. timeLayout := "2006-01-02"
  1556. loc, _ := time.LoadLocation("Local")
  1557. var startTime int64
  1558. if len(start_time) > 0 {
  1559. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1560. if err != nil {
  1561. fmt.Println(err)
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1563. return
  1564. }
  1565. startTime = theTime.Unix()
  1566. }
  1567. var endTime int64
  1568. if len(end_time) > 0 {
  1569. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1570. if err != nil {
  1571. utils.ErrorLog(err.Error())
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1573. return
  1574. }
  1575. endTime = theTime.Unix()
  1576. }
  1577. adminUserInfo := c.GetAdminUserInfo()
  1578. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  1579. if err == nil {
  1580. c.ServeSuccessJSON(map[string]interface{}{
  1581. "list": list,
  1582. "total": total,
  1583. })
  1584. } else {
  1585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1586. }
  1587. }
  1588. func (c *StockManagerApiController) SearchWarehouse() {
  1589. keywords := c.GetString("keywords")
  1590. adminUserInfo := c.GetAdminUserInfo()
  1591. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  1592. if err == nil {
  1593. c.ServeSuccessJSON(map[string]interface{}{
  1594. "list": warehouseList,
  1595. "total": total,
  1596. })
  1597. } else {
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1599. }
  1600. }
  1601. func (c *StockManagerApiController) GetAllConfig() {
  1602. adminUserInfo := c.GetAdminUserInfo()
  1603. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1604. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1605. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  1606. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  1607. c.ServeSuccessJSON(map[string]interface{}{
  1608. "manufacturer": manufacturer,
  1609. "dealer": dealer,
  1610. "goodType": goodType,
  1611. "goodInfo": goodInfo,
  1612. })
  1613. }
  1614. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  1615. types, _ := this.GetInt64("type", 0)
  1616. adminUserInfo := this.GetAdminUserInfo()
  1617. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  1618. this.ServeSuccessJSON(map[string]interface{}{
  1619. "warehouseInfoList": warehouseInfoList,
  1620. })
  1621. }
  1622. func (this *StockManagerApiController) GetDetailInfo() {
  1623. page, _ := this.GetInt64("page", 0)
  1624. limit, _ := this.GetInt64("limit", 0)
  1625. start_time := this.GetString("start_time")
  1626. end_time := this.GetString("end_time")
  1627. types, _ := this.GetInt64("type", 0)
  1628. keywords := this.GetString("keywords")
  1629. manufacturer, _ := this.GetInt64("manufacturer", 0)
  1630. order_type, _ := this.GetInt64("order_type", 0)
  1631. dealer, _ := this.GetInt64("dealer", 0)
  1632. timeLayout := "2006-01-02"
  1633. loc, _ := time.LoadLocation("Local")
  1634. var startTime int64
  1635. if len(start_time) > 0 {
  1636. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1637. if err != nil {
  1638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. startTime = theTime.Unix()
  1642. }
  1643. var endTime int64
  1644. if len(end_time) > 0 {
  1645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1646. if err != nil {
  1647. utils.ErrorLog(err.Error())
  1648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1649. return
  1650. }
  1651. endTime = theTime.Unix()
  1652. }
  1653. adminUserInfo := this.GetAdminUserInfo()
  1654. var list []*models.WarehousingInfo
  1655. var list1 []*models.WarehouseOutInfo
  1656. var list2 []*models.SalesReturnInfo
  1657. var list3 []*models.CancelStockInfo
  1658. var total int64
  1659. var err error
  1660. var total_price float64
  1661. if types == 1 {
  1662. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1663. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1664. if err == nil {
  1665. this.ServeSuccessJSON(map[string]interface{}{
  1666. "list": list,
  1667. "total": total,
  1668. "total_price": total_price,
  1669. })
  1670. } else {
  1671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1672. }
  1673. } else if types == 2 {
  1674. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1675. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1676. if err == nil {
  1677. this.ServeSuccessJSON(map[string]interface{}{
  1678. "list": list1,
  1679. "total": total,
  1680. "total_price": total_price,
  1681. })
  1682. } else {
  1683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1684. }
  1685. } else if types == 3 {
  1686. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1687. if err == nil {
  1688. this.ServeSuccessJSON(map[string]interface{}{
  1689. "list": list2,
  1690. "total": total,
  1691. })
  1692. } else {
  1693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1694. }
  1695. } else if types == 4 {
  1696. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1697. if err == nil {
  1698. this.ServeSuccessJSON(map[string]interface{}{
  1699. "list": list3,
  1700. "total": total,
  1701. })
  1702. } else {
  1703. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1704. }
  1705. }
  1706. }
  1707. func (this *StockManagerApiController) GetUserDetailInfo() {
  1708. order_id, _ := this.GetInt64("id")
  1709. if order_id <= 0 {
  1710. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1711. return
  1712. }
  1713. adminUserInfo := this.GetAdminUserInfo()
  1714. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  1715. if err == nil {
  1716. this.ServeSuccessJSON(map[string]interface{}{
  1717. "list": userDetails,
  1718. "total": total,
  1719. })
  1720. } else {
  1721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1722. return
  1723. }
  1724. }
  1725. func (this *StockManagerApiController) PostSearchStock() {
  1726. keyword := this.GetString("keyword")
  1727. fmt.Println("keyword2222222222222", keyword)
  1728. adminUserInfo := this.GetAdminUserInfo()
  1729. orgId := adminUserInfo.CurrentOrgId
  1730. stock, err := service.PostSearchStock(keyword, orgId)
  1731. if err != nil {
  1732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1733. }
  1734. this.ServeSuccessJSON(map[string]interface{}{
  1735. "stock": stock,
  1736. })
  1737. }