OrderModel.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * 下单用户
  24. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  25. */
  26. public function user()
  27. {
  28. return $this->hasOne(MemberModel::class, 'id', 'user_id')
  29. ->select(['id', 'mobile', 'nickname', 'realname', 'status']);
  30. }
  31. /**
  32. * 订单商品关联
  33. * 通过 order_no 字段关联订单商品表
  34. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  35. */
  36. public function orderGoods()
  37. {
  38. return $this->hasMany(OrderGoodsModel::class, 'order_no', 'order_no')
  39. ->where('mark', 1);
  40. }
  41. /**
  42. * 店铺
  43. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  44. */
  45. public function store()
  46. {
  47. return $this->hasOne(StoreModel::class, 'id', 'store_id')
  48. ->select(['id', 'name']);
  49. }
  50. /**
  51. * 经手人
  52. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  53. */
  54. public function adminUser()
  55. {
  56. return $this->hasOne(UserModel::class, 'id', 'confirm_admin_id')
  57. ->select(['id', 'nickname', 'mobile', 'realname', 'status']);
  58. }
  59. /**
  60. * 已审核
  61. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  62. */
  63. public function confirm()
  64. {
  65. return $this->hasOne(OrderModel::class, 'goods_id', 'goods_id')
  66. ->with(['user'])
  67. ->whereIn('status', [2, 3])
  68. ->where(['mark' => 1])
  69. ->select(['id', 'order_no', 'goods_id', 'confirm_at', 'status']);
  70. }
  71. /**
  72. * 订单商品
  73. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  74. */
  75. public function goods()
  76. {
  77. return $this->hasOne(GoodsModel::class, 'id', 'goods_id')->with(['shipperCity', 'shipperDistrict', 'receiverCity', 'receiverDistrict']);
  78. }
  79. }