| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * Created by PhpStorm.
- * User: User
- * Date: 2019/6/19
- * Time: 下午 5:13
- */
- namespace backend\models;
- use Yii;
- /**
- * Class MailConfig 发件箱配置模型
- * @package backend\models
- */
- class MailConfig extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'crm_mail_config';
- }
- /**
- * @return \yii\db\Connection the database connection used by this AR class.
- */
- public static function getDb()
- {
- return Yii::$app->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;
- }
- }
|