OrderModel.php 2.5 KB

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