SiteTotal.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\system;
  4. use Closure;
  5. use library\basic\BaseModel;
  6. use think\Model;
  7. /**
  8. * @mixin \think\Model
  9. */
  10. class SiteTotal extends BaseModel
  11. {
  12. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
  13. $data = $this
  14. ->field("st.*,s.name")
  15. ->alias("st")
  16. ->join("site s","s.sassid = st.sassid")
  17. ->when(!empty($where),function ($query) use($where){
  18. foreach ($where as $k=>$v) {
  19. if($v instanceof Closure) {
  20. $v($query);
  21. } else {
  22. if(is_array($v)) {
  23. //whereLike
  24. if($v[1] == 'whereLike') {
  25. if(!empty($v[0]))
  26. $query->whereLike($k,$v[0]);
  27. continue;
  28. }
  29. if($v[1] == 'whereBetween') {
  30. if(!empty($v[0])) $query->whereBetween($k,$v[0]);
  31. continue;
  32. }
  33. $bool = false;
  34. eval('$bool = '.$v[1].'($v[0]);');
  35. if($bool) {
  36. $query->where($k,$v[0]);
  37. }
  38. } else {
  39. $query->where($k,$v);
  40. }
  41. }
  42. }
  43. })
  44. ->order($desc)
  45. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  46. ->toArray();
  47. // echo $this->getLastSql();
  48. return [$data['total'],$data['data']];
  49. }
  50. }