Order.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Order extends Model
  5. {
  6. protected $table = 'orders';
  7. protected $guarded = [];
  8. public $pay_statuses;
  9. public function __construct(array $attributes = [])
  10. {
  11. parent::__construct($attributes);
  12. $this->pay_statuses = collect([
  13. collect(['key' => 1, 'value' => '未付款']),
  14. collect(['key' => 2, 'value' => '已付款']),
  15. collect(['key' => 3, 'value' => '已退款']),
  16. collect(['key' => 4, 'value' => '已取消']),
  17. collect(['key' => 5, 'value' => '回收站']),
  18. ]);
  19. }
  20. public function student()
  21. {
  22. return $this->belongsTo('App\Models\Student');
  23. }
  24. public function getPayStatuses()
  25. {
  26. return $this->pay_statuses;
  27. }
  28. public function getStudentName()
  29. {
  30. return empty($this['student']) ? '' : $this['student']['name'];
  31. }
  32. public function getPayPosition()
  33. {
  34. return '落地页' . $this['pay_position'] . '付款';
  35. }
  36. public function getPayStatusLabel()
  37. {
  38. switch($this['pay_status']) {
  39. case 1:
  40. return '<span class="label label-default">未付款</span>';
  41. case 2:
  42. return '<span class="label label-info">已付款</span>';
  43. case 3:
  44. return '<span class="label label-danger">已退款</span>';
  45. case 4:
  46. return '<span class="label label-warning">已取消</span>';
  47. case 5:
  48. return '<span class="label label-info">回收站</span>';
  49. default:
  50. return '<span class="label label-default">未付款</span>';
  51. }
  52. }
  53. public function getPayMethodLabel()
  54. {
  55. return '<span class="label label-primary">微信支付</span>';
  56. }
  57. public function getOutTradeNo()
  58. {
  59. return date('YmdHis') . rand(10, 99);
  60. }
  61. public function getPayMoney()
  62. {
  63. return round($this['money'] / 100, 2);
  64. }
  65. }