promotion_helper.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package helpers
  2. import (
  3. "fmt"
  4. "fohow.com/apps/models/balance_model"
  5. "fohow.com/apps/models/cent_model"
  6. "fohow.com/apps/models/order_model"
  7. "fohow.com/apps/models/product_model"
  8. "fohow.com/apps/models/promotion_model"
  9. "fohow.com/apps/models/user_model"
  10. "fohow.com/libs/tool"
  11. "github.com/astaxie/beego"
  12. "time"
  13. )
  14. //订单促销
  15. /*
  16. 如果促销条件中,设置的项目有一项不满足即视为不满足促销条件
  17. */
  18. func SetOrderPromotion(orderId string, wxUid int64) {
  19. beego.BeeLogger.Warn("******* SetOrderPromotion orderId:%s wxUid:%d", orderId, wxUid)
  20. firstOrder := false
  21. //获取订单明细
  22. order := order_model.GetOrderById(orderId, false)
  23. if order == nil {
  24. return
  25. }
  26. //检查会员是否首次下单
  27. list := order_model.GetWxUserOrders(wxUid)
  28. if len(list) == 1 {
  29. firstOrder = true
  30. }
  31. queryDate := time.Now()
  32. // 获取所有有效促销记录
  33. effectivePromotions := promotion_model.GetEffetivePromotions(queryDate, order.OrderType, order.Depart, false)
  34. for _, item := range effectivePromotions {
  35. //beego.Warn("item_name%d", item.Name)
  36. firstFlag := true
  37. totalFlag := true
  38. numsFlag := true
  39. if item.MaxTotal > 0 && order.TotalPrice > item.MaxTotal {
  40. totalFlag = false
  41. continue
  42. }
  43. if item.IsFirst && !firstOrder {
  44. firstFlag = false
  45. continue
  46. }
  47. if item.MinTotal > 0 && order.TotalPrice < item.MinTotal {
  48. totalFlag = false
  49. firstFlag = false
  50. continue
  51. }
  52. nums := int64(999)
  53. nums1 := int64(999)
  54. nums2 := int64(999)
  55. nums3 := int64(999)
  56. nums4 := int64(999)
  57. nums5 := int64(999)
  58. nums6 := int64(999)
  59. if item.Prod1 > 0 {
  60. prd := product_model.GetProductById(item.Prod1, true)
  61. nums1 = int64(0)
  62. if prd != nil {
  63. detail_nums1 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
  64. if detail_nums1 > int64(0) && item.Prod1 > 0 && item.Nums1 > 0 {
  65. nums1 = int64(detail_nums1 / item.Nums1)
  66. }
  67. }
  68. }
  69. if item.Prod2 > 0 {
  70. prd := product_model.GetProductById(item.Prod2, true)
  71. nums2 = int64(0)
  72. if prd != nil {
  73. detail_nums2 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
  74. if detail_nums2 > int64(0) && item.Prod2 > 0 && item.Nums2 > 0 {
  75. nums2 = int64(detail_nums2 / item.Nums2)
  76. }
  77. }
  78. }
  79. if item.Prod3 > 0 {
  80. prd := product_model.GetProductById(item.Prod3, true)
  81. if prd != nil {
  82. nums3 = int64(0)
  83. detail_nums3 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
  84. if detail_nums3 > 0 && item.Prod3 > 0 && item.Nums3 > 0 {
  85. nums3 = int64(detail_nums3 / item.Nums3)
  86. }
  87. }
  88. }
  89. if item.MinTotal > 0 {
  90. nums4 = int64(order.TotalPrice / item.MinTotal)
  91. }
  92. if item.Prod4 > 0 {
  93. prd := product_model.GetProductById(item.Prod4, true)
  94. nums5 = int64(0)
  95. if prd != nil {
  96. detail_nums4 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
  97. if detail_nums4 > 0 && item.Prod4 > 0 && item.Nums4 > 0 {
  98. nums5 = int64(detail_nums4 / item.Nums4)
  99. }
  100. }
  101. }
  102. if item.Prod5 > 0 {
  103. prd := product_model.GetProductById(item.Prod5, true)
  104. nums6 = int64(0)
  105. if prd != nil {
  106. detail_nums5 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
  107. if detail_nums5 > 0 && item.Prod5 > 0 && item.Nums5 > 0 {
  108. nums6 = int64(detail_nums5 / item.Nums5)
  109. }
  110. }
  111. }
  112. val := []int64{nums1, nums2, nums3, nums4, nums5, nums6}
  113. nums = tool.Min(val...)
  114. if !item.IsMore {
  115. val := []int64{nums, 1}
  116. nums = tool.Min(val...)
  117. }
  118. if nums == int64(999) || nums == int64(0) {
  119. numsFlag = false
  120. }
  121. /* beego.Warn("item_name-1%d", item.Name)
  122. beego.Warn("firstFlag%v", firstFlag)
  123. beego.Warn("totalFlag%v", totalFlag)
  124. beego.Warn("numsFlag%v", numsFlag)
  125. beego.Warn("nums%d", nums)*/
  126. //满足促销条件
  127. if firstFlag && totalFlag && numsFlag {
  128. if item.SendProd1 > 0 && item.SendNums1 > 0 {
  129. sendNums1 := nums * item.SendNums1
  130. //赠送赠品1
  131. product := product_model.GetProductById(item.SendProd1, true)
  132. go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums1, order.Depart)
  133. }
  134. if item.SendProd2 > 0 && item.SendNums2 > 0 {
  135. sendNums2 := nums * item.SendNums2
  136. //赠送赠品1
  137. product := product_model.GetProductById(item.SendProd2, true)
  138. go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums2, order.Depart)
  139. }
  140. if item.SendProd3 > 0 && item.SendNums3 > 0 {
  141. sendNums3 := nums * item.SendNums3
  142. //赠送赠品1
  143. product := product_model.GetProductById(item.SendProd3, true)
  144. go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums3, order.Depart)
  145. }
  146. if item.SendProd4 > 0 && item.SendNums4 > 0 {
  147. sendNums4 := nums * item.SendNums4
  148. //赠送赠品1
  149. product := product_model.GetProductById(item.SendProd4, true)
  150. go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums4, order.Depart)
  151. }
  152. if item.SendProd5 > 0 && item.SendNums5 > 0 {
  153. sendNums5 := nums * item.SendNums5
  154. //赠送赠品1
  155. product := product_model.GetProductById(item.SendProd5, true)
  156. go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums5, order.Depart)
  157. }
  158. //赠送积分 or 代办费
  159. if item.Cash > 0 {
  160. totalCash := nums * item.Cash
  161. source := balance_model.BALANCE_SOURCE_PROMOTION
  162. remark := fmt.Sprintf("促销赠送提货券")
  163. new(balance_model.Balance).Create(order.WxUserId, order.UserId, totalCash, source, order.OrderId, remark)
  164. }
  165. if item.Cent > 0 {
  166. totalCent := nums * item.Cent
  167. source := cent_model.PROMOTION_SEND
  168. remark := fmt.Sprintf("促销活动赠送")
  169. new(cent_model.CentBalance).Create(order.WxUserId, totalCent, source, order.OrderId, remark)
  170. }
  171. }
  172. }
  173. }
  174. func max(vals ...int64) int64 {
  175. var max int64
  176. for _, val := range vals {
  177. if val > max {
  178. max = val
  179. }
  180. }
  181. return max
  182. }
  183. /*
  184. 找到所有当前时间>《开始时间》且 当前时间<《结束时间》 且《是否启用》=1的促销记录
  185. { flag1=1,flag2=1,flag3=1
  186. NUMs=99,NUMs1=99,NUMs2=99,NUMs3=99,NUMs4=99
  187. 如果《是否首次下单》=是,且当前订单不是首次订单,则flag1=0
  188. 如果《最大金额》>0则要求订单金额大于此项值,则flag2=0
  189. 如果:《购买产品ID1》>0且《购买数量1》>0则NUMs1=购买产品ID1的数量/《购买数量1》
  190. 如果:《购买产品ID2》>0且《购买数量2》>0则当前订单中NUMs2=购买产品ID2的数量/《购买数量2》
  191. 如果:《购买产品ID3》>0且《购买数量3》>0则当前订单中NUMs3=购买产品ID3的数量/《购买数量3》
  192. 如果:《最小金额》>0则要求订单金额大于或等于此项值,则NUMs4=订单金额/《最小金额》
  193. NUMs=min(NUMs1,NUMs2,NUMs3,NUMs4);
  194. if(NUMs=99或NUMs=0) 则flag3=0
  195. 如果《是否多买多送》=否,NUMs=MIN(1,NUMs)
  196. if(flag1=1并且flag2=1并且flag3=1)
  197. { 如果《赠送产品ID1》>0且《赠送数量1》>0,则按《赠送数量1》*NUMs赠送《赠送产品ID1》;
  198. 如果《赠送产品ID2》>0且《赠送数量2》>0,则按《赠送数量2》*NUMs赠送《赠送产品ID2》;
  199. 如果《赠送产品ID3》>0且《赠送数量3》>0,则按《赠送数量3》*NUMs赠送《赠送产品ID3》;
  200. }
  201. 找下一个促销记录
  202. }
  203. */
  204. //充值促销
  205. func BalanceOrderPromotion(orderId string, wxUid, depart int64) {
  206. beego.BeeLogger.Warn("******* BalanceOrderPromotion orderId:%s wxUid:%d", orderId, wxUid)
  207. //获取订单明细
  208. balanceOrder := balance_model.GetBalanceOrderByOId(orderId, false)
  209. if balanceOrder == nil {
  210. return
  211. }
  212. queryDate := time.Now()
  213. // 获取所有有效促销记录
  214. effectivePromotions := promotion_model.GetBalanceEffetivePromotions(queryDate, depart, false)
  215. for _, item := range effectivePromotions {
  216. //beego.Warn("item_name%d", item.Name)
  217. totalFlag := true
  218. numsFlag := true
  219. if item.MaxTotal > 0 && balanceOrder.PaiedPrice > item.MaxTotal {
  220. totalFlag = false
  221. continue
  222. }
  223. if item.MinTotal > 0 && balanceOrder.PaiedPrice < item.MinTotal {
  224. totalFlag = false
  225. continue
  226. }
  227. count := int64(0)
  228. if item.MinTotal > 0 {
  229. count = int64(balanceOrder.PaiedPrice / item.MinTotal)
  230. }
  231. if count == int64(0) {
  232. numsFlag = false
  233. }
  234. if !item.IsMore {
  235. val := []int64{count, 1}
  236. count = tool.Min(val...)
  237. }
  238. beego.Warn("item_name-1%d", item.Name)
  239. beego.Warn("totalFlag%v", totalFlag)
  240. beego.Warn("numsFlag%v", numsFlag)
  241. beego.Warn("nums%d", count)
  242. //满足促销条件
  243. if totalFlag && numsFlag {
  244. source := promotion_model.SOURCE_BALANCE
  245. remark := fmt.Sprintf("充值订单(%s)充值成功--促销(%s)", orderId, item.Name)
  246. if item.SendProd1 > 0 && item.SendNums1 > 0 {
  247. sendNums1 := count * item.SendNums1
  248. //生成赠品
  249. product := product_model.GetProductById(item.SendProd1, true)
  250. if product != nil {
  251. total := sendNums1 * product.Price
  252. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums1, source, remark)
  253. }
  254. }
  255. if item.SendProd2 > 0 && item.SendNums2 > 0 {
  256. sendNums2 := count * item.SendNums2
  257. //赠送赠品1
  258. product := product_model.GetProductById(item.SendProd2, true)
  259. if product != nil {
  260. total := sendNums2 * product.Price
  261. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums2, source, remark)
  262. }
  263. }
  264. if item.SendProd3 > 0 && item.SendNums3 > 0 {
  265. sendNums3 := count * item.SendNums3
  266. //赠送赠品3
  267. product := product_model.GetProductById(item.SendProd3, true)
  268. if product != nil {
  269. total := sendNums3 * product.Price
  270. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums3, source, remark)
  271. }
  272. }
  273. //赠送积分 or 代办费
  274. if item.Cash > 0 {
  275. totalCash := count * item.Cash
  276. source := balance_model.BALANCE_SOURCE_BALANCE_RECHARGE_PROMOTION
  277. remark := fmt.Sprintf("充值促销赠送提货券")
  278. new(balance_model.Balance).Create(balanceOrder.WxUserId, balanceOrder.UserId, totalCash, source, balanceOrder.OrderId, remark)
  279. }
  280. if item.Cent > 0 {
  281. totalCent := count * item.Cent
  282. source := cent_model.PROMOTION_SEND
  283. remark := fmt.Sprintf("充值促销活动赠送")
  284. new(cent_model.CentBalance).Create(balanceOrder.WxUserId, totalCent, source, balanceOrder.OrderId, remark)
  285. }
  286. }
  287. }
  288. }
  289. //店长申请促销
  290. func ShopOrderPromotion(shopApplyId, wxUid, depart int64) {
  291. beego.BeeLogger.Warn("******* ShopOrderPromotion shopApplyId:%d wxUid:%d", shopApplyId, wxUid)
  292. //获取订单明细
  293. shopApply := user_model.GetShopApplicationById(shopApplyId)
  294. if shopApply == nil {
  295. return
  296. }
  297. queryDate := time.Now()
  298. // 获取所有有效促销记录
  299. effectivePromotions := promotion_model.GetShopEffetivePromotions(queryDate, depart, false)
  300. for _, item := range effectivePromotions {
  301. //beego.Warn("item_name%d", item.Name)
  302. totalFlag := true
  303. numsFlag := true
  304. if item.Total > 0 && shopApply.Total != item.Total {
  305. totalFlag = false
  306. continue
  307. }
  308. count := int64(0)
  309. if item.Total > 0 {
  310. count = int64(1)
  311. }
  312. if count == int64(0) {
  313. numsFlag = false
  314. }
  315. beego.Warn("item_name-1%d", item.Name)
  316. beego.Warn("totalFlag%v", totalFlag)
  317. beego.Warn("numsFlag%v", numsFlag)
  318. beego.Warn("nums%d", count)
  319. //满足促销条件
  320. if totalFlag && numsFlag {
  321. orderId := fmt.Sprintf("shopapply-(%d)", shopApply.Id)
  322. source := promotion_model.SOURCE_SHOP
  323. remark := fmt.Sprintf("店长申请成功(%d)--促销(%s)", shopApply.Id, item.Name)
  324. if item.SendProd1 > 0 && item.SendNums1 > 0 {
  325. sendNums1 := count * item.SendNums1
  326. //生成赠品
  327. product := product_model.GetProductById(item.SendProd1, true)
  328. if product != nil {
  329. total := sendNums1 * product.Price
  330. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums1, source, remark)
  331. }
  332. }
  333. if item.SendProd2 > 0 && item.SendNums2 > 0 {
  334. sendNums2 := count * item.SendNums2
  335. //赠送赠品1
  336. product := product_model.GetProductById(item.SendProd2, true)
  337. if product != nil {
  338. total := sendNums2 * product.Price
  339. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums2, source, remark)
  340. }
  341. }
  342. if item.SendProd3 > 0 && item.SendNums3 > 0 {
  343. sendNums3 := count * item.SendNums3
  344. //赠送赠品3
  345. product := product_model.GetProductById(item.SendProd3, true)
  346. if product != nil {
  347. total := sendNums3 * product.Price
  348. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums3, source, remark)
  349. }
  350. }
  351. if item.SendProd4 > 0 && item.SendNums4 > 0 {
  352. sendNums4 := count * item.SendNums4
  353. //赠送赠品4
  354. product := product_model.GetProductById(item.SendProd4, true)
  355. if product != nil {
  356. total := sendNums4 * product.Price
  357. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums4, source, remark)
  358. }
  359. }
  360. if item.SendProd5 > 0 && item.SendNums5 > 0 {
  361. sendNums5 := count * item.SendNums5
  362. //赠送赠品3
  363. product := product_model.GetProductById(item.SendProd5, true)
  364. if product != nil {
  365. total := sendNums5 * product.Price
  366. go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums5, source, remark)
  367. }
  368. }
  369. //赠送积分 or 代办费
  370. if item.Cash > 0 {
  371. totalCash := count * item.Cash
  372. source := balance_model.BALANCE_SOURCE_SHOP_PROMOTION
  373. remark := fmt.Sprintf("店长申请促销赠送提货券")
  374. new(balance_model.Balance).Create(shopApply.WxUId, shopApply.UserId, totalCash, source, orderId, remark)
  375. }
  376. if item.Cent > 0 {
  377. totalCent := count * item.Cent
  378. source := cent_model.PROMOTION_SEND
  379. remark := fmt.Sprintf("店长申请促销活动赠送")
  380. new(cent_model.CentBalance).Create(shopApply.WxUId, totalCent, source, orderId, remark)
  381. }
  382. }
  383. }
  384. }
  385. //赠品明细写入订单
  386. func PresentTransferToOrder(orderId string, wxUid int64) {
  387. beego.BeeLogger.Warn("******* PresentTransferToOrder shopApplyId:%s wxUid:%d", orderId, wxUid)
  388. //获取订单明细
  389. order := order_model.GetOrderById(orderId, false)
  390. if order == nil {
  391. return
  392. }
  393. // 获取所有未写入赠品记录
  394. presents := promotion_model.GetAllNoPatchPresents(wxUid)
  395. for _, item := range presents {
  396. //赠送赠品
  397. product := product_model.GetProductById(item.SendProd, true)
  398. if product != nil {
  399. item.OrderId = orderId
  400. item.Status = true
  401. item.Save()
  402. order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, item.SendNums, order.Depart)
  403. }
  404. }
  405. beego.BeeLogger.Warn("******* End PresentTransferToOrder shopApplyId:%s wxUid:%d", orderId, wxUid)
  406. }
  407. //创建店铺申请订单
  408. func CreateShopApplyOrder(shopAppplyId int64) {
  409. beego.BeeLogger.Warn("begin do shopAppply id:(%d)", shopAppplyId)
  410. shopApply := user_model.GetShopApplicationById(shopAppplyId)
  411. if shopApply == nil {
  412. beego.BeeLogger.Warn("shopApply error id:(%d)", shopAppplyId)
  413. return
  414. }
  415. wxUser := user_model.GetWxUserById(shopApply.WxUId, false)
  416. if wxUser == nil {
  417. beego.BeeLogger.Warn("shopApply wxuser no existst id:(%d)", shopAppplyId)
  418. return
  419. }
  420. //创建赠品订单
  421. order := new(order_model.Order).CreateNew(wxUser.Id, wxUser.UserId,
  422. int64(0), int64(0), order_model.ORDER_TYPE_NORMAL, wxUser.Depart, order_model.SOURCE_XCX)
  423. if order == nil {
  424. return
  425. }
  426. total := int64(0)
  427. delOrder := true
  428. queryDate := time.Now()
  429. // 获取所有有效促销记录
  430. effectivePromotions := promotion_model.GetShopEffetivePromotions(queryDate, shopApply.Depart, false)
  431. for _, item := range effectivePromotions {
  432. //beego.Warn("item_name%d", item.Name)
  433. totalFlag := true
  434. numsFlag := true
  435. if item.Total > 0 && shopApply.Total != item.Total {
  436. totalFlag = false
  437. continue
  438. }
  439. count := int64(0)
  440. if item.Total > 0 {
  441. count = int64(1)
  442. }
  443. if count == int64(0) {
  444. numsFlag = false
  445. }
  446. beego.Warn("item_name-1%d", item.Name)
  447. beego.Warn("totalFlag%v", totalFlag)
  448. beego.Warn("numsFlag%v", numsFlag)
  449. beego.Warn("nums%d", count)
  450. //满足促销条件
  451. if totalFlag && numsFlag {
  452. orderId := fmt.Sprintf("shopapply-(%d)", shopApply.Id)
  453. order.Source = promotion_model.SOURCE_SHOP
  454. order.Remark = fmt.Sprintf("店长申请成功(%d)--促销(%s)", shopApply.Id, item.Name)
  455. if item.SendProd1 > 0 && item.SendNums1 > 0 {
  456. sendNums1 := count * item.SendNums1
  457. //生成赠品
  458. product := product_model.GetProductById(item.SendProd1, true)
  459. if product != nil {
  460. delOrder = false
  461. total += sendNums1 * product.Price
  462. go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, product.Name, "", "", sendNums1, order.Depart)
  463. }
  464. }
  465. if item.SendProd2 > 0 && item.SendNums2 > 0 {
  466. sendNums2 := count * item.SendNums2
  467. //赠送赠品1
  468. product := product_model.GetProductById(item.SendProd2, true)
  469. if product != nil {
  470. delOrder = false
  471. total += sendNums2 * product.Price
  472. go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, product.Name, "", "", sendNums2, order.Depart)
  473. }
  474. }
  475. if item.SendProd3 > 0 && item.SendNums3 > 0 {
  476. sendNums3 := count * item.SendNums3
  477. //赠送赠品3
  478. product := product_model.GetProductById(item.SendProd3, true)
  479. if product != nil {
  480. delOrder = false
  481. total += sendNums3 * product.Price
  482. go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, product.Name, "", "", sendNums3, order.Depart)
  483. }
  484. }
  485. if item.SendProd4 > 0 && item.SendNums4 > 0 {
  486. sendNums4 := count * item.SendNums4
  487. //赠送赠品4
  488. product := product_model.GetProductById(item.SendProd4, true)
  489. if product != nil {
  490. delOrder = false
  491. total += sendNums4 * product.Price
  492. go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, product.Name, "", "", sendNums4, order.Depart)
  493. }
  494. }
  495. if item.SendProd5 > 0 && item.SendNums5 > 0 {
  496. sendNums5 := count * item.SendNums5
  497. //赠送赠品5
  498. product := product_model.GetProductById(item.SendProd5, true)
  499. if product != nil {
  500. delOrder = false
  501. total += sendNums5 * product.Price
  502. go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, product.Name, "", "", sendNums5, order.Depart)
  503. }
  504. }
  505. //赠送积分 or 代办费
  506. if item.Cash > 0 {
  507. totalCash := count * item.Cash
  508. source := balance_model.BALANCE_SOURCE_SHOP_PROMOTION
  509. remark := fmt.Sprintf("店长申请促销赠送提货券")
  510. new(balance_model.Balance).Create(shopApply.WxUId, shopApply.UserId, totalCash, source, orderId, remark)
  511. }
  512. if item.Cent > 0 {
  513. totalCent := count * item.Cent
  514. source := cent_model.PROMOTION_SEND
  515. remark := fmt.Sprintf("店长申请促销活动赠送")
  516. new(cent_model.CentBalance).Create(shopApply.WxUId, totalCent, source, orderId, remark)
  517. }
  518. }
  519. }
  520. if !delOrder {
  521. order.Status = order_model.STATUS_PROCESSING
  522. order.TotalPrice = total
  523. order.Contact = shopApply.Name
  524. order.Address = shopApply.Address
  525. order.Tel = shopApply.Mobile
  526. order.Save()
  527. } else {
  528. order.Delete()
  529. }
  530. beego.BeeLogger.Warn("----------------end generate shopapply order ---%d ", shopApply.Id)
  531. return
  532. }