DinnerType.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class DinnerType extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. protected $table = 'dinner_type';
  9. protected $validateName = 'DinnerType';
  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. $name = '菜品分类';
  32. $content = $name.':新增';
  33. if($id > 0){
  34. $content = $name.':编辑';
  35. $data['id'] = $id;
  36. }else{
  37. $data['id'] = $this->id;
  38. }
  39. return true;
  40. }
  41. public function getList($orgId){
  42. $typeList = Db::name('dinner_type')
  43. ->where('org_id',$orgId)
  44. ->where('enable',1)
  45. ->where('del',0)
  46. ->order('sort asc,id asc')
  47. ->select();
  48. return $typeList;
  49. }
  50. }