PreOrderCoupon.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2017/7/25
  6. * Time: 下午7:33
  7. */
  8. namespace app\frontend\models\order;
  9. use app\common\models\coupon\CouponUseLog;
  10. use app\frontend\modules\order\models\PreOrder;
  11. class PreOrderCoupon extends \app\common\models\order\OrderCoupon
  12. {
  13. public $order;
  14. protected $hidden = ['memberCoupon'];
  15. public $coupon;
  16. public function setOrder(PreOrder $order)
  17. {
  18. $this->order = $order;
  19. $this->uid = $order->uid;
  20. $order->orderCoupons->push($this);
  21. }
  22. public function afterSaving()
  23. {
  24. $this->push();
  25. }
  26. public function save(array $options = [])
  27. {
  28. $this->saveLog();
  29. if (isset($this->id)) {
  30. return true;
  31. }
  32. return parent::save($options);
  33. }
  34. public function saveLog()
  35. {
  36. if ($this->coupon_id && $this->member_coupon_id) {
  37. $log_data = [
  38. 'uniacid' => \YunShop::app()->uniacid,
  39. 'member_id' => \YunShop::app()->getMemberId(),
  40. 'detail' => '会员(ID为' . \YunShop::app()->getMemberId() . ')购物使用一张优惠券(ID为' . $this->coupon_id . ')',
  41. 'coupon_id' => $this->coupon_id,
  42. 'member_coupon_id' => $this->member_coupon_id,
  43. 'type' => CouponUseLog::TYPE_SHOPPING
  44. ];
  45. $model = new CouponUseLog();
  46. $model->fill($log_data);
  47. $model->save();
  48. }
  49. // $order = $this->order->toArray();
  50. // foreach ($order['order_coupons'] as $v)
  51. // {
  52. // $log_data = [
  53. // 'uniacid' => \YunShop::app()->uniacid,
  54. // 'member_id' => \YunShop::app()->getMemberId(),
  55. // 'detail' => '会员(ID为' . \YunShop::app()->getMemberId() . ')购物使用一张优惠券(ID为' . $v['coupon_id'] . ')',
  56. // 'coupon_id' => $v['coupon_id'],
  57. // 'member_coupon_id' => $v['member_coupon_id'],
  58. // 'type' => CouponUseLog::TYPE_SHOPPING
  59. // ];
  60. // $model = new CouponUseLog();
  61. // $model->fill($log_data);
  62. // $model->save();
  63. // }
  64. }
  65. }