OrderInfo.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 OrderInfo extends BaseModel
  10. {
  11. /**
  12. * 订单查询
  13. * @param $id
  14. * @return array|Model|null
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function getItem($id) {
  20. $data = $this
  21. ->field("of.*,(SELECT title from table_express where id = of.exp_id) as exp_name,".
  22. "(select order_id from table_order where id = of.o_id) as order_id,".
  23. "p.title as pro_title,p.img as pro_img"
  24. )
  25. ->alias("of")
  26. ->join('product p',"p.id = of.pro_id")
  27. ->where('of.id',$id)
  28. ->find();
  29. return $data;
  30. }
  31. /**
  32. * 获取列表数据
  33. * @param $page
  34. * @param $where
  35. * @param $pageCount
  36. * @param $desc
  37. */
  38. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
  39. $data = $this
  40. ->field("of.*,(SELECT title from table_express where id = of.exp_id) as exp_name,".
  41. "(select order_id from table_order where id = of.o_id) as order_id,".
  42. "(select store_name from table_product where id = of.pro_id) as pro_title")
  43. ->alias("of")
  44. ->when(!empty($where),function ($query) use($where){
  45. if(!empty($where['sassid'])) {
  46. $query->where('of.sassid',$where['sassid']);
  47. }
  48. if(!empty($where['id'])) {
  49. $query->where('of.o_id',$where['id']);
  50. }
  51. if(!empty($where['uid'])) {
  52. $query->where('of.uid',$where['uid']);
  53. }
  54. if(!empty($where['name'])) {
  55. $query->whereLike('of.name',"%{$where['name']}%");
  56. }
  57. if(!empty($where['mobile'])) {
  58. $query->whereLike('of.mobile',"%{$where['mobile']}%");
  59. }
  60. if(!empty($where['order_id'])) {
  61. $query->whereLike('of.out_order_id',"%{$where['order_id']}%");
  62. }
  63. })
  64. ->order($desc)
  65. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  66. ->toArray();
  67. //echo $this->getLastSql();
  68. return [$data['total'],$data['data']];
  69. }
  70. /**
  71. * 导出某一项全部
  72. * @param array $where
  73. * @param string $desc
  74. */
  75. public function getAllList($where = [],$desc = 'id desc'){
  76. $data = $this
  77. ->field("of.*,(SELECT title from table_express where id = of.exp_id) as exp_name,".
  78. "(select order_id from table_order where id = of.o_id) as order_id,".
  79. "(select name from table_platform where id = of.platform_id) as platform_name,".
  80. "p.title as pro_name,p.csno"
  81. )
  82. ->alias("of")
  83. ->when(!empty($where),function ($query) use($where){
  84. if(!empty($where['sassid'])) {
  85. $query->where('of.sassid',$where['sassid']);
  86. }
  87. if(!empty($where['id'])) {
  88. $query->whereIn('of.o_id',$where['id']);
  89. }
  90. })
  91. ->leftJoin('product p','p.id=of.pro_id')
  92. ->order($desc)
  93. ->select()
  94. ->toArray();
  95. return $data;
  96. }
  97. /**
  98. * 未揽件订单
  99. * @param array $where
  100. * @param string $desc
  101. */
  102. public function getWarningList($where = [],$page,$pageCount,$desc = 'id desc'){
  103. $data = $this
  104. ->field("of.*,(SELECT title from table_express where id = of.exp_id) as exp_name,".
  105. "o.order_id,o.pay_time,w.name as warehouse_name,".
  106. "(select name from table_platform where id = of.platform_id) as platform_name,".
  107. "u.mobile as user_mobile,u.avatar as user_avatar"
  108. )
  109. ->alias("of")
  110. ->when(!empty($where),function ($query) use($where){
  111. if(!empty($where['order_id'])) {
  112. $query->whereLike('o.order_id', $where['order_id']);
  113. }
  114. if(!empty($where['exp_number'])) {
  115. $query->whereLike('of.exp_number', $where['exp_number']);
  116. }
  117. if(!empty($where['warehouse_id'])) {
  118. $query->where('of.warehouse_id',$where['warehouse_id']);
  119. }
  120. //查询日期
  121. if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
  122. $query->whereTime('of.time','between',$where['data']);
  123. }
  124. if($where['orderType'] == 1) {
  125. $query->whereDay('of.send_time','yesterday');
  126. }
  127. if($where['orderType'] == 2) {
  128. $time = strtotime(date('Y-m-d', strtotime('-2 day')));
  129. $query->whereDay('of.send_time',date('Y-m-d',$time));
  130. }
  131. if($where['orderType'] == 3) {
  132. $time = strtotime(date('Y-m-d', strtotime('-2 day')));
  133. $query->where('of.send_time','<=',$time);
  134. }
  135. })
  136. ->where('of.status', 2)
  137. ->where('of.exp_status',0)
  138. ->where('of.send_time', '>', strtotime(date('Y-m-d', strtotime('-3 day'))))
  139. ->where('of.send_time', '<', strtotime(date('Y-m-d')))
  140. ->where('of.warehouse_id','>',16)
  141. ->leftJoin('order o','o.id = of.o_id')
  142. ->leftJoin('warehouse w','w.id = of.warehouse_id')
  143. ->leftJoin('member u','u.uid=of.uid')
  144. ->order("of.send_time desc")
  145. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  146. ->toArray();
  147. return [$data['total'],$data['data']];
  148. }
  149. }