OrderModel.php 2.4 KB

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