MateGoods.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class MateGoods extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'mate_goods';
  9. protected $validateName = 'MateGoods';
  10. public function updates(){
  11. $data = request()->post();
  12. $data['buy_time'] = $data['buy_time']?$data['buy_time']:null;
  13. $data['org_id'] = cur_org_id();
  14. $result = validate($this->validateName)->check($data,[],'');
  15. if(true !== $result){
  16. $this->error = validate($this->validateName)->getError();
  17. return false;
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  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. public function getList($offset,$size,$where,$order){
  35. $list =$this
  36. ->where($where)
  37. ->limit($offset,$size)
  38. ->order($order)
  39. ->select()
  40. ->toArray();
  41. return $list;
  42. }
  43. }