RefundChangePrice.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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:35
  9. */
  10. namespace app\backend\modules\refund\services\operation;
  11. use app\common\events\order\BeforeOrderRefundChangePriceEvent;
  12. use app\common\exceptions\AppException;
  13. use app\common\models\refund\RefundChangeLog;
  14. /**
  15. * 修改退款金额
  16. * Class RefundChangePrice
  17. * @package app\backend\modules\refund\services\operation
  18. */
  19. class RefundChangePrice extends RefundOperation
  20. {
  21. // protected $statusBeforeChange = [self::WAIT_CHECK];
  22. protected $name = '修改退款金额';
  23. protected $oldPrice;
  24. protected function updateAfter()
  25. {
  26. }
  27. protected function updateBefore()
  28. {
  29. //兼容旧数据
  30. if (empty($this->apply_price)) {
  31. $this->apply_price = max($this->price - $this->freight_price - $this->other_price,0);
  32. }
  33. $changePriceData = $this->getRequest()->only(['change_price', 'change_freight_price', 'change_other_price']);
  34. event(new BeforeOrderRefundChangePriceEvent($this,$changePriceData));
  35. //旧金额
  36. $this->oldPrice = $this->price;
  37. if (isset($changePriceData['change_freight_price'])) {
  38. $this->freight_price = max($changePriceData['change_freight_price'],0);
  39. }
  40. if (isset($changePriceData['change_other_price'])) {
  41. $this->other_price = max($changePriceData['change_other_price'],0);
  42. }
  43. if (isset($changePriceData['change_price'])) {
  44. $this->apply_price = $this->apply_price + $changePriceData['change_price'];
  45. }
  46. $new_price = max($this->apply_price + $this->freight_price + $this->other_price,0);
  47. if(bccomp($new_price, 0,2) != 1) {
  48. throw new AppException('退款金额必须大于0!');
  49. }
  50. $this->price = min($this->order->price, $new_price);
  51. }
  52. protected function writeLog()
  53. {
  54. $data = [
  55. 'old_price' => $this->oldPrice,
  56. 'new_price' => $this->price,
  57. 'change_price' => $this->getRequest()->input('change_price')?:0,
  58. 'change_freight_price' => $this->getRequest()->input('change_freight_price')?:0,
  59. 'change_other_price' => $this->getRequest()->input('change_other_price')?:0,
  60. 'username' => \Yunshop::app()->username?:'其他',
  61. 'refund_id' => $this->id,
  62. 'order_id' => $this->order_id,
  63. ];
  64. RefundChangeLog::create($data);
  65. }
  66. }