RefundComplete.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/12/22
  8. * Time: 15:16
  9. */
  10. namespace app\backend\modules\refund\services\operation;
  11. use app\backend\modules\refund\services\RefundMessageService;
  12. use app\common\events\order\AfterOrderRefundedEvent;
  13. use app\common\events\order\AfterOrderRefundSuccessEvent;
  14. use app\common\models\refund\RefundProcessLog;
  15. /**
  16. * 确认退款
  17. * Class RefundComplete
  18. * @package app\backend\modules\refund\services\operation
  19. */
  20. class RefundComplete extends RefundOperation
  21. {
  22. protected $statusBeforeChange = [
  23. self::WAIT_CHECK,
  24. self::WAIT_RETURN_GOODS,
  25. self::WAIT_RECEIVE_RETURN_GOODS,
  26. self::WAIT_RESEND_GOODS,
  27. self::WAIT_RECEIVE_RESEND_GOODS,
  28. self::WAIT_REFUND,
  29. ];
  30. protected $statusAfterChanged = self::COMPLETE;
  31. protected $name = '退款完成';
  32. protected $timeField = 'refund_time';
  33. protected function afterEventClass()
  34. {
  35. //event(new AfterOrderRefundedEvent($this->order));
  36. return new AfterOrderRefundSuccessEvent($this);
  37. }
  38. protected function updateBefore()
  39. {
  40. $this->price = $this->getRequest()->input('refund_custom_money')?:$this->price;
  41. }
  42. protected function updateAfter()
  43. {
  44. $this->updateOrderGoodsRefundStatus();
  45. }
  46. //必须要触发完退款事件,才订单关闭
  47. protected function triggerEventAfter()
  48. {
  49. //更新订单支付记录状态
  50. if ($this->order->hasOneOrderPay) {
  51. $this->order->hasOneOrderPay->refund();
  52. }
  53. if ($this->isPartRefund()) {
  54. $this->cancelRefund();
  55. } else {
  56. $this->closeOrder();
  57. }
  58. }
  59. protected function writeLog()
  60. {
  61. $detail = [
  62. $this->getRefundTypeName()[$this->refund_type].'完成',
  63. $this->refund_type == self::REFUND_TYPE_REFUND_MONEY ? '商家确认退款':'商家确认收货',
  64. ];
  65. $processLog = RefundProcessLog::logInstance($this, RefundProcessLog::OPERATOR_SHOP);
  66. $processLog->setAttribute('operate_type', RefundProcessLog::OPERATE_REFUND_COMPLETE);
  67. $processLog->saveLog($detail);
  68. }
  69. protected function sendMessage()
  70. {
  71. RefundMessageService::passMessage($this);//通知买家
  72. if (app('plugins')->isEnabled('instation-message')) {
  73. event(new \Yunshop\InstationMessage\event\OrderRefundSuccessEvent($this));
  74. }
  75. }
  76. }