Pay.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\admin\model\shopro;
  3. use app\admin\model\shopro\Common;
  4. class Pay extends Common
  5. {
  6. protected $name = 'shopro_pay';
  7. // 追加属性
  8. protected $append = [
  9. 'pay_type_text',
  10. 'status_text'
  11. ];
  12. const PAY_STATUS_UNPAID = 'unpaid';
  13. const PAY_STATUS_PAID = 'paid';
  14. const PAY_STATUS_REFUND = 'refund';
  15. public function statusList()
  16. {
  17. return [
  18. self::PAY_STATUS_UNPAID => '未支付',
  19. self::PAY_STATUS_PAID => '已支付',
  20. self::PAY_STATUS_REFUND => '已退款'
  21. ];
  22. }
  23. public function payTypeList()
  24. {
  25. return [
  26. 'wechat' => '微信支付',
  27. 'alipay' => '支付宝',
  28. 'money' => '钱包支付',
  29. 'score' => '积分支付',
  30. 'offline' => '货到付款',
  31. ];
  32. }
  33. public function scopeTypeOrder($query) // scopeOrder 调用时候,和 order 排序方法冲突了
  34. {
  35. return $query->where('order_type', 'order');
  36. }
  37. public function scopeTypeTradeOrder($query)
  38. {
  39. return $query->where('order_type', 'trade_order');
  40. }
  41. public function scopePaid($query)
  42. {
  43. return $query->where('status', self::PAY_STATUS_PAID);
  44. }
  45. public function scopeIsMoney($query)
  46. {
  47. return $query->whereIn('pay_type', ['wechat', 'alipay', 'money']);
  48. }
  49. /**
  50. * 通用类型获取器
  51. *
  52. * @param string $value
  53. * @param array $data
  54. * @return string
  55. */
  56. public function getPayTypeTextAttr($value, $data)
  57. {
  58. $value = $value ?: ($data['pay_type'] ?? null);
  59. $list = $this->payTypeList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. }