面包店
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

svc_order_make.go 8.8 KiB

pirms 8 mēnešiem
pirms 5 mēnešiem
pirms 8 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 6 mēnešiem
pirms 5 mēnešiem
pirms 7 mēnešiem
pirms 6 mēnešiem
pirms 7 mēnešiem
pirms 7 mēnešiem
pirms 7 mēnešiem
pirms 7 mēnešiem
pirms 6 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 4 mēnešiem
pirms 4 mēnešiem
pirms 6 mēnešiem
pirms 6 mēnešiem
pirms 7 mēnešiem
pirms 7 mēnešiem
pirms 7 mēnešiem
pirms 7 mēnešiem
pirms 6 mēnešiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package svc
  2. import (
  3. "applet/app/admin/svc/order"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. "applet/app/e"
  7. "applet/app/ipad/md"
  8. "applet/app/utils"
  9. "github.com/gin-gonic/gin"
  10. "time"
  11. )
  12. func NewOrderMakeEnd(c *gin.Context) {
  13. var args map[string]string
  14. if err := c.ShouldBindJSON(&args); err != nil {
  15. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  16. return
  17. }
  18. args["state"] = "2"
  19. args["str"] = "烘焙"
  20. commNewMake(c, args)
  21. }
  22. func NewOrderBakingEnd(c *gin.Context) {
  23. var args map[string]string
  24. if err := c.ShouldBindJSON(&args); err != nil {
  25. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  26. return
  27. }
  28. args["state"] = "3"
  29. args["str"] = "烘焙"
  30. commNewMake(c, args)
  31. }
  32. func NewOrderSortingEnd(c *gin.Context) {
  33. var args md.NewOrderSorting
  34. if err := c.ShouldBindJSON(&args); err != nil {
  35. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  36. return
  37. }
  38. eg := db.Db
  39. sess := eg.NewSession()
  40. defer sess.Close()
  41. sess.Begin()
  42. //修改制作记录
  43. oids := make([]string, 0)
  44. for _, v := range args.OrderInfo {
  45. oids = append(oids, v["oid"])
  46. record := db.GetOrderGoods(sess, v["oid"], args.Gid, args.SkuId)
  47. if record.MakeDate > utils.StrToInt(time.Now().Format("20060102")) {
  48. sess.Rollback()
  49. e.OutErr(c, 400, e.NewErr(400, v["oid"]+",未到制作时间,请勿提交"))
  50. return
  51. }
  52. if utils.StrToInt(v["num"]) > record.Num-record.SuccessNum {
  53. sess.Rollback()
  54. e.OutErr(c, 400, e.NewErr(400, record.GoodsTitle+",数量只能提交"+utils.IntToStr(record.Num-record.SuccessNum)+"个"))
  55. return
  56. }
  57. record.SuccessNum += utils.StrToInt(v["num"])
  58. if record.SuccessNum >= record.Num {
  59. record.State = 4
  60. }
  61. record.AdminId = utils.StrToInt(args.AdminId)
  62. record.Time = time.Now()
  63. _, err := sess.Where("id=?", record.Id).Cols("success_num,state,time").Update(record)
  64. if err != nil {
  65. sess.Rollback()
  66. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  67. return
  68. }
  69. makeRecord := db.GetOrderGoodsMakeStockByDate(sess, utils.StrToInt64(args.Gid), utils.StrToInt64(args.SkuId), record.MakeDate)
  70. if utils.StrToInt(v["num"]) > makeRecord.WaitSortingNum {
  71. sess.Rollback()
  72. e.OutErr(c, 400, e.NewErr(400, record.GoodsTitle+",数量只能提交"+utils.IntToStr(makeRecord.WaitSortingNum)+"个"))
  73. return
  74. }
  75. makeRecord.WaitSortingNum -= utils.StrToInt(v["num"])
  76. makeRecord.SuccessNum += utils.StrToInt(v["num"])
  77. _, err = sess.Where("id=?", makeRecord.Id).Cols("success_num,wait_sorting_num").Update(makeRecord)
  78. if err != nil {
  79. sess.Rollback()
  80. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  81. return
  82. }
  83. //写入流程记录
  84. var recordFlow = &model.OrderGoodsDoingFlow{
  85. Num: record.Num,
  86. State: 4,
  87. Memo: "",
  88. SuccessNum: utils.StrToInt(v["num"]),
  89. Time: time.Now(),
  90. Gid: record.GoodsId,
  91. SkuId: record.SkuId,
  92. SkuCode: record.SkuCode,
  93. AdminId: utils.StrToInt(args.AdminId),
  94. GoodsTitle: record.GoodsTitle,
  95. Sku: record.Sku,
  96. }
  97. var admin model.Staff
  98. sess.Where("id=?", recordFlow.AdminId).Get(&admin)
  99. recordFlow.AdminName = admin.Name
  100. one, err := sess.InsertOne(recordFlow)
  101. if one == 0 || err != nil {
  102. sess.Rollback()
  103. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  104. return
  105. }
  106. }
  107. if len(oids) > 0 {
  108. ord := db.GetOrderByIdsSess(sess, oids)
  109. if ord != nil {
  110. for _, v := range *ord {
  111. err := order.JudgePackageOrdOrdStateSess(sess, &v)
  112. if err != nil {
  113. sess.Rollback()
  114. e.OutErr(c, 400, e.NewErr(400, "请重新提交"))
  115. return
  116. }
  117. }
  118. }
  119. }
  120. sess.Commit()
  121. e.OutSuc(c, "success", nil)
  122. return
  123. }
  124. func NewOrderSortingEndByOrder(c *gin.Context) {
  125. var args md.OrderSorting
  126. if err := c.ShouldBindJSON(&args); err != nil {
  127. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  128. return
  129. }
  130. eg := db.Db
  131. sess := eg.NewSession()
  132. defer sess.Close()
  133. sess.Begin()
  134. //修改制作记录
  135. oids := make([]string, 0)
  136. oids = append(oids, args.Oid)
  137. for _, v := range args.GoodsInfo {
  138. record := db.GetOrderGoods(sess, args.Oid, v["gid"], v["sku_id"])
  139. if record.MakeDate > utils.StrToInt(time.Now().Format("20060102")) {
  140. sess.Rollback()
  141. e.OutErr(c, 400, e.NewErr(400, v["oid"]+",未到制作时间,请勿提交"))
  142. return
  143. }
  144. if utils.StrToInt(v["num"]) > record.Num-record.SuccessNum {
  145. sess.Rollback()
  146. e.OutErr(c, 400, e.NewErr(400, record.GoodsTitle+",数量只能提交"+utils.IntToStr(record.Num-record.SuccessNum)+"个"))
  147. return
  148. }
  149. record.SuccessNum += utils.StrToInt(v["num"])
  150. if record.SuccessNum >= record.Num {
  151. record.State = 4
  152. }
  153. record.AdminId = utils.StrToInt(args.AdminId)
  154. record.Time = time.Now()
  155. _, err := sess.Where("id=?", record.Id).Cols("success_num,state,time").Update(record)
  156. if err != nil {
  157. sess.Rollback()
  158. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  159. return
  160. }
  161. makeRecord := db.GetOrderGoodsMakeStockByDate(sess, utils.StrToInt64(v["gid"]), utils.StrToInt64(v["sku_id"]), record.MakeDate)
  162. if utils.StrToInt(v["num"]) > makeRecord.WaitSortingNum {
  163. sess.Rollback()
  164. e.OutErr(c, 400, e.NewErr(400, record.GoodsTitle+",数量只能提交"+utils.IntToStr(makeRecord.WaitSortingNum)+"个"))
  165. return
  166. }
  167. makeRecord.WaitSortingNum -= utils.StrToInt(v["num"])
  168. makeRecord.SuccessNum += utils.StrToInt(v["num"])
  169. _, err = sess.Where("id=?", makeRecord.Id).Cols("success_num,wait_sorting_num").Update(makeRecord)
  170. if err != nil {
  171. sess.Rollback()
  172. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  173. return
  174. }
  175. //写入流程记录
  176. var recordFlow = &model.OrderGoodsDoingFlow{
  177. Num: record.Num,
  178. State: 4,
  179. Memo: "",
  180. SuccessNum: utils.StrToInt(v["num"]),
  181. Time: time.Now(),
  182. Gid: record.GoodsId,
  183. SkuId: record.SkuId,
  184. SkuCode: record.SkuCode,
  185. AdminId: utils.StrToInt(args.AdminId),
  186. GoodsTitle: record.GoodsTitle,
  187. Sku: record.Sku,
  188. }
  189. var admin model.Staff
  190. sess.Where("id=?", recordFlow.AdminId).Get(&admin)
  191. recordFlow.AdminName = admin.Name
  192. one, err := sess.InsertOne(recordFlow)
  193. if one == 0 || err != nil {
  194. sess.Rollback()
  195. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  196. return
  197. }
  198. }
  199. if len(oids) > 0 {
  200. ord := db.GetOrderByIdsSess(sess, oids)
  201. if ord != nil {
  202. for _, v := range *ord {
  203. err := order.JudgePackageOrdOrdStateSess(sess, &v)
  204. if err != nil {
  205. sess.Rollback()
  206. e.OutErr(c, 400, e.NewErr(400, "请重新提交"))
  207. return
  208. }
  209. }
  210. }
  211. }
  212. sess.Commit()
  213. e.OutSuc(c, "success", nil)
  214. return
  215. }
  216. func commNewMake(c *gin.Context, args map[string]string) {
  217. eg := db.Db
  218. sess := eg.NewSession()
  219. defer sess.Close()
  220. sess.Begin()
  221. state := utils.StrToInt(args["state"])
  222. orderGoods := db.GetOrderGoodsMakeStockById(sess, utils.StrToInt64(args["id"]))
  223. if orderGoods == nil {
  224. sess.Rollback()
  225. e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
  226. return
  227. }
  228. if orderGoods.MakeDate > utils.StrToInt(time.Now().Format("20060102")) {
  229. sess.Rollback()
  230. e.OutErr(c, 400, e.NewErr(400, "该订单未到制作时间,请勿提交"))
  231. return
  232. }
  233. WaitMakeNum := orderGoods.WaitMakeNum
  234. if state == 2 { //制作完成
  235. if utils.StrToInt(args["num"]) > orderGoods.WaitMakeNum {
  236. sess.Rollback()
  237. e.OutErr(c, 400, e.NewErr(400, "数量只能提交"+utils.IntToStr(orderGoods.WaitMakeNum)+"个"))
  238. return
  239. }
  240. orderGoods.WaitMakeNum -= utils.StrToInt(args["num"])
  241. orderGoods.WaitBakingNum += utils.StrToInt(args["num"])
  242. if orderGoods.WaitMakeNum < 0 {
  243. orderGoods.WaitMakeNum = 0
  244. }
  245. }
  246. if state == 3 { //烘焙完成
  247. if utils.StrToInt(args["num"]) > orderGoods.WaitBakingNum {
  248. sess.Rollback()
  249. e.OutErr(c, 400, e.NewErr(400, "数量只能提交"+utils.IntToStr(orderGoods.WaitBakingNum)+"个"))
  250. return
  251. }
  252. WaitMakeNum = orderGoods.WaitBakingNum
  253. orderGoods.WaitBakingNum -= utils.StrToInt(args["num"])
  254. orderGoods.WaitSortingNum += utils.StrToInt(args["num"])
  255. if orderGoods.WaitBakingNum < 0 {
  256. orderGoods.WaitBakingNum = 0
  257. }
  258. }
  259. _, err := sess.Where("id=?", orderGoods.Id).Cols("wait_make_num,wait_baking_num,wait_sorting_num").Update(orderGoods)
  260. if err != nil {
  261. sess.Rollback()
  262. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  263. return
  264. }
  265. //写入流程记录
  266. var recordFlow = &model.OrderGoodsDoingFlow{
  267. Num: WaitMakeNum,
  268. State: state,
  269. Memo: args["memo"],
  270. SuccessNum: utils.StrToInt(args["num"]),
  271. Time: time.Now(),
  272. Gid: orderGoods.Gid,
  273. SkuId: orderGoods.SkuId,
  274. SkuCode: orderGoods.SkuCode,
  275. AdminId: utils.StrToInt(args["admin_id"]),
  276. GoodsTitle: orderGoods.GoodsTitle,
  277. Sku: orderGoods.Sku,
  278. }
  279. var admin model.Staff
  280. sess.Where("id=?", recordFlow.AdminId).Get(&admin)
  281. recordFlow.AdminName = admin.Name
  282. one, err := sess.InsertOne(recordFlow)
  283. if one == 0 || err != nil {
  284. sess.Rollback()
  285. e.OutErr(c, 400, e.NewErr(400, "操作失败,请重试"))
  286. return
  287. }
  288. sess.Commit()
  289. e.OutSuc(c, "success", nil)
  290. return
  291. }