ApplyRefund.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/8/2
  6. * Time: 下午5:51
  7. */
  8. namespace app\frontend\modules\order\operations\member;
  9. use app\backend\modules\goods\models\GoodsTradeSet;
  10. use app\frontend\models\OrderGoods;
  11. use app\frontend\modules\order\operations\OrderOperation;
  12. use Illuminate\Support\Carbon;
  13. class ApplyRefund extends OrderOperation
  14. {
  15. public function getApi()
  16. {
  17. return 'refund.apply.store';
  18. }
  19. public function getValue()
  20. {
  21. return static::REFUND;
  22. }
  23. public function getName()
  24. {
  25. return '申请售后';
  26. }
  27. public function enable()
  28. {
  29. //商城关闭退款按钮
  30. if (!\Setting::get('shop.trade.refund_status')) {
  31. return false;
  32. }
  33. //商品开启不可退款
  34. if ($this->order->no_refund) {
  35. return false;
  36. }
  37. $can_refund = $this->order->canRefund();
  38. $order_goods = OrderGoods::where('order_id', $this->order->id)->get();
  39. if ($can_refund && $order_goods->count() == 1) {
  40. $goods_trade = GoodsTradeSet::where('goods_id', $order_goods[0]->goods_id)->first();
  41. if ($goods_trade && $goods_trade->hide_status) {
  42. $begin_hide_day = $goods_trade->begin_hide_day;
  43. if ($begin_hide_day > 1) {
  44. $begin_hide_day -= 1;
  45. $begin_time = $this->order->pay_time->addDays($begin_hide_day)->format('Y-m-d');
  46. } else {
  47. $begin_time = $this->order->pay_time->format('Y-m-d');
  48. }
  49. $begin_time .= " {$goods_trade->begin_hide_time}:00";
  50. $begin_timestamp = strtotime($begin_time);
  51. $end_hide_day = $goods_trade->end_hide_day;
  52. if ($end_hide_day) {
  53. $end_time = Carbon::createFromTimestamp($begin_timestamp)->addDays(1)->format('Y-m-d');
  54. } else {
  55. $end_time = Carbon::createFromTimestamp($begin_timestamp)->format('Y-m-d');
  56. }
  57. $end_time .= " {$goods_trade->end_hide_time}:00";
  58. $end_timestamp = strtotime($end_time);
  59. if ($begin_timestamp < time() && $end_timestamp > time()) {
  60. return false;
  61. }
  62. }
  63. }
  64. return $can_refund;
  65. }
  66. }