Dinner.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class Dinner extends Base
  5. {
  6. public function updates($cate=0){
  7. $data = request()->post();
  8. $data['org_id'] = cur_org_id();
  9. if(($cate == 0 && $data['free'] == 1) || $cate == 1){
  10. $data['discount'] = 0;
  11. }
  12. $result = validate('Dinner')->check($data,[],'cate'.$cate);
  13. if(true !== $result){
  14. $this->error = validate('Dinner')->getError();
  15. return false;
  16. }
  17. $id = $data['id'];
  18. $data['imgs'] = $data['imgs']?implode(',',$data['imgs']):'';
  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. if($cate == 1){
  33. $name = '特殊人群菜单';
  34. }
  35. $content = $name.':新增';
  36. if($id > 0){
  37. $content = $name.':编辑';
  38. $data['id'] = $id;
  39. }else{
  40. $data['id'] = $this->id;
  41. }
  42. return true;
  43. }
  44. }