面包店
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

204 linhas
5.9 KiB

  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 commNewMake(c *gin.Context, args map[string]string) {
  125. eg := db.Db
  126. sess := eg.NewSession()
  127. defer sess.Close()
  128. sess.Begin()
  129. state := utils.StrToInt(args["state"])
  130. orderGoods := db.GetOrderGoodsMakeStockById(sess, utils.StrToInt64(args["id"]))
  131. if orderGoods == nil {
  132. sess.Rollback()
  133. e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
  134. return
  135. }
  136. if orderGoods.MakeDate > utils.StrToInt(time.Now().Format("20060102")) {
  137. sess.Rollback()
  138. e.OutErr(c, 400, e.NewErr(400, "该订单未到制作时间,请勿提交"))
  139. return
  140. }
  141. WaitMakeNum := orderGoods.WaitMakeNum
  142. if state == 2 { //制作完成
  143. if utils.StrToInt(args["num"]) > orderGoods.WaitMakeNum {
  144. sess.Rollback()
  145. e.OutErr(c, 400, e.NewErr(400, "数量只能提交"+utils.IntToStr(orderGoods.WaitMakeNum)+"个"))
  146. return
  147. }
  148. orderGoods.WaitMakeNum -= utils.StrToInt(args["num"])
  149. orderGoods.WaitBakingNum += utils.StrToInt(args["num"])
  150. if orderGoods.WaitMakeNum < 0 {
  151. orderGoods.WaitMakeNum = 0
  152. }
  153. }
  154. if state == 3 { //烘焙完成
  155. if utils.StrToInt(args["num"]) > orderGoods.WaitBakingNum {
  156. sess.Rollback()
  157. e.OutErr(c, 400, e.NewErr(400, "数量只能提交"+utils.IntToStr(orderGoods.WaitBakingNum)+"个"))
  158. return
  159. }
  160. WaitMakeNum = orderGoods.WaitBakingNum
  161. orderGoods.WaitBakingNum -= utils.StrToInt(args["num"])
  162. orderGoods.WaitSortingNum += utils.StrToInt(args["num"])
  163. if orderGoods.WaitBakingNum < 0 {
  164. orderGoods.WaitBakingNum = 0
  165. }
  166. }
  167. _, err := sess.Where("id=?", orderGoods.Id).Cols("wait_make_num,wait_baking_num,wait_sorting_num").Update(orderGoods)
  168. if err != nil {
  169. sess.Rollback()
  170. e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
  171. return
  172. }
  173. //写入流程记录
  174. var recordFlow = &model.OrderGoodsDoingFlow{
  175. Num: WaitMakeNum,
  176. State: state,
  177. Memo: args["memo"],
  178. SuccessNum: utils.StrToInt(args["num"]),
  179. Time: time.Now(),
  180. Gid: orderGoods.Gid,
  181. SkuId: orderGoods.SkuId,
  182. SkuCode: orderGoods.SkuCode,
  183. AdminId: utils.StrToInt(args["admin_id"]),
  184. GoodsTitle: orderGoods.GoodsTitle,
  185. Sku: orderGoods.Sku,
  186. }
  187. var admin model.Staff
  188. sess.Where("id=?", recordFlow.AdminId).Get(&admin)
  189. recordFlow.AdminName = admin.Name
  190. one, err := sess.InsertOne(recordFlow)
  191. if one == 0 || err != nil {
  192. sess.Rollback()
  193. e.OutErr(c, 400, e.NewErr(400, "操作失败,请重试"))
  194. return
  195. }
  196. sess.Commit()
  197. e.OutSuc(c, "success", nil)
  198. return
  199. }