Exemple #1
0
/*** 会社と顧客担当者とKW情報とのひもづけ ******/
//登録日(申込日)
#$rkw_resistdate = $rowItem['rkw_resistdate'];
//更新間隔
$rkw_contract_term = $rowItem['rkw_contract_term'];
if ($rkw_contract_term === '0:なし') {
    $rkw_contract_term = 0;
}
//顧客企業ID(accountid)
//$rowItem['rcl_id']の値があるかどうか
if ((int) $rowItem['rcl_id'] !== 0) {
    #JASのクライアントIDがある場合
    $rkw_rclid = $rowItem['rcl_id'];
} else {
    #JASのクライアントIDがない場合
    $rkw_rclid = jas_account_save($rowItem['accountid']);
}
//End if
$rkw_client = $rowItem['accountname'];
#exit;
//顧客担当者ID(contactid)
//$rowItem['rcm_id']の値があるかどうか
if ((int) $rowItem['rcm_id'] !== 0) {
    #担当者IDが保存されているとき
    $rkw_rcmid = $rowItem['rcm_id'];
} elseif ((int) $rowItem['contactid'] !== 0) {
    #担当者IDがない場合
    //JASに担当者情報を保存する
    $rkw_rcmid = jas_contact_save($rowItem['contactid']);
} else {
    $rkw_rcmid = 0;
function jas_products_save($productid, $salesorderflag)
{
    $arrrUrlStrict = array("part" => "0", "部分一致(下層ページも課金対象)" => "0", "domain" => "1", "ドメイン一致" => "1", "perfect" => "2", "完全一致" => "2", "文字のマッチ" => "3", "文字マッチ" => "3", "character" => "3");
    $queryItem = " SELECT * FROM `vtiger_products` ";
    $queryItem .= " LEFT JOIN  `vtiger_account` ON `seo_agency_customers` = `accountid`";
    $queryItem .= " WHERE TRUE ";
    $queryItem .= " AND productid = {$productid} ";
    $queryItem .= " AND productcategory = 'SEO' ";
    print $queryItem . "<br /><br />";
    global $adb;
    $resultItem = $adb->pquery($queryItem);
    $countItemNum = $adb->num_rows($resultItem);
    $rowItem = $adb->fetch_array($resultItem);
    #if($countItemNum === 0) return false;
    #print "コメントあうとしてね<br /><br />";
    if (is_null($rowItem[seo_keyword]) || is_null($rowItem[seo_url])) {
        return false;
    }
    #キーワード、URLどちらかが空で合った場合、登録・変更しない
    //KwIDの取得(基幹)
    $arrKeywordInfo['rkw_id'] = (int) $rowItem['seo_kwid'];
    #Kwid
    /** ▼ JASへの代理店顧客情報保存準備 ****/
    if ((int) $rowItem['seo_agency_customers'] !== 0) {
        #代理店顧客があるとき
        if ($rowItem['jgid'] == false) {
            //JASに代理店顧客情報がないので登録する
            $_POST['agencyflag'] = true;
            $arrKeywordInfo['rkw_child_cliid'] = jas_account_save($rowItem['accountid']);
            $arrKeywordInfo['rkw_child_client'] = $rowItem['accountname'];
        } else {
            $arrKeywordInfo['rkw_child_cliid'] = $rowItem['jgid'];
            $arrKeywordInfo['rkw_child_client'] = $rowItem['accountname'];
        }
        //End if
    } else {
        #代理店顧客がないとき
        $arrKeywordInfo['rkw_child_cliid'] = 0;
        $arrKeywordInfo['rkw_child_client'] = "";
    }
    //End if
    /** ▲ JASへの代理店顧客情報保存準備 ****/
    #rkw_word キーワード名
    $arrKeywordInfo['rkw_word'] = $rowItem['seo_keyword'];
    #rkw_url
    $arrKeywordInfo['rkw_url'] = $rowItem['seo_url'];
    #$arrKeywordInfo['rkw_resistdate'] = date('Y-m-d');
    #rkw_contract_startdate 契約期間開始日
    $arrKeywordInfo['rkw_contract_startdate'] = $rowItem['start_date'];
    #rkw_contract_enddate   契約期間終了日
    $arrKeywordInfo['rkw_contract_enddate'] = $rowItem['expiry_date'];
    #rkw_url_strict	順位チェック方法
    $arrKeywordInfo['rkw_url_strict'] = $arrrUrlStrict[$rowItem['seo_rank_check']];
    #rkw_away_flag 解約処理
    if ((int) $rowItem['seo_away_flag'] === 1) {
        #有効がいいえのとき
        $arrKeywordInfo['rkw_away_flag'] = 1;
        #JASの解約フラグをたてる
    } else {
        #それ以外(有効がはいのとき)
        $arrKeywordInfo['rkw_away_flag'] = 0;
        #JASの解約フラグを解除する
    }
    //End if
    #rkw_fee_month 月額固定金額
    $arrKeywordInfo['rkw_fee_month'] = (int) preg_replace('@,@', '', $rowItem['unit_price']);
    print "KwId : " . $arrKeywordInfo['rkw_id'] . "<br />";
    echo "<pre>";
    var_dump($salesorderflag);
    var_dump($arrKeywordInfo);
    echo "</pre>";
    /** ▼ JASへの反映 **/
    if ($salesorderflag == true && $arrKeywordInfo['rkw_id'] === 0) {
        #JASにKWが登録されているとき
        /** ▼ JASのキーワードデータの追加 *****/
        #rkw_input_flag キーワード内訳
        $arrKeywordInfo['rkw_input_flag'] = 1;
        #rkw_segment セグメント
        $arrKeywordInfo['rkw_segment'] = 1;
        #rkw_random_flag ランダムフラグ デフォルト値:1
        $arrKeywordInfo['rkw_random_flag'] = 1;
        $arrKeywordInfo['rkw_fee_status'] = '固定';
        $arrKeywordInfo['rkw_account_type'] = 4;
        foreach ($arrKeywordInfo as $rkw_fields_name => $strKeywordData) {
            $_POST[$rkw_fields_name] = $strKeywordData;
        }
        //End foreach
        //キーワードIDの初期化
        unset($_POST['rkw_id']);
        print "Insert : " . DataJasInsertString('rank_keyword') . "<br /><br />";
        $_POST['rkw_id'] = DataJasInsert('rank_keyword');
        $queryInsert = " UPDATE `vtiger_products` SET ";
        $queryInsert .= " seo_kwid = {$_POST['rkw_id']} ";
        $queryInsert .= " WHERE TRUE ";
        $queryInsert .= " AND productid = {$productid} ";
        print $queryInsert . "<br /><br />";
        global $adb;
        $adb->pquery($queryInsert);
        /** ▲ JASのキーワードデータの追加 *****/
    } elseif ($arrKeywordInfo['rkw_id'] === 0) {
        #キーワードIDが0のときはなにもしない
        return false;
    } elseif ($module === 'Products' || $module === 'Services') {
        #製品登録のみキーワードの更新をおこなう
        /** ▼ JASのキーワードデータの更新 ***/
        /** ▼ 変更前キーワード情報の取得 ****/
        #		require('cin/SQLConnect.php');
        require 'cin/SQLConnect_jas.php';
        $sqlRkw = "SELECT * FROM rank_keyword WHERE TRUE AND rkw_id = {$arrKeywordInfo['rkw_id']} ";
        print $sqlRkw . "<br /><br />";
        $rsRkw = mysql_db_query($dbName, $sqlRkw);
        $rsCountRkw = mysql_num_rows($rsRkw);
        $rowRkw = mysql_fetch_array($rsRkw);
        $arrRkw = $rowRkw;
        if ((int) $rowRkw['rkw_account_type'] !== 4) {
            return false;
        }
        require 'cin/SQLClose.php';
        /** ▲ 変更前キーワード情報の取得 ****/
        /** ▼ ** キーワードの履歴を保存する ****/
        foreach ($arrRkw as $rkw_fields_name => $strRkwValue) {
            unset($_POST[$rkw_fields_name]);
            $_POST[$rkw_fields_name] = $strRkwValue;
        }
        //End foreach
        $_POST[rkw_create_datetime] = date('Y-m-d H:i:s');
        print "Insert : " . DataInsertString('backup_keyword') . "<br /><br />";
        DataInsert('backup_keyword');
        /** ▲ ** キーワードの履歴を保存する ****/
        /** ▼ ** 変更後の反映 *********/
        foreach ($arrKeywordInfo as $rkw_fields_name => $strKeywordData) {
            $_POST[$rkw_fields_name] = $strKeywordData;
        }
        //End foreach
        print "Update : " . DataJasUpdateString('rank_keyword') . "<br /><br />";
        DataJasUpdate('rank_keyword');
        /** ▲ ** 変更後の反映 **********/
        /** ▲ JASのキーワードデータの更新 ***/
    }
    //End if
    /** ▼ ** vitiger_crmentityへの契約期間を説明に反映 ***/
    $queryUpdate = " UPDATE `vtiger_crmentity` SET ";
    $queryUpdate .= " description = CONCAT(";
    $queryUpdate .= " description, ' 契約期間:" . $arrKeywordInfo['rkw_contract_startdate'] . "~" . $arrKeywordInfo['rkw_contract_enddate'] . "' ";
    $queryUpdate .= " ) ";
    $queryUpdate .= " WHERE TRUE ";
    $queryUpdate .= " AND crmid = {$productid} ";
    print $queryUpdate . "<br /><br />";
    global $adb;
    $adb->pquery($queryUpdate);
    /** ▲ ** vtiger_crmentityへの契約期間を説明の反映 ***/
    registDomain($_POST[rkw_id]);
    return (int) $_POST[rkw_id];
}
Exemple #3
0
<?php

//月額固定の登録・更新
// テスト
#ini_set('include_path', '/var/www/vtigercrm');
#require_once('include/utils/utils.php');
#require_once('include/logging.php');
// テスト
#require_once('cin/defalut.php');
require_once 'cin/defalut.php';
require_once 'cin/common/client_common.php';
#$accountid = 20519;
jas_account_save($accountid);
function jas_contact_save($contactid)
{
    //vtiger_account
    $query = " SELECT ";
    $query .= " `firstname`, ";
    $query .= " `lastname`, ";
    $query .= " `title`, ";
    $query .= " `mailingzip`, ";
    $query .= " `mailingstate`, ";
    $query .= " `mailingcity`, ";
    $query .= " `mailingstreet`, ";
    $query .= " `otherzip`, ";
    $query .= " `otherstate`, ";
    $query .= " `othercity`, ";
    $query .= " `otherstreet`, ";
    $query .= " `vtiger_contactdetails`.`email`, ";
    $query .= " `vtiger_contactdetails`.`secondaryemail`, ";
    $query .= " `vtiger_contactdetails`.`phone`, ";
    $query .= " `vtiger_contactdetails`.`mobile`, ";
    $query .= " `vtiger_account`.`jgid` AS rcl_id, ";
    $query .= " `vtiger_account`.`accountid`, ";
    $query .= " `rcm_id`, ";
    $query .= " `accountname` FROM `vtiger_contactdetails` ";
    $query .= " LEFT JOIN `vtiger_contactaddress` ON contactid = contactaddressid ";
    $query .= " LEFT JOIN `vtiger_account` ON `vtiger_contactdetails`.`accountid` = `vtiger_account`.`accountid`";
    $query .= " WHERE TRUE ";
    $query .= " AND contactid = {$contactid} ";
    print $query . "<br /><br />";
    global $adb;
    $result = $adb->pquery($query);
    $countNum = $adb->num_rows($result);
    $row = $adb->fetch_array($result);
    $arrChargerMasData['rcm_name'] = $row['firstname'] . " " . $row['lastname'];
    $arrChargerMasData['rcm_post'] = $row['title'];
    $zip = $row['mailingzip'] ? $row['mailingzip'] : $row['otherzip'];
    $arrChargerMasData['rcm_postcode'] = $zip;
    $state = $row[$row['mailingstate']] ? $row['mailingstate'] : $row['otherstate'];
    $city = $row['mailingcity'] ? $row['mailingcity'] : $row['othercity'];
    $street = $row['mailingstreet'] ? $row['mailingstreet'] : $row['otherstreet'];
    $arrChargerMasData['rcm_address'] = $state . " " . $city . " " . $street;
    if ($row['email']) {
        $strRcmMail = $row['email'];
    } else {
        $strRcmMail = $row['secondaryemail'];
    }
    //End if
    $arrChargerMasData['rcm_mail'] = $strRcmMail;
    if ($row['phone']) {
        $strRcmTel = $row['phone'];
    } else {
        $strRcmTel = $row['mobile'];
    }
    //End if
    $arrChargerMasData['rcm_tel'] = $strRcmTel;
    $arrChargerMasData['rcm_client_id'] = $row['rcl_id'];
    $intAccountId = $row['accountid'];
    $strAccountName = $row['accountname'];
    $intRcmid = (int) $row['rcm_id'];
    //JASのクライアント情報(rank_client)の保存
    if ($arrChargerMasData['rcm_client_id'] == false) {
        $arrChargerMasData['rcm_client_id'] = jas_account_save($intAccountId);
    }
    if ($intRcmid !== 0 && $_POST['module'] === 'Contacts') {
        #基幹システムにJASの顧客担当者ID(rcm_id)が登録されているとき
        #JASの顧客担当者情報の変更
        updateChargerMasData($intRcmid, $arrChargerMasData);
        #JASのクライアント情報を更新
    } elseif ($_POST['division'] === '202:Webコミュ') {
        #基幹システムにJASのクライアントIDが登録されていないとき
        #		require('cin/SQLConnect.php');
        require 'cin/SQLConnect_jas.php';
        $sqlRcm = " SELECT * FROM rank_charger_mas ";
        $sqlRcm .= " INNER JOIN rank_client ON rcm_client_id = rcl_id ";
        $sqlRcm .= " WHERE TRUE ";
        $sqlRcm .= " AND rcl_name = '{$strAccountName}' ";
        $sqlRcm .= " AND rcm_name = '{$arrChargerMasData['rcm_name']}' LIMIT 0,1";
        print $sqlRcm . "<br /><br />";
        $rsRcm = mysql_db_query($dbName, $sqlRcm);
        $rsRcmCount = mysql_num_rows($rsRcm);
        if ($rsRcmCount !== 0) {
            #JASに顧客担当者情報があるとき
            //JASの顧客担当者IDを取得
            $rowRcm = mysql_fetch_array($rsRcm);
            $intRcmid = $rowRcm['rcm_id'];
            #JASの顧客担当者ID
            if ($_POST['module'] === 'Contacts') {
                updateChargerMasData($intRcmid, $arrChargerMasData);
                #JASの顧客担当者情報を更新
            }
            //End if
        } else {
            #JASに顧客担当者情報がないとき
            #JASに顧客担当者情報を登録(Insert)
            $intRcmid = insertChargerMasData($arrChargerMasData);
        }
        //End if
        require 'cin/SQLClose.php';
        #基幹システムに顧客担当者IDを保存(update)
        $query_contact = " UPDATE vtiger_contactdetails SET rcm_id = {$intRcmid} ";
        $query_contact .= " WHERE TRUE ";
        $query_contact .= " AND contactid = {$contactid} ";
        print "contact_update : " . $query_contact . "<br /><br />";
        $adb->pquery($query_contact);
    }
    //End if
    return $intRcmid;
}