12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace app\common\model;
- use think\Db;
- use think\Exception;
- use think\Model;
- class Base extends Model
- {
- // 不需要存入时间的可以直接调用
- protected function updateInfo($data,$valiname,$scene=''){
- $result = validate($valiname)->check($data,[],$scene);
- if(true !== $result){
- $this->error = validate($valiname)->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->error = '操作失败';
- return false;
- }
- return true;
- }
- public function getTableField($table,$where,$field){
- $val = Db::name($table)
- ->where($where)
- ->value($field);
- return $val?$val:"";
- }
- }
|