/** * 编辑供应商信息的函数 * @return void */ public function view_editType() { $category_id = post_check($_GET['id']); $result = PartnerTypeAct::act_getPartnerTypeInfo($category_id); $category_name = $result[0]['category_name']; $this->smarty->assign("category_id", $category_id); $this->smarty->assign("category_name", $category_name); $this->smarty->display('editPartnerType.htm'); }
/** * 导入供应商信息的函数 * 基于 PHPExcel.php * @return $result $result > 0 成功,否则失败 */ public function act_importSave() { $uploadfile = date("Y") . date("m") . date("d") . rand(1, 3009) . ".xls"; if (!move_uploaded_file($_FILES['upfile']['tmp_name'], WEB_PATH . 'upload_datas/' . $uploadfile)) { return false; } $fileName = WEB_PATH . 'upload_datas/' . $uploadfile; $filePath = $fileName; $PHPExcel = new PHPExcel(); $PHPReader = new PHPExcel_Reader_Excel2007(); if (!$PHPReader->canRead($filePath)) { $PHPReader = new PHPExcel_Reader_Excel5(); if (!$PHPReader->canRead($filePath)) { echo 'no Excel'; return; } } $PHPExcel = $PHPReader->load($filePath); $currentSheet = $PHPExcel->getSheet(0); /**取得一共有多少列*/ $c = 2; while (true) { $aa = 'A' . $c; $bb = 'B' . $c; $cc = 'C' . $c; $dd = 'D' . $c; $ee = 'E' . $c; $ff = 'F' . $c; $gg = 'G' . $c; $hh = 'H' . $c; $ii = 'I' . $c; $jj = 'J' . $c; $kk = 'K' . $c; $ll = 'L' . $c; $mm = 'M' . $c; $nn = 'N' . $c; $oo = 'O' . $c; $pp = 'P' . $c; $qq = 'Q' . $c; $rr = 'R' . $c; $ss = 'S' . $c; $tt = 'T' . $c; $uu = 'U' . $c; $vv = 'V' . $c; $ww = 'W' . $c; $zz = 'Z' . $c; $xx = 'X' . $c; $c++; $company_name = str_rep(trim($currentSheet->getCell($aa)->getValue())); $username = str_rep(trim($currentSheet->getCell($bb)->getValue())); $category_name = str_rep(trim($currentSheet->getCell($cc)->getValue())); $tel = str_rep(trim($currentSheet->getCell($dd)->getValue())); $phone = str_rep(trim($currentSheet->getCell($ee)->getValue())); $fax = str_rep(trim($currentSheet->getCell($ff)->getValue())); $QQ = str_rep(trim($currentSheet->getCell($gg)->getValue())); $e_mail = str_rep(trim($currentSheet->getCell($hh)->getValue())); $AliIM = str_rep(trim($currentSheet->getCell($ii)->getValue())); $shoplink = str_rep(trim($currentSheet->getCell($jj)->getValue())); $city = str_rep(trim($currentSheet->getCell($kk)->getValue())); $address = str_rep(trim($currentSheet->getCell($ll)->getValue())); $status = str_rep(trim($currentSheet->getCell($mm)->getValue())); $email_status = str_rep(trim($currentSheet->getCell($nn)->getValue())); $sms_status = str_rep(trim($currentSheet->getCell($oo)->getValue())); $purchaser = str_rep(trim($currentSheet->getCell($pp)->getValue())); $company = str_rep(trim($currentSheet->getCell($qq)->getValue())); $note = str_rep(trim($currentSheet->getCell($rr)->getValue())); $partnerStr = "单位名称:{$company_name}, 姓名:{$username}, 电话:{$tel} ... "; //var_dump(self::check_input($company_name)); //exit; if ($company_name != '' && !self::check_input($company_name)) { $errInfo = " -[<font color='#FF0000'>导入失败, '单位名称':'{$company_name}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($username != '' && !self::check_input($username)) { $errInfo = " -[<font color='#FF0000'>导入失败, '姓名':'{$username}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($category_name != '' && !self::check_input($category_name)) { $errInfo = " -[<font color='#FF0000'>导入失败, '单位类型':'{$category_name}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($tel != '' && !self::isTel($tel)) { $errInfo = " -[<font color='#FF0000'>导入失败, '电话号码':'{$tel}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($phone != '' && !self::isMobile($phone)) { $errInfo = " -[<font color='#FF0000'>导入失败, '手机号码':'{$phone}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($fax != '' && !self::isPhone($fax)) { $errInfo = " -[<font color='#FF0000'>导入失败, '传真号码':'{$fax}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($QQ != '' && !self::isQQ($QQ)) { $errInfo = " -[<font color='#FF0000'>导入失败, 'QQ号码':'{$QQ}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($e_mail != '' && !self::isEmail($e_mail)) { $errInfo = " -[<font color='#FF0000'>导入失败, '邮件':'{$e_mail}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($AliIM != '' && !self::isNormalCharacter($AliIM)) { $errInfo = " -[<font color='#FF0000'>导入失败, '阿里旺旺':'{$AliIM}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($city != '' && !self::check_input($city)) { $errInfo = " -[<font color='#FF0000'>导入失败, '所属城市':'{$city}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($address != '' && !self::check_input($address)) { $errInfo = " -[<font color='#FF0000'>导入失败, '地址':'{$address}' 填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } $status = $status == '黑名单' ? 0 : $status == '正常' ? 1 : 2; if ($status < 0 || $status > 2) { $errInfo = " -[<font color='#FF0000'>导入失败, '状态'填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } $email_status = $email_status == '是' ? 1 : 0; if ($email_status != 0 && $email_status != 1) { $errInfo = " -[<font color='#FF0000'>导入失败, '支持邮件'填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } $sms_status = $sms_status == '是' ? 1 : 0; if ($sms_status != 0 && $sms_status != 1) { $errInfo = " -[<font color='#FF0000'>导入失败, '支持短信'填写有误!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } if ($company_name == '') { break; } //$c++; //To get type_id $where = " AND `category_name` = '{$category_name}' "; $field = " `id` "; $resultType = PartnerTypeAct::act_getPartnerTypeList($where, $field); $type_id = $resultType[0]['id']; if (!isset($type_id)) { $errInfo = " -[<font color='#FF0000'>导入失败, 单位类型 '{$category_name}' 不存在!" . $partnerStr . "</font>]"; continue; } //To get purchaser_id $where = " AND `global_user_name` = '{$purchaser}' "; $field = " `global_user_id` "; $resultPurchase = self::act_getPurchaserList($where, $field); $purchaser_id = $resultPurchase[0]['global_user_id']; if (!isset($purchaser_id)) { $errInfo = " -[<font color='#FF0000'>导入失败, 采购员 '{$purchaser}' 不存在!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } //To get company_id $where = " AND `company` = '{$company}' "; $field = " `id` "; $resultCompany = self::act_getPartnerCompany($where, $field); //print_r($resultCompany); $company_id = $resultCompany[0]['id']; if (!isset($company_id)) { $errInfo = " -[<font color='#FF0000'>导入失败, 关联公司 '{$company}' 不存在!" . $partnerStr . "</font>]"; echo $errInfo . '<br>'; continue; } $data = array('company_name' => $company_name, 'username' => $username, 'type_id' => $type_id, 'tel' => $tel, 'phone' => $phone, 'fax' => $fax, 'QQ' => $QQ, 'AliIM' => $AliIM, 'e_mail' => $e_mail, 'shoplink' => $shoplink, 'city' => $city, 'address' => $address, 'note' => $note, 'status' => $status, 'sms_status' => $sms_status, 'email_status' => $email_status, 'purchaseuser_id' => $purchaser_id, 'company_id' => $company_id); //print_r($data); $result = PartnerModel::insertRow($data); if ($result) { $errInfo = " -[<font color='#33CC33'>导入成功, " . $partnerStr . "</font>]"; } else { $errMsg = PartnerModel::$errMsg; $errInfo = " -[<font color='#FF0000'>导入失败, " . $partnerStr . $errMsg . "</font>]"; } echo $errInfo . '<br>'; } }
/** * 编辑供应商信息的函数 * @return void */ public function view_editPartner() { $this->smarty->assign('title', '修改供应商信息'); $partnerId = post_check($_GET['id']); $field = " pp.limit_money,pp.limit_alert_money,pp.is_sign,pp.id,pp.company_name,ppt.category_name,pp.username,pp.type_id,pp.status,pp.tel,pp.phone,pp.fax,pp.QQ,pp.AliIM,pp.e_mail,pp.shoplink,pp.address,pp.city,pp.email_status,pp.sms_status,pu.global_user_name as purchaser,pp.note,pp.company_id,pp.purchaseuser_id "; $result = PartnerAct::act_getPartnerInfo($partnerId, $field); $this->smarty->assign("partnerInfo", $result[0]); $isSMSChecked = $result[0]['sms_status'] == '1' ? 'checked="checked"' : ''; $isEmailChecked = $result[0]['email_status'] == '1' ? 'checked="checked"' : ''; $this->smarty->assign("isSMSChecked", $isSMSChecked); $this->smarty->assign("isEmailChecked", $isEmailChecked); $where = ''; $field = ' `id`, `category_name` '; $list = PartnerTypeAct::act_getPartnerTypeList($where, $field); krsort($list); $option_values = array(); $option_output = array(); $type_id = 0; foreach ($list as $key => $type) { $option_values[] = $type['id']; $option_output[] = $type['category_name']; if ($result[0]['type_id'] == $type['id']) { $type_id = $type['id']; } } $this->smarty->assign("option_values", $option_values); $this->smarty->assign("option_output", $option_output); $this->smarty->assign("option_selected", $type_id); $field = ' `id`,`company` '; $list = PartnerAct::act_getPartnerCompany($where, $field); $option_company_id = array(); $option_company_name = array(); $company_id = 0; foreach ($list as $key => $company) { $option_company_id[] = $company['id']; $option_company_name[] = $company['company']; if ($result[0]['company_id'] == $company['id']) { $company_id = $company['id']; } } $this->smarty->assign("option_company_id", $option_company_id); $this->smarty->assign("option_company_name", $option_company_name); $this->smarty->assign("option_company_selected", $company_id); $field = " global_user_id as id, global_user_login_name as username "; $where = " and global_user_id in ({$_SESSION['access_id']})"; $list = PartnerAct::act_getPurchaserList($where, $field); $option_purchaser_id = array(); $option_purchaser = array(); $purchaser_id = 0; foreach ($list as $key => $purchaser) { $option_purchaser_id[] = $purchaser['id']; $option_purchaser[] = $purchaser['global_user_name']; if ($result[0]['purchaseuser_id'] == $purchaser['id']) { $purchaser_id = $purchaser['id']; } } $purchaseList = getPurchaseUserList(); $this->smarty->assign('purchaseList', $purchaseList); //采购列表 $this->smarty->assign("option_purchaser_id", $option_purchaser_id); $this->smarty->assign("option_purchaser", $option_purchaser); $this->smarty->assign("option_purchaser_selected", $purchaser_id); $this->smarty->display('editPartner.htm'); }