OrderModel.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. ->with(['category','sku'])
  40. ->where('mark', 1);
  41. }
  42. /**
  43. * 店铺
  44. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  45. */
  46. public function store()
  47. {
  48. return $this->hasOne(StoreModel::class, 'id', 'store_id')
  49. ->select(['id', 'name', 'logo']);
  50. }
  51. /**
  52. * 经手人
  53. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  54. */
  55. public function adminUser()
  56. {
  57. return $this->hasOne(UserModel::class, 'id', 'confirm_admin_id')
  58. ->select(['id', 'nickname', 'mobile', 'realname', 'status']);
  59. }
  60. /**
  61. * 已审核
  62. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  63. */
  64. public function confirm()
  65. {
  66. return $this->hasOne(OrderModel::class, 'goods_id', 'goods_id')
  67. ->with(['user'])
  68. ->whereIn('status', [2, 3])
  69. ->where(['mark' => 1])
  70. ->select(['id', 'order_no', 'goods_id', 'confirm_at', 'status']);
  71. }
  72. }