Order.php 6.2 KB

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