function getAreaId($data, $pid) { foreach ($data as $k => $v) { if ($v['parent_id'] == $pid) { $id .= getAreaId($data, $v['id']); $id .= $v['id'] . ','; } } return $id; }
public function foreverdelete() { //删除指定记录 $name = $this->getActionName(); $model = D($name); if (!empty($model)) { $pk = $model->getPk(); $id = $_REQUEST[$pk]; if (isset($id)) { $node = M("Areas"); $menu = $node->order('listorder')->select(); $idlist = $id . ',' . getAreaId($menu, $id); $idlist = substr($idlist, 0, strlen($idlist) - 1); $condition = array($pk => array('in', explode(',', $idlist))); if (false !== $model->where($condition)->delete()) { $this->success('删除成功!'); } else { $this->error('删除失败!'); } } else { $this->error('非法操作'); } } //$this->forward(); }
function insert($data) { global $dbCom; $temp = $dbCom->get("cb_combusiness", array('cid'), array('comname' => $data['Name'], 'LIMIT' => 1)); if (!empty($temp['cid'])) { //数据存在不采集 //根据注册号 判断是否有重复 if (!empty($data['No']) && (strlen($data['No']) == 13 || strlen($data['No']) == 15)) { $temp = $dbCom->get("cb_combusiness", array('cid'), array('regno' => $data['No'], 'LIMIT' => 1)); if (is_array($temp) && !empty($temp) && $temp['cid'] > 0) { $update = array('comname' => $data['Name'], 'uniqueno' => unique($data['Name'], $data['No']), 'scope' => $data['Scope'], 'state' => $data['Status'], 'comtype' => $data['EconKind'], 'regcapital' => regcap($data['RegistCapi']), 'address' => $data['Address'], 'businessstart' => strtotime($data['TermStart']), 'businessend' => strtotime($data['TeamEnd']), 'checkdate' => strtotime($data['CheckDate']), 'regagency' => $data['BelongOrg'], 'legal' => $data['OperName'], 'startdate' => strtotime($data['StartDate']), 'enddate' => strtotime($data['EndDate']), 'cate1' => 0, 'cate2' => 0, 'uptime' => strtotime($data['UpdatedDate']), 'areaid' => getAreaId($data['No']), 'RegistCapi' => $data['RegistCapi']); $update = area($update, $data); $dbCom->update("cb_combusiness", $update, array('cid' => $temp['cid'])); } } return $temp['cid']; } //写入主表 $insert = array('comname' => $data['Name'], 'regno' => $data['No'], 'uniqueno' => unique($data['Name'], $data['No']), 'scope' => $data['Scope'], 'state' => $data['Status'], 'comtype' => $data['EconKind'], 'regcapital' => regcap($data['RegistCapi']), 'address' => $data['Address'], 'businessstart' => strtotime($data['TermStart']), 'businessend' => strtotime($data['TeamEnd']), 'checkdate' => strtotime($data['CheckDate']), 'regagency' => $data['BelongOrg'], 'legal' => $data['OperName'], 'startdate' => strtotime($data['StartDate']), 'enddate' => strtotime($data['EndDate']), 'cate1' => 0, 'cate2' => 0, 'uptime' => strtotime($data['UpdatedDate']), 'areaid' => getAreaId($data['No']), 'RegistCapi' => $data['RegistCapi']); //bug处理 empty($insert['scope']) && ($insert['scope'] = '无'); empty($insert['regno']) && ($insert['regno'] = '0'); // empty($insert['comtype']) && $insert['comtype'] = '无'; // empty($insert['state']) && $insert['state'] = '无'; // empty($insert['regcapital']) && $insert['regcapital'] = 0; // empty($insert['address']) && $insert['address'] = '无'; empty($insert['regagency']) && ($insert['regagency'] = '无'); // empty($insert['legal']) && $insert['legal'] = '无'; //省 市 区处理 $insert = area($insert, $data); $cid = $dbCom->insert('cb_combusiness', $insert); if ($cid <= 0) { print_r($dbCom->error()); die; return; } //分公司 if (is_array($data['Branches']) && !empty($data['Branches'])) { $insert = array(); foreach ($data['Branches'] as $value) { $insert[] = array('cid' => $cid, 'regno' => $value['RegNo'], 'comname' => $value['Name']); } if (is_array($insert) && !empty($insert)) { $dbCom->insert('cb_branch', $insert); } } //联系人 if (isset($data['ContactInfo']) && $data['ContactInfo'] && !empty($data['ContactInfo'])) { $insert = array('cid' => $cid, 'WebSite' => isset($data['ContactInfo']['WebSite']) ? json_encode($data['ContactInfo']['WebSite'], JSON_UNESCAPED_UNICODE) : json_encode(array()), 'PhoneNumber' => isset($data['ContactInfo']['PhoneNumber']) ? $data['ContactInfo']['PhoneNumber'] : '', 'Email' => isset($data['ContactInfo']['Email']) ? $data['ContactInfo']['Email'] : array()); if (is_array($insert) && !empty($insert)) { $dbCom->insert('cb_com_contact', $insert); } } //变更记录 if (is_array($data['ChangeRecords']) && !empty($data['ChangeRecords'])) { $insert = array(); foreach ($data['ChangeRecords'] as $value) { $insert[] = array('cid' => $cid, 'infoname' => $value['ProjectName'], 'oldvalue' => $value['BeforeContent'], 'newvalue' => $value['AfterContent'], 'uptime' => strtotime($value['ChangeDate'])); } if (is_array($insert) && !empty($insert)) { $dbCom->insert('cb_changelog', $insert); } } //主要员工 if (is_array($data['Employees']) && !empty($data['Employees'])) { $insert = array(); foreach ($data['Employees'] as $value) { $insert[] = array('cid' => $cid, 'name' => $value['Name'], 'job' => $value['Job'], 'certno' => isset($value['CerNo']) && !empty($value['CerNo']) ? $value['CerNo'] : '无'); } if (is_array($insert) && !empty($insert)) { $dbCom->insert('cb_employee', $insert); } } //合伙人 if (is_array($data['Partners']) && !empty($data['Partners'])) { $insert = array(); foreach ($data['Partners'] as $value) { $insert[] = array('cid' => $cid, 'stockholder' => $value['StockName'], 'stocktype' => $value['StockType'], 'stockpercent' => $value['StockPercent'], 'identifyname' => $value['IdentifyType'], 'identifyno' => $value['IdentifyNo'], 'shouldcapi' => $value['ShouldCapi'], 'shoulddate' => is_string($value['ShoudDate']) ? strtotime($value['ShoudDate']) : '', 'shouldtype' => $value['InvestType'], 'realtype' => $value['InvestType'], 'realcapi' => $value['RealCapi'], 'realdate' => is_string($value['CapiDate']) ? strtotime($value['CapiDate']) : ''); if (!is_string($value['ShoudDate']) || !is_string($value['CapiDate'])) { // print_r($value); } } if (is_array($insert) && !empty($insert)) { $dbCom->insert('cb_partner', $insert); } } return $cid; }