OrderInfo.php 3.7 KB

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