SiteDetail.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\admin;
  4. use Closure;
  5. use library\basic\BaseModel;
  6. use think\Model;
  7. /**
  8. * @mixin \think\Model
  9. */
  10. class SiteDetail extends BaseModel
  11. {
  12. /**
  13. * 获取列表数据
  14. * @param $page
  15. * @param $where
  16. * @param $pageCount
  17. * @param $desc
  18. */
  19. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
  20. $data = $this
  21. ->field("s.type,s.code,s.time,s.title,s.content,s.v,s.money,s.order_id")
  22. ->alias("s")
  23. ->when(!empty($where),function ($query) use($where){
  24. foreach ($where as $k=>$v) {
  25. if($v instanceof Closure) {
  26. $v($query);
  27. } else {
  28. if(is_array($v)) {
  29. //whereLike
  30. if($v[1] == 'whereLike') {
  31. if(!empty($v[0]))
  32. $query->whereLike($k,$v[0]);
  33. continue;
  34. }
  35. if($v[1] == 'whereBetween') {
  36. if(!empty($v[0])) $query->whereBetween($k,$v[0]);
  37. continue;
  38. }
  39. $bool = false;
  40. eval('$bool = '.$v[1].'($v[0]);');
  41. if($bool) {
  42. $query->where($k,$v[0]);
  43. }
  44. } else {
  45. $query->where($k,$v);
  46. }
  47. }
  48. }
  49. })
  50. ->order($desc)
  51. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  52. ->toArray();
  53. //echo $this->getLastSql();
  54. foreach ($data['data'] as $k=>$v) {
  55. $data['data'][$k]['all_price'] = (new Order)->where('order_id', $v['order_id'])->value("all_price");
  56. }
  57. return [$data['total'],$data['data']];
  58. }
  59. }