BaseCoinExchange.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/5/23
  6. * Time: 下午3:55
  7. */
  8. namespace app\frontend\modules\orderGoods\coin_exchange;
  9. use app\frontend\models\orderGoods\PreOrderGoodsDiscount;
  10. use app\frontend\modules\order\models\PreOrder;
  11. use app\frontend\models\order\PreOrderCoinExchange;
  12. use app\frontend\models\orderGoods\PreOrderGoodsCoinExchange;
  13. use app\frontend\modules\orderGoods\price\option\BaseOrderGoodsPrice;
  14. abstract class BaseCoinExchange
  15. {
  16. /**
  17. * @var BaseOrderGoodsPrice
  18. */
  19. protected $orderGoodsPrice;
  20. protected $shopSet;
  21. public function __construct(BaseOrderGoodsPrice $orderGoodsPrice)
  22. {
  23. $this->orderGoodsPrice = $orderGoodsPrice;
  24. //获取商城设置: 判断 积分、余额 是否有自定义名称
  25. $this->shopSet = \Setting::get('shop.shop');
  26. }
  27. public function setLog()
  28. {
  29. // 优惠记录
  30. $preOrderGoodsDiscount = new PreOrderGoodsDiscount([
  31. 'discount_code' => 'coinExchange',
  32. 'amount' => $this->orderGoodsPrice->getGoodsPrice() ?: 0,
  33. 'name' => $this->shopSet['credit1'] ? $this->shopSet['credit1'] . '全额抵扣' : '积分全额抵扣',
  34. ]);
  35. $preOrderGoodsDiscount->setOrderGoods($this->orderGoodsPrice->orderGoods);
  36. // 全额抵扣记录
  37. $orderGoodsCoinExchange = new PreOrderGoodsCoinExchange([
  38. 'code' => 'point',
  39. 'amount' => $this->orderGoodsPrice->getGoodsPrice() ?: 0,
  40. 'coin' => $this->orderGoodsPrice->orderGoods->goods->hasOneSale->all_point_deduct * $this->orderGoodsPrice->orderGoods->total,
  41. 'name' => $this->shopSet['credit1'] ? $this->shopSet['credit1'] . '全额抵扣' : '积分全额抵扣',
  42. ]);
  43. $orderGoodsCoinExchange->setOrderGoods($this->orderGoodsPrice->orderGoods);
  44. $orderCoinExchange = new PreOrderCoinExchange([
  45. 'code' => 'point',
  46. 'amount' => $this->orderGoodsPrice->getGoodsPrice() ?: 0,
  47. 'coin' => $this->orderGoodsPrice->orderGoods->goods->hasOneSale->all_point_deduct * $this->orderGoodsPrice->orderGoods->total,
  48. 'name' => $this->shopSet['credit1'] ? $this->shopSet['credit1'] . '全额' : '积分全额',
  49. 'uid' => $this->orderGoodsPrice->orderGoods->uid,
  50. ]);
  51. return $orderCoinExchange;
  52. }
  53. public function validate()
  54. {
  55. return true;
  56. }
  57. }