post(); $data['org_id'] = cur_org_id(); $result = validate($this->validateName)->check($data,[],''); if(true !== $result){ $this->error = validate($this->validateName)->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; } // 检查几个任务内容是否在同一分类下,在同一分类下返回分类ID public function check_form_type($ids) { $ret = Db::name('f_clean_form') ->alias('clean_form') ->join('f_clean_type clean_type','clean_type.id = clean_form.type_id') ->field('clean_form.id,clean_form.title,clean_type.parent_id') ->whereIn('clean_form.ID',$ids) ->select(); $types = array(); foreach ($ret as $k=>$v){ if(empty($types)){ $types[] = $v['parent_id']; } else if(!in_array($v['parent_id'],$types)){ $types[] = $v['parent_id']; } } return count($types) == 1 ? $types[0] : 0; } public function queryAddByForm($recordId,$formId){ // $recordId 任务id $formId 表单id $record = Db::name('f_clean_record')->where('task_id',$recordId) ->where('form_id',$formId) ->find(); $items = []; if($record){ $addrlist = json_decode($record['check_json'],true); foreach ($addrlist as $k=>$v){ $address = Db::name('address')->where('id',$v['id']) ->value('title'); $addrlist[$k]['address_name'] = $address; } $items = Db::name('f_clean_record_items') ->alias('cr') ->join('mate_goods mm','cr.items_id=mm.id','left') ->where('cr.record_id',$record['id']) ->field('cr.items_id as itemsId,mm.title,cr.total,cr.money') ->select(); }else{ $address = Db::name('f_clean_form') ->where('id',$formId)->find(); $addrs = explode(',',$address['address_ids']); $alist = Db::name('address') ->where('id','in',$addrs)->select(); $addrlist = []; foreach ($alist as $k=>$v){ $d = [ 'address_id' => $v['id'], 'status' => 0, 'address_name' => $v['title'] ]; $addrlist[] = $d; } } $data = [ 'address' => $addrlist, 'remark' => $record?$record['content']:'', 'items' => $items?$items:[] ]; return $data; } }