Ejemplo n.º 1
0
 function find($qihao, $urlName, $codeArr, $code_id)
 {
     sort($codeArr);
     //数组从小到大排序 用户需求
     //数据分析
     $config = Configure::findOne(['type' => 1]);
     //系统报警配置
     //记录中奖与未中奖号码
     $model = Comparison::findOne(['type' => 1]);
     $data = $model->txt;
     $dataTxts = str_replace("\r\n", ' ', $data);
     //将回车转换为空格
     $dataArr = explode(' ', $dataTxts);
     $dataArr = array_filter($dataArr);
     $dataArr = array_chunk($dataArr, 5);
     //当前开奖号码 对比 数据库
     $lucky = array();
     //中奖号
     $regret = $dataArr;
     //未中奖号
     foreach ($dataArr as $key => $val) {
         sort($val);
         // 从小到大排序
         if ($codeArr == $val) {
             //中奖号组
             array_push($lucky, $val);
             unset($regret[$key]);
         }
     }
     //将中奖与未中奖的数组 转换为用户上传数据本的 格式 存入数据库
     $luckyStr = null;
     $regretStr = null;
     if (count($lucky) != 0) {
         //有中奖号码 记录数据库
         foreach ($lucky as $luc) {
             foreach ($luc as $l) {
                 $luckyStr .= $l . ' ';
             }
             $luckyStr .= "\r\n";
         }
     }
     if (count($regret) != 0) {
         //有未中奖号码 记录数据库
         foreach ($regret as $reg) {
             foreach ($reg as $r) {
                 $regretStr .= $r . ' ';
             }
             $regretStr .= "\r\n";
         }
     }
     //分析数据本与当前这期开奖号码 记录数据本里面 中奖号码与未中奖的号码 到数据库中
     $analysis = new Analysis();
     $analysis->codi_id = $code_id;
     $analysis->lucky_txt = $luckyStr;
     $analysis->regret_txt = $regretStr;
     $analysis->data_txt = $data;
     $analysis->time = time();
     $analysis->save();
     if ($config->state == 1) {
         //系统开启邮件 通知
         if (date('H', time()) > intval($config->start_time) && date('H', time()) < intval($config->end_time)) {
             //            if(true){
             //报警时间段内
             if ($config->forever == 1) {
                 //每一期 邮件通知打开
                 $cfg = array('type' => 1, 'qihao' => $qihao, 'codeArr' => $codeArr, 'urlName' => $urlName, 'luckyStr' => $luckyStr, 'regretStr' => $regretStr);
                 $this->send($cfg);
             }
             // 用户设置 几期都未中奖 报警通知
             $NewestCodes = Code::find()->orderBy('time DESC')->limit($config->regret_number)->all();
             if (count($NewestCodes) == $config->regret_number) {
                 //所有的最新的数据 必须 等于 用户设置的报警期数
                 $codeLucky = true;
                 foreach ($NewestCodes as $codeold) {
                     if (!empty($codeold->analysis->lucky_txt)) {
                         //N 期内有中奖 不发送报警
                         $codeLucky = false;
                         break;
                     }
                 }
                 if ($codeLucky) {
                     //发送报警通知 当前 $config->regret_number 内 都未中奖
                     $cfg = array('type' => 2, 'regret_number' => $config->regret_number, 'NewestCodes' => $NewestCodes);
                     $this->send($cfg);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAnalysis()
 {
     return $this->hasOne(Analysis::className(), ['codi_id' => 'id']);
 }