WasteType.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class WasteType extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'waste_type';
  9. protected $validateName = 'WasteType';
  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. if($id > 0){
  21. $data['update_time'] = date('Y-m-d H:i:s');
  22. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  23. }else{
  24. $data['create_time'] = date('Y-m-d H:i:s');
  25. $ret = $this->allowField(true)->save($data);
  26. }
  27. if(!$ret){
  28. $this->error = '操作失败';
  29. return false;
  30. }
  31. return true;
  32. }
  33. public function getList($orgId){
  34. $list =$this
  35. ->where('org_id','in',[0,$orgId])
  36. ->where('del',0)
  37. ->where('enable',1)
  38. ->select()
  39. ->toArray();
  40. return $list;
  41. }
  42. public function list($orgId=0){
  43. $list =$this
  44. ->where('org_id','in',[0,$orgId])
  45. ->where('del',0)
  46. ->where('enable',1)
  47. ->select()
  48. ->toArray();
  49. return $list;
  50. }
  51. public function list1($orgId){
  52. $list =$this
  53. ->where('org_id','in',[0,$orgId])
  54. ->field('id as waste_id,title,type,unit')
  55. ->where('del',0)
  56. ->where('enable',1)
  57. ->select()
  58. ->toArray();
  59. return $list;
  60. }
  61. }