Order.php 6.3 KB

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