PayOrder.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/20
  6. * Time: 上午10:42
  7. */
  8. namespace app\common\models;
  9. use app\backend\models\BackendModel;
  10. use Illuminate\Support\Collection;
  11. /**
  12. * Class PayOrder
  13. * @package app\common\models
  14. * @property string trade_no
  15. * @property int status
  16. * @property Collection all_status
  17. * @property string status_name
  18. * @property OrderPay orderPay
  19. * @property PayRefundOrder payRefundOrder
  20. */
  21. class PayOrder extends BackendModel
  22. {
  23. public $table = 'yz_pay_order';
  24. const STATUS_UNPAID = 0;
  25. const STATUS_WAIT_PAID = 1;
  26. const STATUS_PAID = 2;
  27. protected $appends = ['status_name'];
  28. /**
  29. * 可以被批量赋值的属性.
  30. *
  31. * @var array
  32. */
  33. protected $fillable = ['uniacid', 'member_id', 'int_order_no', 'out_order_no', 'status', 'type', 'third_type', 'pay_type_id', 'price'];
  34. public static function getPayOrderInfo($orderno)
  35. {
  36. return self::uniacid()
  37. ->where('out_order_no', $orderno)
  38. ->orderBy('id', 'desc');
  39. }
  40. public static function getPayOrderInfoByTradeNo($trade_no)
  41. {
  42. return self::uniacid()
  43. ->where('trade_no', $trade_no)
  44. ->orderBy('id', 'desc');
  45. }
  46. /**
  47. * @return \Illuminate\Support\Collection
  48. */
  49. public function getAllStatusAttribute(){
  50. return collect([
  51. self::STATUS_UNPAID => '未支付',
  52. self::STATUS_WAIT_PAID => '待支付',
  53. self::STATUS_PAID => '已支付',
  54. ]);
  55. }
  56. public function orderPay(){
  57. return $this->belongsTo(OrderPay::class,'out_order_no','pay_sn');
  58. }
  59. public function payRefundOrder(){
  60. return $this->hasOne(PayRefundOrder::class,'out_order_no','out_order_no');
  61. }
  62. public function isRefunded(){
  63. return isset($this->payRefundOrder) && $this->payRefundOrder->status == 2;
  64. }
  65. /**
  66. * @return mixed
  67. */
  68. public function getStatusNameAttribute()
  69. {
  70. if($this->isRefunded()){
  71. return '已退款';
  72. }
  73. return $this->all_status[$this->status];
  74. }
  75. }