TradeDiscount.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/11/23
  6. * Time: 5:11 PM
  7. */
  8. namespace app\common\modules\trade\models;
  9. use app\common\models\BaseModel;
  10. class TradeDiscount extends BaseModel
  11. {
  12. protected $attributes = [
  13. 'whether_show_coupon' => "1",
  14. 'coupon_show' => '0'
  15. ];
  16. /**
  17. * @var Trade
  18. */
  19. private $trade;
  20. public function init(Trade $trade)
  21. {
  22. $this->trade = $trade;
  23. $this->setRelation('memberCoupons', $this->getCoupons());
  24. $order_coupon = \Setting::get('coupon.order_coupon');
  25. //设置 order_coupon = 0:显示 1:关闭显示
  26. if (isset($order_coupon) && $order_coupon == 1) {
  27. $this->whether_show_coupon = "0";
  28. }
  29. $this->coupon_show = $this->couponShow();
  30. $this->deduction_lang = $this->deductionLang();
  31. $this->default_deduction = $this->defaultDeduction();//添加开启默认积分抵扣按钮
  32. return $this;
  33. }
  34. private function defaultDeduction()
  35. {
  36. return \Setting::get('point.set')['default_deduction'] ?: 0;
  37. }
  38. private function couponShow()
  39. {
  40. return \Setting::getByGroup('coupon')['coupon_show'];
  41. }
  42. private function deductionLang()
  43. {
  44. $langSetting = \Setting::get('shop.lang');
  45. return $langSetting[$langSetting['lang']]['order']['deduction_lang'] ?: "抵扣";
  46. }
  47. protected function getCoupons()
  48. {
  49. return $this->trade->orders->getMemberCoupons();
  50. }
  51. }