getList($input); return $data; } /* * 数据添加 * */ public function addList($input) { try { $list_id = $input['list_id']; $emailInfo = ListClassnev::findOne($list_id); $email = $emailInfo['day_email']; $data = json_decode($input['data'], true); $info = []; $saveInfo = []; foreach ($data as $k => $v) { $emailData['username'] = $v['name']; $emailData['phone'] = $v['phone']; $info[] = $emailData; //保存的数据 $sava['list_id'] = $list_id; $sava['name'] = $v['name']; $sava['phone'] = $v['phone']; $sava['send_email'] = $email; $sava['send_state'] = 2; $sava['create_at'] = time(); $sava['update_at'] = time(); $saveInfo[] = $sava; } $tui = (new \common\service\common\MailerService())->ordinarySend($email, ['data' => $info], 'toutiao', $emailInfo['day_title']); if ($tui) { $k = array_keys($saveInfo[0]); Yii::$app->db->createCommand()->batchInsert('pfg_day_toutiao', $k, $saveInfo)->execute(); return '发送中'; } else { foreach ($saveInfo as &$val) { $val['send_state'] = 1; } $k = array_keys($saveInfo[0]); Yii::$app->db->createCommand()->batchInsert('pfg_day_toutiao', $k, $saveInfo)->execute(); return '发送失败'; } } catch (\Exception $e) { return $e->getMessage(); } } /* * 重新单个发送 * */ public function anewSend($id) { try { $row = DayToutiao::findOne($id); if ($row['send_state'] != 1) { return '该信息已在' . date('H/m/d H:i:s', $row['update_at']) . '发送过'; } $emailInfo = ListClassnev::findOne($row['list_id']); $email = $emailInfo['day_email']; $info = [['username' => $row['name'], 'phone' => $row['phone']]]; $tui = (new \common\service\common\MailerService())->ordinarySend($email, ['data' => $info], 'toutiao', $emailInfo['day_title']); if ($tui) { $row->send_state = 2; $row->update(false); return '发送中'; } else { return '发送失败'; } } catch (\Exception $e) { return $e->getMessage(); } } public function delOne($id) { $model = DayToutiao::findOne($id); if ($model->delete()) return true; return false; } public function setWx($did) { return Yii::$app->db->createCommand()->update('pfg_day_toutiao', ['efficacious' => 2], ['id' => $did])->execute(); } public function editData($input) { $row = DayToutiao::findOne($input['id']); $row->list_id = $input['list_id']; $row->name = $input['name']; $row->phone = $input['phone']; $row->efficacious = $input['efficacious']; if(!empty($input['like']) && $input['like'] === 'yes'){ $row->send_state = 1; } if($row->update(false)){ if(!empty($input['like']) && $input['like'] === 'yes'){ return $this->anewSend($input['id']); } return '修改完成'; }else{ return false; } } }