OrderInfo.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\admin;
  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. ->alias("of")
  43. ->when(!empty($where),function ($query) use($where){
  44. if(!empty($where['sassid'])) {
  45. $query->where('of.sassid',$where['sassid']);
  46. }
  47. if(!empty($where['id'])) {
  48. $query->where('of.o_id',$where['id']);
  49. }
  50. if(!empty($where['uid'])) {
  51. $query->where('of.uid',$where['uid']);
  52. }
  53. if(!empty($where['name'])) {
  54. $query->whereLike('of.name',"%{$where['name']}%");
  55. }
  56. if(!empty($where['mobile'])) {
  57. $query->whereLike('of.mobile',"%{$where['mobile']}%");
  58. }
  59. if(!empty($where['order_id'])) {
  60. $query->whereLike('of.out_order_id',"%{$where['order_id']}%");
  61. }
  62. })
  63. ->order($desc)
  64. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  65. ->toArray();
  66. //echo $this->getLastSql();
  67. return [$data['total'],$data['data']];
  68. }
  69. /**
  70. * 导出某一项全部
  71. * @param array $where
  72. * @param string $desc
  73. */
  74. public function getAllList($where = [],$desc = 'id desc'){
  75. $data = $this
  76. ->field("of.*,(SELECT title from table_express where id = of.exp_id) as exp_name,".
  77. "(select order_id from table_order where id = of.o_id) as order_id,".
  78. "(select name from table_platform where id = of.platform_id) as platform_name,".
  79. "p.title as pro_name,p.csno"
  80. )
  81. ->alias("of")
  82. ->when(!empty($where),function ($query) use($where){
  83. if(!empty($where['sassid'])) {
  84. $query->where('of.sassid',$where['sassid']);
  85. }
  86. if(!empty($where['id'])) {
  87. $query->whereIn('of.o_id',$where['id']);
  88. }
  89. })
  90. ->leftJoin('product p','p.id=of.pro_id')
  91. ->order($desc)
  92. ->select()
  93. ->toArray();
  94. return $data;
  95. }
  96. }