ShopGoodsCate.php 1.2 KB

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