Order.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\system;
  4. use library\basic\BaseModel;
  5. use think\Model;
  6. /**
  7. * @mixin \think\Model
  8. */
  9. class Order extends BaseModel
  10. {
  11. /**
  12. * 获取列表数据
  13. * @param $page
  14. * @param $where
  15. * @param $pageCount
  16. * @param $desc
  17. */
  18. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
  19. $data = $this
  20. ->field(
  21. "o.*,p.store_name as pro_title,p.image as pro_img,m.mobile,m.avatar,
  22. (select count(*) from table_order_info where o_id = o.id) as order_count,
  23. (select count(*) from table_order_info where o_id = o.id and status = 2) as send_count,
  24. (SELECT title from table_express where id = o.express_id) as exp_name,
  25. (SELECT name from table_warehouse where id = o.warehouse_id) as ck_name"
  26. )
  27. ->alias("o")
  28. //->join('platform pf',"pf.id=o.platform_id")
  29. ->join('member m','m.uid=o.uid')
  30. ->leftJoin('product p',"p.id = o.pro_id")
  31. ->when(!empty($where),function ($query) use($where){
  32. //用户
  33. if(!empty($where['uid'])) {
  34. $query->where('o.uid',$where['uid']);
  35. }
  36. //搜索订单
  37. if(!empty($where['order_id'])) {
  38. $query->whereLike('o.order_id',"%{$where['order_id']}%");
  39. }
  40. //搜索平台
  41. if(!empty($where['platform_id'])) {
  42. $query->whereLike('o.platform_id',$where['platform_id']);
  43. }
  44. //仓库
  45. if(!empty($where['warehouse_id'])) {
  46. $query->whereLike('o.warehouse_id',$where['warehouse_id']);
  47. }
  48. //搜索备注信息
  49. if(!empty($where['mono'])) {
  50. $query->whereLike('o.order_id',"%{$where['mono']}%");
  51. }
  52. //查询日期
  53. if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
  54. $query->whereTime('o.time','between',$where['data']);
  55. }
  56. //订单类型
  57. if(is_numeric($where['orderType'])) {
  58. $query->where('o.status',$where['orderType']);
  59. } else {
  60. $query->where('o.status','>',0);
  61. }
  62. //timeType[今日,昨日,最近7天,最近30天]
  63. if(!empty($where['timeType'])) {
  64. if($where['timeType'] == 'day') {
  65. $query->whereDay('o.time');
  66. }
  67. if($where['timeType'] == 'yesterday') {
  68. $query->whereDay('o.time','yesterday');
  69. }
  70. if($where['timeType'] == 'last7') {
  71. $query->whereTime('o.time','-7 day');
  72. }
  73. if($where['timeType'] == 'last30') {
  74. $query->whereTime('o.time','-30 day');
  75. }
  76. }
  77. })
  78. ->order($desc)
  79. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  80. ->toArray();
  81. //echo $this->getLastSql();exit;
  82. return [$data['total'],$data['data']];
  83. }
  84. /**
  85. * 获取推送数据
  86. * @param $page
  87. * @param array $where
  88. * @param int $pageCount
  89. * @param string $filed
  90. * @param string $desc
  91. * @return array
  92. */
  93. public function getPushList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
  94. $data = $this
  95. ->field(
  96. "o.*,p.store_name as pro_title,p.image as pro_img,m.mobile,m.avatar,
  97. (select count(*) from table_order_info where o_id = o.id) as order_count,
  98. (select count(*) from table_order_info where o_id = o.id and is_push = 1) as push_count,
  99. (SELECT title from table_express where id = o.express_id) as exp_name,
  100. (SELECT name from table_warehouse where id = o.warehouse_id) as ck_name"
  101. )
  102. ->alias("o")
  103. //->join('platform pf',"pf.id=o.platform_id")
  104. ->join('member m','m.uid=o.uid')
  105. ->leftJoin('product p',"p.id = o.pro_id")
  106. ->when(!empty($where),function ($query) use($where){
  107. //用户
  108. if(!empty($where['uid'])) {
  109. $query->where('o.uid',$where['uid']);
  110. }
  111. //搜索订单
  112. if(!empty($where['order_id'])) {
  113. $query->whereLike('o.order_id',"%{$where['order_id']}%");
  114. }
  115. //搜索平台
  116. if(!empty($where['platform_id'])) {
  117. $query->whereLike('o.platform_id',$where['platform_id']);
  118. }
  119. //仓库
  120. if(!empty($where['warehouse_id'])) {
  121. $query->whereLike('o.warehouse_id',$where['warehouse_id']);
  122. }
  123. //查询日期
  124. if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
  125. $query->whereTime('o.time','between',$where['data']);
  126. }
  127. //订单类型
  128. if(is_numeric($where['orderType'])) {
  129. $query->where('o.status',$where['orderType']);
  130. } else {
  131. $query->where('o.status','>',0);
  132. }
  133. })
  134. ->order($desc)
  135. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  136. ->toArray();
  137. //echo $this->getLastSql();exit;
  138. return [$data['total'],$data['data']];
  139. }
  140. }