OrderModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 订单管理-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class OrderModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'orders';
  22. // 发票
  23. public function getTicketImgAttribute($value)
  24. {
  25. $value = $value ? get_image_url($value) : '';
  26. return $value;
  27. }
  28. public function setTicketImgAttribute($value)
  29. {
  30. return $value ? get_image_path($value) : '';
  31. }
  32. /**
  33. * 下单用户
  34. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  35. */
  36. public function user()
  37. {
  38. return $this->hasOne(MemberModel::class, 'id', 'user_id')
  39. ->select(['id','openid', 'mobile', 'nickname','balance', 'realname', 'status']);
  40. }
  41. /**
  42. * 订单商品关联
  43. * 通过 order_no 字段关联订单商品表
  44. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  45. */
  46. public function orderGoods()
  47. {
  48. return $this->hasMany(OrderGoodsModel::class, 'order_no', 'order_no')
  49. ->with(['category'])
  50. ->leftJoin('goods_skus as b','b.id','=','orders_goods.sku_id')
  51. ->where('orders_goods.mark', 1)->select(['orders_goods.*','b.sku_name']);
  52. }
  53. /**
  54. * 店铺
  55. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  56. */
  57. public function store()
  58. {
  59. return $this->hasOne(StoreModel::class, 'id', 'store_id')
  60. ->select(['id', 'nickname as name', 'avatar as logo']);
  61. }
  62. /**
  63. * 关联会议
  64. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  65. */
  66. public function meeting()
  67. {
  68. return $this->hasOne(MeetingModel::class, 'id', 'meeting_id')
  69. ->select(['id', 'title', 'thumb','company','bonus_rate']);
  70. }
  71. /**
  72. * 经手人
  73. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  74. */
  75. public function adminUser()
  76. {
  77. return $this->hasOne(UserModel::class, 'id', 'confirm_admin_id')
  78. ->select(['id', 'nickname', 'mobile', 'realname', 'status']);
  79. }
  80. /**
  81. * 已审核
  82. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  83. */
  84. public function confirm()
  85. {
  86. return $this->hasOne(OrderModel::class, 'goods_id', 'goods_id')
  87. ->with(['user'])
  88. ->whereIn('status', [2, 3])
  89. ->where(['mark' => 1])
  90. ->select(['id', 'order_no', 'goods_id', 'confirm_at', 'status']);
  91. }
  92. }