date('Y-m-d H:i:s'), 'create_yyyy'=>date('Y'), 'create_yyyymm'=>date('Ym'), 'create_yyyymmdd'=>date('Ymd'), ]; $items =$post['items']; unset($post['items']); $data = array_merge($data,$post); $this->startTrans(); try{ $recordId = $this->insertGetId($data); if(intval($recordId) <=0){ exception('添加记录失败'); } foreach ($items as $k=>$v){ $items[$k]['create_time'] =date('Y-m-d H:i:s'); $items[$k]['washing_record_id'] =$recordId; } $res = Db::name('washing_record_item')->insertAll($items); if (!$res) { \exception('保存物品失败'); } $data['id'] = $recordId; $this->commit(); return true; }catch (Exception $e){ $this->rollback(); $this->error = $e->getMessage(); return false; } } public function returnWash($id,$orgId){ $ret = $this->where('id',$id) ->where('mode',1) ->where('org_id',$orgId) ->find(); if(!$ret){ $this->error='记录不存在,或当前状态已归还'; return false; } $res = $this->where('id',$id)->update( ['mode'=>2,'return_time'=>date('Y-m-d H:i:s')]); return $res; } public function confirmWash($id,$orgId,$sign='',$img=''){ $ret = $this->where('id',$id) ->where('mode',2) ->where('org_id',$orgId) ->find(); if(!$ret){ $this->error='记录不存在,或当前状态不可确认'; return false; } $res = $this->where('id',$id)->update( ['mode'=>3,'confirm_time'=>date('Y-m-d H:i:s'),'sign'=>$sign,'img'=>$img]); return $res; } public function getApiList($page,$size,$type,$userId,$orgId){ $offset =($page-1)*$size; $data = $this ->alias('a') ->join('address b','a.dep_id=b.id') ->field('a.id,a.create_time,a.return_time,a.confirm_time,b.title,a.mode as mode') ->where('a.mode',$type) ->where('a.user_id',$userId) ->where('a.org_id',$orgId) ->where('a.del',0) ->limit($offset,$size) ->select(); $data = $data?$data->toArray():[]; foreach ($data as $k=>$v){ $data[$k]['return_time'] = $v['return_time']?$v['return_time']:''; $data[$k]['confirm_time'] = $v['confirm_time']?$v['confirm_time']:''; } return $data; } }