CinemaOrder.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 悦活影院订单
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class CinemaOrder extends Model
  11. {
  12. /**
  13. *
  14. * The table associated with the model.
  15. *
  16. * @var string
  17. */
  18. protected $table = 'life_cinema_order';
  19. public $timestamps = false;
  20. /**
  21. * Notes:获取订单列表
  22. * @param string $keywords
  23. * @param int $page
  24. * @param int $limit
  25. * @return array
  26. * User: ZQ
  27. * Date: 2022/10/13
  28. */
  29. public static function getOrderList(int $page, int $limit,$keywords)
  30. {
  31. $list = static::select('*')
  32. ->with(['user'])
  33. ->with(['detail'])
  34. ->when($keywords != '', function ($query) use ($keywords){
  35. $query->where('order_sn', 'like', '%' . $keywords . '%');
  36. })
  37. ->orderBy('order_create_time','DESC')
  38. ->forPage($page, $limit)
  39. ->get();
  40. $count = static::when($keywords != '', function ($query) use ($keywords){
  41. $query->where('order_sn', 'like', '%' . $keywords . '%');
  42. })->count();
  43. return [$list, $count];
  44. }
  45. public function Attr(){
  46. return $this->hasMany(MedicalCareProductAttr::class,'attr_product_id','product_id')->where(['attr_is_delete'=>0]);
  47. }
  48. //关联店铺
  49. public function Shop(){
  50. return $this->belongsTo(MerchantShop::class,'order_shop_id','shop_id');
  51. }
  52. //获取用户信息
  53. public function User(){
  54. return $this->belongsTo(User::class,'order_user_id','user_id');
  55. }
  56. //获取订单详情
  57. public function Detail(){
  58. return $this->hasMany(CinemaOrderDetail::class,'detail_order_id','order_id')
  59. ->leftJoin('life_cinema','cinema_id','=','life_cinema_order_detail.detail_goods_id')
  60. ->select(['life_cinema_order_detail.*','life_cinema.cinema_name']);
  61. }
  62. }