Base.php 955 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Exception;
  5. use think\Model;
  6. class Base extends Model
  7. {
  8. // 不需要存入时间的可以直接调用
  9. protected function updateInfo($data,$valiname,$scene=''){
  10. $result = validate($valiname)->check($data,[],$scene);
  11. if(true !== $result){
  12. $this->error = validate($valiname)->getError();
  13. return false;
  14. }
  15. $id = $data['id'];
  16. unset($data['id']);
  17. if($id > 0){
  18. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  19. }else{
  20. $ret = $this->allowField(true)->save($data);
  21. }
  22. if(!$ret){
  23. $this->error = '操作失败';
  24. return false;
  25. }
  26. return true;
  27. }
  28. public function getTableField($table,$where,$field){
  29. $val = Db::name($table)
  30. ->where($where)
  31. ->value($field);
  32. return $val?$val:"";
  33. }
  34. }