CompanyOrdered Table Configuration
CompanyOrdered Table Configuration
/**
* テーブル設定
*/
public $useTable = 'CompanyOrdered';
public $primaryKey = 'company_id';
/**
* Search プラグイン Searchable ビヘイビアの読込
*/
public $actsAs = [
'Search.Searchable',
'Containable'
];
/**
* アソシエーション
*/
public $hasMany = [
'ApprovalStatusLog' => [
'className' => 'ApprovalStatusLog',
'foreignKey' => 'company_id'
],
'CancelStatusLog' => [
'className' => 'CancelStatusLog',
'foreignKey' => 'company_id'
],
'Contract' => [
'className' => 'Contract',
'foreignKey' => 'company_id'
],
'User' => [
'className' => 'User',
'foreignKey' => 'company_id'
],
'Project' => [
'className' => 'Project',
'foreignKey' => 'company_id'
],
];
/**
* バーチャルフィールド
*/
public $virtualFields = [
'company_padding_id' => "lpad(CompanyOrdered.company_id, 6, '0')",
'company_factor_padding_id' => "CONCAT(lpad(CompanyOrdered.company_id, 6,
'0'), lpad('', 8, '0'))",
'name' => "CONCAT(CompanyOrdered.last_name, ' ',
CompanyOrdered.first_name)",
'name_kana' => "CONCAT(CompanyOrdered.last_name_kana, ' ',
CompanyOrdered.first_name_kana)",
'representative_name' => "CONCAT(CompanyOrdered.representative_last_name, '
', CompanyOrdered.representative_first_name)",
'representative_name_kana' =>
"CONCAT(CompanyOrdered.representative_last_name_kana, ' ',
CompanyOrdered.representative_first_name_kana)",
'address' => "CONCAT(
IFNULL(CompanyOrdered.prefecture, ''),
IFNULL(CompanyOrdered.city, ''),
IFNULL(CompanyOrdered.town, ''),
IFNULL(CompanyOrdered.street_number_choume, ''),
IFNULL(CompanyOrdered.street_number_banchi, ''),
IFNULL(CompanyOrdered.building_name, '')
)",
'shipment_address' => "CONCAT(
IFNULL(CompanyOrdered.shipment_prefecture, ''),
IFNULL(CompanyOrdered.shipment_city, ''),
IFNULL(CompanyOrdered.shipment_town, ''),
IFNULL(CompanyOrdered.shipment_street_number_choume, ''),
IFNULL(CompanyOrdered.shipment_street_number_banchi, ''),
IFNULL(CompanyOrdered.shipment_building_name, '')
)",
'plan_set' => "CONCAT(
CompanyOrdered.plan,
'_',
CompanyOrdered.plan_payment_type
)",
'total_id_count' => "id_count + add_id_count",
'remain_id_count' => "id_count + add_id_count - use_id_count",
'total_project_count' => "project_count + add_project_count",
'remain_project_count' => "project_count + add_project_count -
use_project_count",
'total_consult_count' => "consult_count + add_consult_count",
'remain_consult_count' => "consult_count + add_consult_count -
use_consult_count",
'remove_id_count' => "CASE WHEN use_id_count - id_count > 0 THEN
add_id_count + id_count - use_id_count ELSE add_id_count END",
'remove_project_count' => "CASE WHEN use_project_count - project_count > 0
THEN add_project_count + project_count - use_project_count ELSE add_project_count
END",
];
/**
* バリデーション
*/
public $validate = [
'last_name' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'first_name' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'last_name_kana' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
],
[
'rule' => 'katakanaOnly',
'message' => 'カタカナで入力してください。',
]
],
'first_name_kana' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
],
[
'rule' => 'katakanaOnly',
'message' => 'カタカナで入力してください。',
]
],
'company_name' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'zip_code' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
],
[
'rule' => ['custom', '/^[0-9]{3}[\s-]?[0-9]{4}$/'],
'allowEmpty' => true,
'message' => '有効な郵便番号を入力してください。',
]
],
'prefecture' => [
[
'rule' => 'notBlank',
'message' => '選択してください。',
]
],
'city' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'town' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'street_number_banchi' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'phone' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'company_phone' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'mail_address' => [
'notBlank' => [
'rule' => 'notBlank',
'message' => '入力してください。',
],
'isUniqueEmail' => [
'rule' => 'isUniqueEmail',
'message' => '既に使用されているメールアドレスです。',
'on' => 'update'
],
'isUniqueCreateEmail' => [
'rule' => 'isUniqueCreateEmail',
'message' => '既に使用されているメールアドレスです。',
'on' => 'create'
],
'isUniqueCreateEmailVenture' => [
'rule' => 'isUniqueCreateEmailVenture',
'message' => '既に使用されているメールアドレスです。',
'on' => 'create'
],
// 'isFreeMailAddress' => [
// 'rule' => 'isFreeMailAddress',
// 'message' => 'フリーメールアドレスはご登録いただけません。',
// ],
[
'rule' => ['email', false],
'message' => '有効なメールアドレスを入力してください。',
],
],
'stock_market' => [
[
'rule' => 'notBlank',
'message' => '選択してください。',
]
],
'industry_b_id' => [
[
'rule' => 'notBlank',
'message' => '選択してください。',
]
],
'industry_m_id' => [
[
'rule' => 'notBlank',
'message' => '選択してください。',
]
],
'cancel_desired_date' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
],
[
'rule' => 'date',
'message' => '正しい形式で入力してください。',
],
[
'rule' => 'isValid',
'message' => '本日以降〜契約期間満了日の日付で入力してください。',
]
],
'cancel_reason' => [
[
'rule' => 'notBlank',
'message' => '入力してください。',
]
],
'representative_mail_address' => [
'isValidRepresentativeMail' => [
'rule' => 'isValidRepresentativeMail',
'message' => "ご担当者と同一メールアドレスは使用できません。",
'on' => 'update'
],
// [
// 'rule' => 'isValidDomainMail',
// 'message' => 'ご担当者メールアドレスとドメインが一致しません。',
// 'on' => 'update'
// ],
],
'card_number' => [
'rule' => [
'cc', ['visa', 'maestro', 'jcb', 'amex', 'diners'], false, null
],
'message' => 'カード番号が正しくありません。'
],
'establishment_of_contract_corporation_date_year' => [
[
'rule' => 'checkEstablishmentYear',
'message' => '5 年以上の法人はお申し込みができません。',
],
[
'rule' => 'checkEstablishmentYearFuture',
'message' => '未来日は指定できません。',
],
[
'rule' => 'isValidDate',
'message' => '有効な日付を選択してください。',
]
],
'establishment_of_contract_corporation_date_month' => [
[
'rule' => 'checkEstablishmentYear',
'message' => '5 年以上の法人はお申し込みができません。',
],
[
'rule' => 'checkEstablishmentYearFuture',
'message' => '未来日は指定できません。',
],
[
'rule' => 'isValidDate',
'message' => '有効な日付を選択してください。',
]
],
'establishment_of_contract_corporation_date_day' => [
[
'rule' => 'checkEstablishmentYear',
'message' => '5 年以上の法人はお申し込みができません。',
],
[
'rule' => 'checkEstablishmentYearFuture',
'message' => '未来日は指定できません。',
],
[
'rule' => 'isValidDate',
'message' => '有効な日付を選択してください。',
]
],
'establishment_of_contract_registration_number' => [
[
'rule' => 'checkEstablishmentRegistrationNumber',
'message' => '有効な桁数ではありません。',
]
],
];
/**
* 解約希望日の確認
*
* @param array $data
* @return boolean
*/
public function isValid($check) {
if (strtotime($check['cancel_desired_date']) >= strtotime('now')
&& strtotime($this->data['CompanyOrdered']['contract_expiration_date'])
>= strtotime($check['cancel_desired_date'])
) {
return true;
}
return false;
}
/**
* 最後にログインした日時を更新
*
* @param int ユーザー ID
* @return void
*/
public function updateLoginTime($id = null) {
if (!empty($id)) {
$data = [
'company_id' => $id,
'last_login' => date('Y-m-d H:i:s')
];
$this->save($data, ['callbacks' => false]);
}
}
/**
* 英数記号のみのバリデーション
*
* @param array $check
* @return boolena
*/
public function alphanumericsymbols($check){
$value = array_values($check);
$value = $value[0];
return preg_match('/^[a-zA-Z0-9\s\x21-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]+$/',
$value);
}
/**
* 全角カタカナ以外が含まれていればエラーとするバリデーションチェック
*
* @param array &$model
* @param array $wordvalue
* @return boolean
*/
public function katakanaOnly($check) {
$value = array_shift($check);
return preg_match("/^[ァ-ヶー゛゜]*$/u", $value); // カタカナ
//return preg_match("/^[ァ-ヶー゛゜]*$/u", $value); // スペースも含むカタカナ
}
/**
* メールアドレスの確認
*
* @param array $check
* @return boolean
*/
public function isUniqueCreateEmailVenture($check) {
// CompanyOrdered テーブルの確認
$sql = "
SELECT count(company_id) as count
FROM CompanyOrdered
WHERE
mail_address = :mail_address";
$binds['mail_address'] = $check['mail_address'];
$res = $this->query($sql, $binds);
$bool = !(bool)$res[0][0]['count'];
if (!$bool) {
return false;
}
// users テーブルの確認
$this->User = new User();
$sql = "
SELECT count(company_id) as count
FROM users
WHERE
type = :type
AND
email = :email";
$binds = [];
$binds['type'] = USER_TYPE_COMPANY; // agency_id の追加に伴い type で判定するように変更
$binds['email'] = $check['mail_address'];
$res = $this->User->query($sql, $binds);
return !(bool)$res[0][0]['count'];
}
/**
* メールドメインの確認
*
* @param array $check
* @return boolean
*/
public function isUniqueCreateEmail($check) {
$this->User = new User();
return !$this->User->hasAny([
'type' => USER_TYPE_COMPANY,
'email' => $check['mail_address']
]);
// $freeMailDomains = [
// 'yahoo.co.jp',
// 'gmail.com',
// 'outlook.jp', 'outlook.com', 'hotmail.co.jp', 'hotmail.com',
'live.jp',
// 'mail.ru',
// 'zoho.com',
// 'aol.jp',
// 'excite.co.jp',
// 'inter7.jp',
// 'icloud.com',
// 'freeml.com',
// 'protonmail.com', 'mprotonmail.ch',
// 'yandex.com',
// 'xxx.biglobe.ne.jp',
// 'cs.117.cx', 'momo-mail.com',
// 'smoug.net',
// 'mail.ru', 'inbox.ru', 'list.ru', 'bk.ru',
// 'mail.goo.ne.jp',
// 'uu.tok2.com',
// 'infoseek.jp',
// 'desu.ne.jp', 'kun.ne.jp', 'chan.ne.jp', 'yan.ne.jp', 'sann.ne.jp',
// 'livedoor.com',
// 'tora.zzn.com', 'hage.zzzn.com',
// 'auone.jp',
// 'yesyes.jp',
// 'sute.jp',
// 'gmx.com',
// 'inbox.com',
// 'tutanaka.com', 'yandex.ru', 'vivaldi.net', 'mail.com', 'cook.li',
'disroot.org',
// 'me.com', 'icloud.com', 'mac.com',
// ];
// // CompanyOrdered テーブルの確認
// // $sql = "
// // SELECT count(company_id) as count
// // FROM CompanyOrdered
// // WHERE
// // mail_address = :mail_address";
// $sql = "
// SELECT count(company_id) as count
// FROM CompanyOrdered
// WHERE
// mail_address like :mail_address";
// $bool = !(bool)$res[0][0]['count'];
// if (!$bool) {
// return false;
// }
// // users テーブルの確認
// // $sql = "
// // SELECT count(company_id) as count
// // FROM users
// // WHERE
// // advisory_id = :advisory_id
// // AND
// // email = :email";
// $sql = "
// SELECT count(company_id) as count
// FROM users
// WHERE
// type = :type
// AND
// email like :email";
// $binds = [];
// $binds['type'] = USER_TYPE_COMPANY; // agency_id の追加に伴い type で判定するように変更
// // $binds['email'] = $check['mail_address'];
// $checkaddress = '%@'.explode('@', $check['mail_address'])[1].'%';
// $binds['email'] = $checkaddress;
// $res = $this->User->query($sql, $binds);
// return !(bool)$res[0][0]['count'];
}
/**
* メールアドレスの確認
*
* @param array $check
* @return boolean
*/
public function isUniqueEmail($check) {
$sql = "
SELECT count(company_id) as count
FROM CompanyOrdered
WHERE
mail_address = :mail_address AND
mail_address != (SELECT mail_address FROM CompanyOrdered WHERE
company_id = :company_id);";
$binds['mail_address'] = $check['mail_address'];
$binds['company_id'] = $this->id;
$res = $this->query($sql, $binds);
return !(bool)$res[0][0]['count'];
}
/**
* 解約チェック
*
* @param int 企業 ID
* @return int
*/
public function cancelCheck($companyId) {
// 解約日を取得
$cancelDate = $this->field('cancel_date', [
'CompanyOrdered.company_id' => $companyId
]);
// 解約していない場合 or 解約日を過ぎていない
if (empty($cancelDate) || $cancelDate > date('Y-m-d')) {
return NOT_CANCELED;
}
// 解約日過ぎていても契約中の案件がある場合は、機能を制限
$company = $this->find('first', [
'fields' => [
'company_id'
],
'contain' => [
'Contract' => [
'fields' => [
'id'
],
'conditions' => [
'Contract.status' => [
UNDER_CONTRACT
]
]
]
],
'conditions' => [
'CompanyOrdered.company_id' => $companyId
]
]);
if (count($company['Contract']) > 0) {
return CANCELED_BUT_HAS_CONTRACT;
}
return CANCELED;
}
/**
* フリーメールアドレスチェック
*
* @param array $check
* @return boolean
*/
public function isFreeMailAddress($check) {
$freeMailDomains = [
'yahoo.co.jp',
'gmail.com',
'outlook.jp', 'outlook.com', 'hotmail.co.jp', 'hotmail.com', 'live.jp',
'mail.ru',
'zoho.com',
'aol.jp',
'excite.co.jp',
'inter7.jp',
'icloud.com',
'freeml.com',
'protonmail.com', 'mprotonmail.ch',
'yandex.com',
'xxx.biglobe.ne.jp',
'cs.117.cx', 'momo-mail.com',
'smoug.net',
'mail.ru', 'inbox.ru', 'list.ru', 'bk.ru',
'mail.goo.ne.jp',
'uu.tok2.com',
'infoseek.jp',
'desu.ne.jp', 'kun.ne.jp', 'chan.ne.jp', 'yan.ne.jp', 'sann.ne.jp',
'livedoor.com',
'tora.zzn.com', 'hage.zzzn.com',
'auone.jp',
'yesyes.jp',
'sute.jp',
'gmx.com',
'inbox.com',
'tutanaka.com', 'yandex.ru', 'vivaldi.net', 'mail.com', 'cook.li',
'disroot.org',
'me.com', 'icloud.com', 'mac.com',
];
/**
* 代表者メールアドレスチェック
*
* @param array $check
* @return boolean
*/
public function isValidRepresentativeMail($check) {
if (isset($this->data['CompanyOrdered']['representative-setting'])
&& $this->data['CompanyOrdered']['representative-setting'] == 1
) {
return $this->data['CompanyOrdered']['mail_address'] !=
$check['representative_mail_address'];
} else {
return true;
}
}
/**
* メールアドレスドメインチェック
*
* @param array $check
* @return boolean
*/
public function isValidDomainMail($check) {
preg_match('/^(.*)@([^_]+)$/i', $this->data['CompanyOrdered']
['mail_address'], $matches);
$userDomain = $matches[2];
preg_match('/^(.*)@([^_]+)$/i', $check['representative_mail_address'],
$matches);
$representativeDomain = $matches[2];
/**
* ID 利用数の更新
*
* @param int $companyId
* @return void
*/
public function updateIdCount($companyId) {
if (!empty($companyId)) {
$this->User = new User();
$useIdCount = $this->User->find('count', [
'conditions' => [
'company_id' => $companyId,
'status' => true,
]
]);
$data = [
'company_id' => $companyId,
'use_id_count' => $useIdCount,
'modified' => false,
];
$this->save($data, false);
}
}
/**
* 案件公開数の更新
*
* @param int $companyId
* @return void
*/
public function updateProjectCount($companyId) {
if (!empty($companyId)) {
App::uses('Project', 'Model');
$this->Project = new Project();
$projectReleaseCount = $this->Project->find('count', [
'conditions' => [
'company_id' => $companyId,
'status' => RELEASE
],
'recursive' => -1
]);
$data = [
'company_id' => $companyId,
'use_project_count' => $projectReleaseCount,
'modified' => false,
];
$this->save($data, false);
}
}
/**
* 案件相談メール数の更新
*
* @param int $companyId
* @return bool
*/
public function updateConsultCount($companyId, $count) {
$fields = [
'use_consult_count' => 'use_consult_count ' . $count
];
$conditions = [
'CompanyOrdered.company_id' => $companyId
];
/**
* プラン別のカウントの取得
*
* @param array $company
* @return array [id_count, project_count, consult_count]
*/
public function getPlanCounts($company)
{
$results = [
'id_count' => 0,
'project_count' => 0,
'consult_count' => 0,
'advisor_tag_count' => 0,
];
if ($company['agency_flg']) {
// 代理店経由企業の場合 CompanyOptionConfig の Count で更新する
App::uses('CompanyOptionConfig', 'Model');
$this->CompanyOptionConfig = new CompanyOptionConfig();
$counts = $this->CompanyOptionConfig->find('first', [
'fields' => [
'id_count',
'project_count',
'consult_count',
],
'conditions' => [
'company_id' => $company['company_id']
],
'recursive' => -1
]);
if (isset($counts['CompanyOptionConfig'])) {
$results = $counts['CompanyOptionConfig'] + $results;
}
} else {
// common 側ではプランが変更されている可能性は考慮しない、管理側でプラン変更時に、id_count などを更新しているはず
// $company['id_count']などの設定がある場合、それを返す。
// config の値を返すケースは、企業登録後、初回ログイン時などで、$company['id_count']が設定されていないとき
// ID 発行数
if ($company['id_count'] ?? false) {
$results['id_count'] = $company['id_count'];
} else {
$results['id_count'] = Configure::read('company_plan.' .
$company['plan'] . '.id_count');
if (empty($results['id_count'])) {
$results['id_count'] = Configure::read('company_new_plan.' .
$company['plan'] . '.id_count');
}
}
// 案件公開数
if ($company['project_count'] ?? false) {
$results['project_count'] = $company['project_count'];
} else {
$results['project_count'] = Configure::read('company_plan.' .
$company['plan'] . '.project_count');
if (empty($results['project_count'])) {
$results['project_count'] = Configure::read('company_new_plan.'
. $company['plan'] . '.project_count');
}
$results['project_count'] = $results['project_count'] == '無制限' ?
9999 : $results['project_count'];
}
// 案件相談メール数
if ($company['consult_count'] ?? false) {
$results['consult_count'] = $company['consult_count'];
} else {
$results['consult_count'] = Configure::read('company_plan.' .
$company['plan'] . '.consult_count');
if (empty($results['consult_count'])) {
$results['consult_count'] = Configure::read('company_new_plan.'
. $company['plan'] . '.consult_count');
}
}
// 顧問タグ数
if ($company['advisor_tag_count'] ?? false) {
$results['advisor_tag_count'] = $company['advisor_tag_count'];
} else {
$results['advisor_tag_count'] = Configure::read('company_plan.' .
$company['plan'] . '.advisor_tag_count');
if (empty($results['advisor_tag_count'])) {
// トライアルプランの場合、顧問タグ機能を購入していなければ、0 とする
if ($company['plan'] == FREE_PLAN && !$this-
>ableDisplayAdvisorTag($company)) {
$results['advisor_tag_count'] = 0;
} else {
$results['advisor_tag_count'] =
Configure::read('company_new_plan.' . $company['plan'] . '.advisor_tag_count');
}
}
}
}
return $results;
}
/**
* ID 数・案件公開数・相談メール数更新
*
* @param array $company
* @return void
*/
public function updateCount($company)
{
$counts = $this->getPlanCounts($company);
$idCount = $counts['id_count'];
$projectCount = $counts['project_count'];
$consultCount = $counts['consult_count'];
$advisorTagCount = $counts['advisor_tag_count'];
$fields = [
'id_count' => "'" . $idCount . "'",
'project_count' => "'" . $projectCount . "'",
'consult_count' => "'" . $consultCount . "'",
'advisor_tag_count' => "'" . $advisorTagCount . "'",
];
$conditions = [
'CompanyOrdered.company_id' => $company['company_id']
];
$this->updateAll($fields, $conditions);
$this->updateIdCount($company['company_id']);
$this->updateProjectCount($company['company_id']);
}
/**
* ベンチャー登録期間チェック(5年未満)
*
* @param array $check
* @return boolean
*/
public function checkEstablishmentYear($check) {
if(!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_year']) &&
!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_month']) &&
!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_day'])) {
$checkYm = strval($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_year']).strval(sprintf('%02d', $this-
>data['CompanyOrdered']
['establishment_of_contract_corporation_date_month'])).strval(sprintf('%02d',
$this->data['CompanyOrdered']['establishment_of_contract_corporation_date_day']));
$now5MinusYm = strval((date('Y')-
5)).strval(date('m')).strval(date('d'));
// 2020/03/17 の場合 201503
// 選択日 >= 5 年前
return (int)$checkYm > (int)$now5MinusYm;
}else{
return true;
}
}
/**
* ベンチャー登録期間チェック(未来日)
*
* @param array $check
* @return boolean
*/
public function checkEstablishmentYearFuture($check) {
if(!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_year']) &&
!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_month']) &&
!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_day'])) {
$checkYm = strval($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_year']).strval(sprintf('%02d', $this-
>data['CompanyOrdered']
['establishment_of_contract_corporation_date_month'])).strval(sprintf('%02d',
$this->data['CompanyOrdered']['establishment_of_contract_corporation_date_day']));
$nowYm = strval((date('Y'))).strval(date('m')).strval(date('d'));
return (int)$nowYm >= (int)$checkYm;
}else{
return true;
}
}
/**
* ベンチャー登録番号桁チェック
*
* @param array $check
* @return boolean
*/
public function checkEstablishmentRegistrationNumber($check) {
if(!empty($this->data['CompanyOrdered']
['establishment_of_contract_registration_number'])) {
$registration_number = str_replace(array(" ", " "), "", $this-
>data['CompanyOrdered']['establishment_of_contract_registration_number']);
return strlen($registration_number) == 12 || strlen($registration_number)
== 13;
}else{
return true;
}
}
/**
* 日付チェック
*
* @param array $check
* @return boolean
*/
public function isValidDate($check) {
if(!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_year']) &&
!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_month']) &&
!empty($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_day'])) {
$yyyy = strval($this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_year']);
$mm = strval(sprintf('%02d', $this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_month']));
$dd = strval(sprintf('%02d', $this->data['CompanyOrdered']
['establishment_of_contract_corporation_date_day']));
return checkdate((int)$mm, (int)$dd, (int)$yyyy);
}else{
return true;
}
}
/**
* 本日以降日付チェック
*
* @param array $check
* @return boolean
*/
public function afterToday($check) {
$now = (new DateTime())->format('Y-m-d');
// 影響範囲を考慮してカラム指定しておく
if ($check["issue_dt_for_agency"] ?? false) {
if ((new DateTime($check["issue_dt_for_agency"]))->format('Y-m-d') <
$now) {
return false;
}
} else if ($check["application_dt_for_agency"] ?? false) {
if ((new DateTime($check["application_dt_for_agency"]))->format('Y-m-
d') < $now) {
return false;
}
} else if ($check["expected_cancellation_dt_for_agency"] ?? false) {
if ((new DateTime($check["expected_cancellation_dt_for_agency"]))-
>format('Y-m-d') < $now) {
return false;
}
}
return true;
}
/**
* 代理店企業判定
*
* @return boolean
*/
public function isAgencyCompany($company = null) {
if ($company === null) {
$company = $this->_getAuthCompany();
}
return $company && $company['agency_flg'];
}
/**
* 顧問ランキングの表示判定
*
* @return boolean
*/
public function ableDisplayAdvisorRanking($company = null) {
if ($company === null) {
$company = $this->_getAuthCompany();
}
return $company && ($company['plan'] != FREE_PLAN ||
(
$this->_withinPeriod(
$company['option_advisor_ranking_start_dt'],
$company['option_advisor_ranking_end_dt']
)
));
}
/**
* 顧問経歴の表示判定
*
* @return boolean
*/
public function ableDisplayAdvisorProfile($company = null) {
if ($company === null) {
$company = $this->_getAuthCompany();
}
return $company && ($company['plan'] != FREE_PLAN ||
(
$this->_withinPeriod(
$company['option_advisor_profile_start_dt'],
$company['option_advisor_profile_end_dt']
)
));
}
/**
* 顧問タグの表示判定
*
* @return boolean
*/
public function ableDisplayAdvisorTag($company = null) {
if ($company === null) {
$company = $this->_getAuthCompany();
}
return $company && ($company['plan'] != FREE_PLAN ||
(
$this->_withinPeriod(
$company['option_advisor_tag_start_dt'],
$company['option_advisor_tag_end_dt']
)
));
}
/**
* 顧問タグ追加オプションの表示判定
*
* @return boolean
*/
public function ableDisplayAdvisorTagOption($company = null) {
if ($company === null) {
$company = $this->_getAuthCompany();
}
return $company && ($company['plan'] != FREE_PLAN ||
(
$company['option_advisor_tag']
));
}
/**
* 日付の期間内判定
*
* @return boolean
*/
private function _withinPeriod($start_dt, $end_dt) {
$format = 'Y-m-d';
if (!empty($start_dt)) {
$start_dt = date($format, strtotime($start_dt));
}
if (!empty($end_dt)) {
$end_dt = date($format, strtotime($end_dt));
}
return (
$start_dt != null &&
$start_dt <= date($format) &&
(
$end_dt == null ||
$end_dt >= date($format)
)
);
}
/**
* ログイン企業の取得
*
* @return boolean
*/
private function _getAuthCompany() {
App::uses('AuthComponent', 'Controller/Component');
$company_id = AuthComponent::user('company_id');
return ($this->findByCompanyId($company_id)['CompanyOrdered'] ?? null);
}
/**
* 無料プラン企業として登録する
*
* @param array 企業情報
* @return array 無料プラン企業情報
*/
public function changeToFreePlan($company) {
if (isset($company['CompanyOrdered'])) {
// 階層が違った場合にずらす
$companyTmp = &$company['CompanyOrdered'];
} else {
$companyTmp = &$company;
}
if (!isset($companyTmp['company_id'])) {
// company_id が必要
return false;
}
// representative
// 'representative_last_name' => $company['last_name'],
// 'representative_first_name' => $company['first_name'],
// 'representative_last_name_kana' => $company['last_name_kana'],
// 'representative_first_name_kana' => $company['first_name_kana'],
// 'representative_mail_address' => $company['mail_address'],
// 'representative_date' => date('Y-m-d H:i:s'),
// shipment
'acting_entry_dt' => date('Y-m-d H:i:s'),
'factor_token' => sha1($companyTmp['company_id']),
'entry_status' => 1,
'shipment_company_name' => $companyTmp['company_name']??null,
'shipment_zip_code' => $companyTmp['zip_code']??null,
'shipment_prefecture' => $companyTmp['prefecture']??null,
'shipment_city' => $companyTmp['city']??null,
'shipment_town' => $companyTmp['town']??null,
'shipment_street_number_banchi' =>
$companyTmp['street_number_banchi']??null,
'shipment_building_name' => $companyTmp['building_name']??null,
'shipment_phone' => $companyTmp['company_phone']??null,
// メール+20 プレゼント
'add_consult_count' => Configure::read($configKey),
];
return $company;
}
$this->save($this->changeToFreePlan($company));
}
/**
* 保存後のコールバックメソッド
*
* @param array $created
* @param array $options
*/
public function afterSave($created, $options = [])
{
if (isset($this->data['CompanyOrdered']['cancel_flag'])) {
$isCanceled = $this->data['CompanyOrdered']['cancel_flag'] == CANCELED;
// 解約状態の場合
if ($isCanceled) {
// 企業が解約された場合、案件を掲載終了にし関連メールログを削除する
App::uses('Project', 'Model');
App::uses('PromotionEmailLog', 'Model');
$this->Project = new Project();
$this->PromotionEmailLog = new PromotionEmailLog();
// 案件の取得
$projects = $this->Project->find('all', [
'conditions' => [
'company_id' => $this->data['CompanyOrdered']['company_id']
],
'recursive' => -1
]);
if (0 < count($projects)) {
// 案件のステータスを掲載終了にする
for ($i = 0; $i < count($projects); $i++) {
$ids[] = $projects[$i]['Project']['id'];
$projects[$i]['Project']['status'] = CLOSE; // 3:掲載終了
}
// 案件票保存(促進メール情報を別途まとめて削除するため、'callbacks'=>false)
$this->Project->saveMany($projects, ['callbacks'=>false,
'validate' => false]);
// PromotionEmailLogs を削除する
$this->PromotionEmailLog->deleteAll([
'PromotionEmailLog.project_id' => $ids,
'PromotionEmailLog.status' => false, // 未送信
]);
}
}
}
}
/**
* 無料プラン用のバリデーションに変更
*/
public function changeValidationForFreePlan()
{
$validate = [];
$validate['last_name'] = $this->validate['last_name'];
$validate['first_name'] = $this->validate['first_name'];
$validate['company_name'] = $this->validate['company_name'];
$validate['phone'] = $this->validate['phone'];
$validate['mail_address'] = $this->validate['mail_address'];
$this->validate = $validate;
}
/**
* 代理店企業用のバリデーションに変更
*/
public function changeValidationForAgencyCompany()
{
$this->validate['mail_address']['isUniqueEmail']['message'] = "既に同一メールアドレスで
のご登録がございます。\n ご不明な場合は顧問バンク事務局にお問い合わせください。";
$this->validate['mail_address']['isUniqueCreateEmail']['message'] = "既に同一メー
ルアドレスでのご登録がございます。\n ご不明な場合は顧問バンク事務局にお問い合わせください。";
$this->validate['mail_address']['isUniqueCreateEmailVenture']['message'] =
"既に同一メールアドレスでのご登録がございます。\n ご不明な場合は顧問バンク事務局にお問い合わせください。";
$this->validate += [
'issue_dt_for_agency' => [
[
'rule' => array('date', 'ymd'),
'message' => '有効な日付を入力してください。',
],
[
'rule' => 'afterToday',
'message' => '本日以降の日付で入力してください。',
]
],
'application_dt_for_agency' => [
[
'rule' => array('date', 'ymd'),
'message' => '有効な日付を入力してください。',
],
[
'rule' => 'afterToday',
'message' => '本日以降の日付で入力してください。',
]
],
'expected_cancellation_dt_for_agency' => [
[
'rule' => array('date', 'ymd'),
'message' => '有効な日付を入力してください。',
],
[
'rule' => 'afterToday',
'message' => '本日以降の日付で入力してください。',
]
],
];
}
}