GreenCate.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class GreenCate extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'green_cate';
  9. protected $validateName = 'GreenCate';
  10. public function updates(){
  11. $data = request()->post();
  12. $data['org_id'] = cur_org_id();
  13. $result = validate($this->validateName)->check($data,[],'');
  14. if(true !== $result){
  15. $this->error = validate($this->validateName)->getError();
  16. return false;
  17. }
  18. $id = $data['id'];
  19. unset($data['id']);
  20. unset($data['type']);
  21. if($id > 0){
  22. $data['update_time'] = date('Y-m-d H:i:s');
  23. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  24. }else{
  25. $data['create_time'] = date('Y-m-d H:i:s');
  26. $ret = $this->allowField(true)->save($data);
  27. }
  28. if(!$ret){
  29. $this->error = '操作失败';
  30. return false;
  31. }
  32. return true;
  33. }
  34. }