public function actionSetMsg()
 {
     $data = Yii::$app->request->post();
     $phone = User::findOne(['phone' => $data['phone']]);
     $info = CollectInteract::findOne(['userid' => $phone['id'], 'msg' => $data['msg']]);
     if ($info) {
         echo json_encode(array('flag' => 0, 'msg' => 'Already collect!'));
         return;
     }
     $to = Message::findOne(['id' => $data['msg']]);
     $model2 = new Notify();
     $model2->from = $phone['id'];
     $model2->to = $to['userid'];
     $model2->message = '收藏';
     $model2->created_at = time();
     if (!$model2->save()) {
         echo json_encode(array('flag' => 0, 'msg' => 'Collect fail!'));
         return;
     }
     $model = new CollectInteract();
     $model->userid = $phone['id'];
     $model->msg = $data['msg'];
     $model->created_at = time();
     if ($model->save()) {
         echo json_encode(array('flag' => 1, 'msg' => 'Collect success!'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'Collect fail!'));
     }
 }
Esempio n. 2
0
<?php

ignore_user_abort(true);
set_time_limit(90);
$id = isset($_GET['id']) ? $_GET['id'] : null;
$state = isset($_GET['state']) ? $_GET['state'] : null;
$notify = new Notify($id);
if (!$notify->hasAccess()) {
    Ajax::outputError('You don\'t have access to this notification');
}
if (!($json = $notify->getJSONContent())) {
    Ajax::output('Could not generate default json params!');
}
//doar pe ON se mai poate pune
$params = json_decode($json, true);
$params['configs']['state'] = 'ON';
if (!$notify->updateJSON_Data($params)) {
    Ajax::outputError('Could not update json params.');
}
//doar pe ON se mai poate pune
$notify->id = $id;
$notify->state = $state == 'ON';
$notify->save();