123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/11
- * Time: 下午3:08
- */
- namespace backend\server;
- use yii\base\Component;
- use common\models\DayToutiao;
- use common\enums\EmailEnum;
- use common\models\ListClassnev;
- use Yii;
- use yii\db\Exception;
- class Daytoutiaoserver extends Component
- {
- /*
- * 获取头条报名列表
- * */
- public function getList($input)
- {
- $model = new DayToutiao();
- $data = $model->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;
- }
- }
- }
|