OrderInfoAsw.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 OrderInfoAsw 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 = 'mo.id desc')
  19. {
  20. $data = $this
  21. ->field(
  22. "mo.id,mo.msg_mono,mo.mono,mo.status,mo.time as cl_time,mo.admin_time as cl_admin_time,(select order_id from table_order where id = of.o_id) as order_id,"
  23. . "mo.o_id,of.name,of.out_order_id,of.mobile,of.address,of.time,of.send_time,(SELECT title from table_express where id = of.exp_id) as exp_name,of.exp_number"
  24. )
  25. ->alias("mo")
  26. ->join('order_info of', "mo.of_id=of.id")
  27. ->when(!empty($where), function ($query) use ($where) {
  28. if(!empty($where['name'])) {
  29. $query->whereLike('of.name',"%{$where['name']}%");
  30. }
  31. if(!empty($where['id'])) {
  32. $query->whereLike('mo.o_id',$where['id']);
  33. }
  34. if(!empty($where['sassid'])) {
  35. $query->whereLike('mo.sassid',$where['sassid']);
  36. }
  37. if(!empty($where['uid'])) {
  38. $query->whereLike('mo.uid',$where['uid']);
  39. }
  40. if(!empty($where['mobile'])) {
  41. $query->whereLike('of.mobile',"%{$where['mobile']}%");
  42. }
  43. if(!empty($where['out_order_id'])) {
  44. $query->whereLike('of.out_order_id',"%{$where['out_order_id']}%");
  45. }
  46. if( $where['orderType'] == 1 ) {
  47. $query->whereLike('mo.status',0);
  48. }
  49. if( $where['orderType'] == 2 ) {
  50. $query->whereLike('mo.status',1);
  51. }
  52. //timeType[今日,昨日,最近7天,最近30天]
  53. if(!empty($where['timeType'])) {
  54. if($where['timeType'] == 'day') {
  55. $query->whereDay('mo.time');
  56. }
  57. if($where['timeType'] == 'yesterday') {
  58. $query->whereDay('mo.time','yesterday');
  59. }
  60. if($where['timeType'] == 'last7') {
  61. $query->whereTime('mo.time','-7 day');
  62. }
  63. if($where['timeType'] == 'last30') {
  64. $query->whereTime('mo.time','-30 day');
  65. }
  66. }
  67. })
  68. ->order($desc)
  69. ->paginate(['list_rows' => $pageCount, 'page' => $page])
  70. ->toArray();
  71. return [$data['total'], $data['data']];
  72. }
  73. }