get('dbXcrm'); } /** * @inheritdoc */ public function rules() { return [ [['smtp_username', 'host', 'password','port','add_time'], 'required'], [['is_check','is_enable'], 'number'], [['send_mail'], 'string'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => '主键ID', 'send_mail' => '发件人名称', 'smtp_username' => 'smtp用户名', 'host' => 'smtp服务域名', 'port' => '端口', 'add_time' => '添加时间', 'is_enable' => '是否启用', 'is_check' => '选中优先级', ]; } /** * @param $subject string 邮箱发送标题 * @param string $receiver string 收件人 * @return \yii\db\ActiveRecord */ public function getMailConfig($receiver='') { $time = time() - 300;//排除5分钟内给同一个客户发送邮件失败的发件箱配置 $sql = "select distinct mail_num from crm_mail_record where status = 0 and receiver = '$receiver' and in_time > $time"; $mail_arr = MailRecord::findBySql($sql)->asArray()->all(); $mail_nums = implode(',',array_column($mail_arr,'mail_num')); if(empty($mail_nums)){ $sql = "select * from crm_mail_config where is_enable = 0 order by is_check desc limit 1"; }else{ $sql = "select * from crm_mail_config where is_enable = 0 and id not in ($mail_nums) order by is_check desc limit 1"; } $config_arr = MailConfig::findBySql($sql)->asArray()->all()[0]; return $config_arr; } }