promotion_helper.go 20 KB

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