OrderGoodsCollection.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/11/26
  6. * Time: 3:52 PM
  7. */
  8. namespace app\common\modules\orderGoods;
  9. use app\common\modules\orderGoods\models\PreOrderGoods;
  10. use app\framework\Database\Eloquent\Collection;
  11. class OrderGoodsCollection extends Collection
  12. {
  13. public function setOrder($order){
  14. foreach ($this as $orderGoods){
  15. $orderGoods->setOrder($order);
  16. }
  17. }
  18. /**
  19. * 获取原价
  20. * @return int
  21. */
  22. public function getGoodsPrice()
  23. {
  24. return $this->sum(function (PreOrderGoods $orderGoods) {
  25. return $orderGoods->getGoodsPrice();
  26. });
  27. }
  28. /**
  29. * 获取成交价
  30. * @return int
  31. */
  32. public function getPrice()
  33. {
  34. return $this->sum(function (PreOrderGoods $orderGoods) {
  35. return $orderGoods->getPrice();
  36. });
  37. }
  38. /**
  39. * 获取会员价
  40. * @return int
  41. */
  42. public function getVipPrice()
  43. {
  44. return $this->sum(function (PreOrderGoods $orderGoods) {
  45. return $orderGoods->getVipPrice();
  46. });
  47. }
  48. /**
  49. * 获取支付价
  50. * @return int
  51. */
  52. public function getPaymentAmount()
  53. {
  54. return $this->sum(function (PreOrderGoods $orderGoods) {
  55. return $orderGoods->getPaymentAmount();
  56. });
  57. }
  58. /**
  59. * 获取折扣优惠券优惠金额
  60. * @return int
  61. */
  62. public function getCouponDiscountPrice()
  63. {
  64. return $this->sum(function ($orderGoods) {
  65. return $orderGoods->couponDiscountPrice;
  66. });
  67. }
  68. /**
  69. * 订单商品集合中包含虚拟物品
  70. * @return bool true 包含 false 不包含
  71. */
  72. public function hasVirtual(){
  73. $bool = $this->contains(function ($aOrderGoods) {
  74. // 包含虚拟商品
  75. //return $aOrderGoods->goods->type == 2;
  76. //todo 20190107 blank 修改 :包含实体商品按实体商品下单流程走
  77. return $aOrderGoods->goods->type == 1;
  78. });
  79. return !$bool;
  80. }
  81. /**
  82. * 订单商品集合中包含不需要地址的物品
  83. * @return bool true 不需要 false 需要
  84. */
  85. public function hasNeedAddress()
  86. {
  87. $bool = $this->contains(function ($aOrderGoods) {
  88. // 包含不需要地址的商品
  89. //return $aOrderGoods->goods->need_address == 1;
  90. //todo 20190107 blank 修改 :包含需要地址的商品按标准下单流程走
  91. return $aOrderGoods->goods->need_address != 1;
  92. });
  93. return !$bool;
  94. }
  95. }