Order.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  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,p.title as pro_title,p.img as pro_img"
  21. .",(select count(*) from table_order_info where o_id = o.id " .
  22. (empty($where['shop_id']) ? '' : (' AND shop_id='.$where['shop_id']) )
  23. . ") as order_count"
  24. )
  25. ->alias("o")
  26. ->join('platform pf',"pf.id=o.platform_id")
  27. ->when(!empty($where),function ($query) use($where){
  28. //分站
  29. if(!empty($where['sassid'])) {
  30. $query->where('o.sassid',$where['sassid']);
  31. }
  32. //店铺信息
  33. if(!empty($where['shop_id'])) {
  34. $query->whereRaw("(SELECT count(*) from table_order_info where o_id = o.id AND shop_id =:shop_id) > 0",
  35. ['shop_id'=>$where['shop_id']]);
  36. }
  37. //用户
  38. if(!empty($where['uid'])) {
  39. $query->where('o.uid',$where['uid']);
  40. }
  41. //搜索订单
  42. if(!empty($where['order_id'])) {
  43. $query->whereLike('o.order_id',"%{$where['order_id']}%");
  44. }
  45. //搜索平台
  46. if(!empty($where['platform_id'])) {
  47. $query->whereLike('o.platform_id',$where['platform_id']);
  48. }
  49. //搜索备注信息
  50. if(!empty($where['mono'])) {
  51. $query->whereLike('o.order_id',"%{$where['mono']}%");
  52. }
  53. //查询日期
  54. if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
  55. $query->whereTime('o.time','between',$where['data']);
  56. }
  57. //订单类型
  58. if(is_numeric($where['orderType'])) {
  59. $query->where('o.status',$where['orderType']);
  60. }
  61. //timeType[今日,昨日,最近7天,最近30天]
  62. if(!empty($where['timeType'])) {
  63. if($where['timeType'] == 'day') {
  64. $query->whereDay('o.time');
  65. }
  66. if($where['timeType'] == 'yesterday') {
  67. $query->whereDay('o.time','yesterday');
  68. }
  69. if($where['timeType'] == 'last7') {
  70. $query->whereTime('o.time','-7 day');
  71. }
  72. if($where['timeType'] == 'last30') {
  73. $query->whereTime('o.time','-30 day');
  74. }
  75. }
  76. })
  77. ->leftJoin('product p',"p.id = o.pro_id")
  78. ->order($desc)
  79. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  80. ->toArray();
  81. //echo $this->getLastSql();
  82. return [$data['total'],$data['data']];
  83. }
  84. }