正在显示
1 个修改的文件
包含
11 行增加
和
6 行删除
| @@ -24,7 +24,8 @@ class Base extends Model | @@ -24,7 +24,8 @@ class Base extends Model | ||
| 24 | */ | 24 | */ |
| 25 | public function lists($map, $p, $row, $order = 'id', $fields = ['*']){ | 25 | public function lists($map, $p, $row, $order = 'id', $fields = ['*']){ |
| 26 | //TODO::where(['id'=>'','name'=>'']) | 26 | //TODO::where(['id'=>'','name'=>'']) |
| 27 | - $lists = $this->select($fields)->where($map)->orderBy($order)->paginate($row, ['*'], 'page', $p); | 27 | + $query = $this->formatQuery($map); |
| 28 | + $lists = $query->select($fields)->orderBy($order)->paginate($row, ['*'], 'page', $p); | ||
| 28 | if (empty($lists)) { | 29 | if (empty($lists)) { |
| 29 | return false; | 30 | return false; |
| 30 | } | 31 | } |
| @@ -43,7 +44,8 @@ class Base extends Model | @@ -43,7 +44,8 @@ class Base extends Model | ||
| 43 | * @method | 44 | * @method |
| 44 | */ | 45 | */ |
| 45 | public function list($map,$order = 'id',$fields = ['*']){ | 46 | public function list($map,$order = 'id',$fields = ['*']){ |
| 46 | - $lists = $this->select($fields)->where($map)->orderBy($order)->get(); | 47 | + $query = $this->formatQuery($map); |
| 48 | + $lists = $query->select($fields)->orderBy($order)->get(); | ||
| 47 | if (empty($lists)) { | 49 | if (empty($lists)) { |
| 48 | return false; | 50 | return false; |
| 49 | } | 51 | } |
| @@ -88,8 +90,10 @@ class Base extends Model | @@ -88,8 +90,10 @@ class Base extends Model | ||
| 88 | * @method post | 90 | * @method post |
| 89 | */ | 91 | */ |
| 90 | public function edit($data,$condition){ | 92 | public function edit($data,$condition){ |
| 93 | + $query = $this->formatQuery($condition); | ||
| 91 | $data['updated_at'] = date('Y-m-d H:i:s'); | 94 | $data['updated_at'] = date('Y-m-d H:i:s'); |
| 92 | - return $this->where($condition)->update($data); | 95 | + $rs = $query->update($data); |
| 96 | + return $rs; | ||
| 93 | } | 97 | } |
| 94 | 98 | ||
| 95 | /** | 99 | /** |
| @@ -99,19 +103,20 @@ class Base extends Model | @@ -99,19 +103,20 @@ class Base extends Model | ||
| 99 | * @method | 103 | * @method |
| 100 | */ | 104 | */ |
| 101 | public function del($condition){ | 105 | public function del($condition){ |
| 102 | - return $this->where($condition)->delete(); | 106 | + $query = $this->formatQuery($condition); |
| 107 | + return $query->delete(); | ||
| 103 | } | 108 | } |
| 104 | 109 | ||
| 105 | 110 | ||
| 106 | /** | 111 | /** |
| 107 | * @param $map = ['$k'=>['like',$v],$k1] | 112 | * @param $map = ['$k'=>['like',$v],$k1] |
| 108 | * @param $val | 113 | * @param $val |
| 109 | - * @name | 114 | + * @name :参数处理查询 |
| 110 | * @return Base | 115 | * @return Base |
| 111 | * @author :liyuhang | 116 | * @author :liyuhang |
| 112 | * @method | 117 | * @method |
| 113 | */ | 118 | */ |
| 114 | - public function formatQuery($map = []){ | 119 | + public function formatQuery($map = [],$query = ''){ |
| 115 | $query = $this; | 120 | $query = $this; |
| 116 | $query->where(function ($query) use ($map){ | 121 | $query->where(function ($query) use ($map){ |
| 117 | foreach ($map as $k => $v){ | 122 | foreach ($map as $k => $v){ |
-
请 注册 或 登录 后发表评论