DinnerGroup.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class DinnerGroup extends Base
  5. {
  6. public function updates(){
  7. $data = request()->post();
  8. $data['org_id'] = cur_org_id();
  9. if($data['id'] <= 0){ //新增
  10. if($data['week'] == 0){ // 本周
  11. $week = get_week_days(0);
  12. }else{ // 下周
  13. $week = get_week_days(1);
  14. }
  15. $data['start'] = $week[0];
  16. $data['end'] = $week[1];
  17. unset($data['week']);
  18. }else{
  19. $info = Db::name('dinner_group')->where('id',$data['id'])->find();
  20. if(!$info){
  21. $this->error = "记录不存在";
  22. return false;
  23. }
  24. $data['start'] = $info['start'];
  25. $data['end'] = $info['end'];
  26. }
  27. $result = validate('DinnerGroup')->check($data,[],'');
  28. if(true !== $result){
  29. $this->error = validate('DinnerGroup')->getError();
  30. return false;
  31. }
  32. $id = $data['id'];
  33. unset($data['id']);
  34. if($id > 0){
  35. $data['update_time'] = date('Y-m-d H:i:s');
  36. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  37. }else{
  38. $data['create_time'] = date('Y-m-d H:i:s');
  39. $ret = $this->allowField(true)->save($data);
  40. }
  41. if(!$ret){
  42. $this->error = '操作失败';
  43. return false;
  44. }
  45. return true;
  46. }
  47. }