123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\common\model;
- use think\Db;
- class DinnerGroup extends Base
- {
- public function updates(){
- $data = request()->post();
- $data['org_id'] = cur_org_id();
- if($data['id'] <= 0){ //新增
- if($data['week'] == 0){ // 本周
- $week = get_week_days(0);
- }else{ // 下周
- $week = get_week_days(1);
- }
- $data['start'] = $week[0];
- $data['end'] = $week[1];
- unset($data['week']);
- }else{
- $info = Db::name('dinner_group')->where('id',$data['id'])->find();
- if(!$info){
- $this->error = "记录不存在";
- return false;
- }
- $data['start'] = $info['start'];
- $data['end'] = $info['end'];
- }
- $result = validate('DinnerGroup')->check($data,[],'');
- if(true !== $result){
- $this->error = validate('DinnerGroup')->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->error = '操作失败';
- return false;
- }
- return true;
- }
- }
|