WlnPro.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 WlnPro extends BaseModel
  11. {
  12. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
  13. $data = $this
  14. ->field("w.*,
  15. (SELECT name from table_warehouse where id = w.warehouse_id) as warehouse_name,
  16. (SELECT title from table_express where id = w.express_id) as exp_name,
  17. (SELECT name from table_platform where id = w.platform_id) as platform_name,
  18. (SELECT title from table_product where id = w.pro_id) as product_name
  19. ")
  20. ->alias("w")
  21. ->when(!empty($where),function ($query) use($where){
  22. foreach ($where as $k=>$v) {
  23. if($v instanceof Closure) {
  24. $v($query);
  25. } else {
  26. if(is_array($v)) {
  27. //whereLike
  28. if($v[1] == 'whereLike') {
  29. if(!empty($v[0]))
  30. $query->whereLike($k,$v[0]);
  31. continue;
  32. }
  33. if($v[1] == 'whereBetween') {
  34. if(!empty($v[0])) $query->whereBetween($k,$v[0]);
  35. continue;
  36. }
  37. $bool = false;
  38. eval('$bool = '.$v[1].'($v[0]);');
  39. if($bool) {
  40. $query->where($k,$v[0]);
  41. }
  42. } else {
  43. $query->where($k,$v);
  44. }
  45. }
  46. }
  47. })
  48. ->order($desc)
  49. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  50. ->toArray();
  51. return [$data['total'],$data['data']];
  52. }
  53. }