Order.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\model\api;
  3. use library\basic\BaseModel;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class Order extends BaseModel
  9. {
  10. public function getUserOrderList($uid, $where){
  11. $list = $this->where('status', $where['type'])->where('uid', $uid)
  12. ->order('time DESC')->page((int)$where['page'], (int)$where['limit'])->select()->toArray();
  13. return $list;
  14. }
  15. /**
  16. * 获取列表数据
  17. * @param $page
  18. * @param $where
  19. * @param $pageCount
  20. * @param $desc
  21. */
  22. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
  23. $data = $this
  24. ->field("o.*,pf.name as platfrom_name,p.title as pro_title,p.img as pro_img"
  25. .",(select count(*) from table_order_info where o_id = o.id " .
  26. (empty($where['shop_id']) ? '' : (' AND shop_id='.$where['shop_id']) )
  27. . ") as order_count"
  28. )
  29. ->alias("o")
  30. ->join('platform pf',"pf.id=o.platform_id")
  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['shop_id'])) {
  38. $query->whereRaw("(SELECT count(*) from table_order_info where o_id = o.id AND shop_id =:shop_id) > 0",
  39. ['shop_id'=>$where['shop_id']]);
  40. }
  41. //用户
  42. if(!empty($where['uid'])) {
  43. $query->where('o.uid',$where['uid']);
  44. }
  45. //搜索订单
  46. if(!empty($where['order_id'])) {
  47. $query->whereLike('o.order_id',"%{$where['order_id']}%");
  48. }
  49. //搜索平台
  50. if(!empty($where['platform_id'])) {
  51. $query->whereLike('o.platform_id',$where['platform_id']);
  52. }
  53. //搜索备注信息
  54. if(!empty($where['mono'])) {
  55. $query->whereLike('o.order_id',"%{$where['mono']}%");
  56. }
  57. //查询日期
  58. if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
  59. $query->whereTime('o.time','between',$where['data']);
  60. }
  61. //订单类型
  62. if(is_numeric($where['orderType'])) {
  63. $query->where('o.status',$where['orderType']);
  64. }
  65. //timeType[今日,昨日,最近7天,最近30天]
  66. if(!empty($where['timeType'])) {
  67. if($where['timeType'] == 'day') {
  68. $query->whereDay('o.time');
  69. }
  70. if($where['timeType'] == 'yesterday') {
  71. $query->whereDay('o.time','yesterday');
  72. }
  73. if($where['timeType'] == 'last7') {
  74. $query->whereTime('o.time','-7 day');
  75. }
  76. if($where['timeType'] == 'last30') {
  77. $query->whereTime('o.time','-30 day');
  78. }
  79. }
  80. })
  81. ->leftJoin('product p',"p.id = o.pro_id")
  82. ->order($desc)
  83. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  84. ->toArray();
  85. //echo $this->getLastSql();
  86. return [$data['total'],$data['data']];
  87. }
  88. }