追加悬赏
@param int $id
@return \yii\web\Response
@throws ForbiddenHttpException
@throws NotFoundHttpException
549910
public function actionAppendReward($id)
    {
        /** @var Question $model */
        $model = $this->findModel($id);
        if ($model->isAuthor()) {
            $coins = Yii::$app->request->post('coins', 0);
            //此处开始扣钱
            $transaction = Question::getDb()->beginTransaction();
            try {
                if (function_exists('credit')) {
                    credit($model->user_id, 'answer_adopted', -$coins, $model->id, $model->title);
                }

                $model->updateCounters(['price' => $coins]);
                $model->save();
                if (function_exists('doing')) {
                    doing($model->user_id, 'append_reward', get_class($model), $model->id, $model->title, "追加了 " . $coins . " 个积分");
                }
                Yii::$app->session->setFlash('success', 'question Submitted');
                $transaction->commit();
            } catch (\Exception $e) {
                $transaction->rollBack();
                Yii::$app->session->setFlash('error', 'question Submitted');
            }
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            Yii::$app->session->setFlash('danger', Yii::t('yii', 'You are not allowed to perform this action.'));
            return $this->redirect(['/question/question/view', 'id' => $model->id]);
        }
    }
868916
public function actionAssign($id)
    {
        $model = Yii::createObject([
            'class'   => Assignment::className(),
            'user_id' => $id,
        ]);

        if ($model->load(\Yii::$app->request->post()) && $model->updateAssignments()) {
        }

        return \matacms\rbac\widgets\Assignments::widget([
            'model' => $model,
        ]);
        /*$model = Yii::createObject([
            'class'   => Assignment::className(),
            'user_id' => $id,
        ]);

        if ($model->load(Yii::$app->request->post()) && $model->updateAssignments()) {

        }

        return $this->render('assign', [
            'model' => $model,
        ]);*/
    }
832940
public function actionBlock($id)
    {
        $user = $this->findModel($id);
        if ($user->getIsBlocked()) {
            $user->unblock();
            Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User has been unblocked'));
        } else {
            $user->block();
            Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User has been blocked'));
        }
        return $this->redirect(Url::previous('actions-redirect'));
    }
1151597
public function actionUpdate($id)
    {
        $request = \Yii::$app->request;
        if ($request->getIsOptions()) {
            return $this->ResponseOptions($this->verbs()['update']);
        }
        if($model = $this->findModel($id)){
            //($model->save());die();
            if ($model->load(Yii::$app->request->post())&& $model->save()) {
                //Helper::invalidate();

                return ['success'=>true];
            }else {
                throw new \yii\web\ServerErrorHttpException();
            }
        }
        throw new \yii\web\ServerErrorHttpException();
    }
339089
public function run($id = null, $contextId = null)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        if (false === Yii::$app->user->can('dotplant-structure-view')) {
            throw new ForbiddenHttpException(Yii::t(
                'yii', 'You are not allowed to perform this action.'
            ));
        }
        /** @var BaseStructure | string $class */
        if (null === $current_selected_id = Yii::$app->request->get($this->querySelectedAttribute)) {
            $current_selected_id = Yii::$app->request->get($this->queryParentAttribute);
        }
        $checked = Yii::$app->request->get('checked', '');
        $cacheKey = "AdjacencyFullTreeData:{$this->cacheKey}:{$this->querySortOrder}:{$id}:{$contextId}"
            . Yii::$app->multilingual->language_id . $this->showHiddenInTree . $checked;
        if (false === empty($checked)) {
            $checked = explode(',', $checked);
        } else {
            $checked = [];
        }
        if (false === $result = Yii::$app->cache->get($cacheKey)) {
            $contexts = call_user_func([Yii::$app->multilingual->modelsMap['Context'], 'getListData']);
            /** @var ActiveQuery $query */
            $parentId = ('#' == $id) ? null : $id;
            $query = BaseStructure::find()
                ->where(['parent_id' => $parentId])
                ->orderBy([
                    $this->contextIdAttribute => SORT_ASC,
                    $this->querySortOrder => SORT_ASC
                ]);
            if (count($this->whereCondition) > 0) {
                $query = $query->where($this->whereCondition);
            }
            if ($contextId != 'all') {
                $query->andWhere([$this->contextIdAttribute => $contextId]);
            }

            $entityId = (null !== $this->className) ? Entity::getEntityIdForClass($this->className) : null;
            if (null === $rows = $query->asArray()->all()) {
                return [];
            }
            $result = [];
            $hidden = [];
            $roots = BaseStructure::find()->select(['id'])->where(['is_deleted' => 1])->column();
            $hidden += $roots;
            foreach ($roots as $id) {
                self::treeGoDown($id, $rows, $hidden);
            }
            foreach ($rows as $row) {
                if ((int)$row['expand_in_tree'] === 1) {
                    $c = (new Query())
                        ->from(BaseStructure::tableName())
                        ->where(['parent_id' => $row['id']])
                        ->select('id')
                        ->count();
                    $children = $c > 0;
                } else {
                    $children = false;
                }
                $item = [];
                if (true === in_array($row[$this->modelIdAttribute], $hidden)) {
                    if (true === $this->showHiddenInTree) {
                        self::setState($item, ['disabled' => true]);
                    } else {
                        continue;
                    }
                }
                $text = ($row[$this->modelParentAttribute] > 0)
                    ? $row['defaultTranslation'][$this->modelLabelAttribute]
                    : ($row['defaultTranslation'][$this->modelLabelAttribute]
//                        . " ({$contexts[$row[$this->contextIdAttribute]]})"
                    );
                $item += [
                    'id' => $row[$this->modelIdAttribute],
                    'parent' => ($row[$this->modelParentAttribute] > 0) ? $row[$this->modelParentAttribute] : '#',
                    'text' => $text,
                    'children' => $children,
                    'a_attr' => [
                        'data-id' => $row[$this->modelIdAttribute],
                        'data-parent_id' => $row[$this->modelParentAttribute],
                        'data-context_id' => $row[$this->contextIdAttribute],
                        'data-entity_id' => $row['entity_id'],
                    ],
                ];
                if (null !== $entityId && $entityId != $row['entity_id']) {
                    self::setState($item, ['checkbox_disabled' => true]);
                }
                if (true === in_array($row[$this->modelIdAttribute], $checked)) {
                    self::setState($item, ['opened' => true, 'checked' => true, 'selected' => true]);
                }
                if (null !== $this->varyByTypeAttribute) {
                    $item['type'] = $row[$this->varyByTypeAttribute];
                }
                $result[$row[$this->modelIdAttribute]] = $item;
            }

            Yii::$app->cache->set(
                $cacheKey,
                $result,
                86400,
                new TagDependency([
                    'tags' => [
                        NamingHelper::getCommonTag(BaseStructure::class),
                    ],
                ])
            );
        }

        if (array_key_exists($current_selected_id, $result)) {
            $result[$current_selected_id] = array_merge(
                $result[$current_selected_id],
                ['state' => ['opened' => true, 'selected' => true]]
            );
        }

        return array_values($result);
    }
73346
public function actionView($id)
    {
        $formModel = new AddAuthItemForm();

        /* @var $am CAuthManager|AuthBehavior */
        $am = Yii::app()->getAuthManager();

        if (isset($_POST['AddAuthItemForm'])) {
            $formModel->attributes = $_POST['AddAuthItemForm'];
            if ($formModel->validate()) {
                if (!$am->isAssigned($formModel->items, $id)) {
                    $am->assign($formModel->items, $id);
                    if ($am instanceof CPhpAuthManager) {
                        $am->save();
                    }

                    if ($am instanceof ICachedAuthManager) {
                        $am->flushAccess($formModel->items, $id);
                    }
                }
            }
        }

        $model = CActiveRecord::model($this->module->userClass)->findByPk($id);

        $assignments = $am->getAuthAssignments($id);
        $authItems = $am->getItemsPermissions(array_keys($assignments));
        $authItemDp = new AuthItemDataProvider();
        $authItemDp->setAuthItems($authItems);

        $assignmentOptions = $this->getAssignmentOptions($id);
        if (!empty($assignmentOptions)) {
            $assignmentOptions = array_merge(
                array('' => Yii::t('AuthModule.main', 'Select item') . ' ...'),
                $assignmentOptions
            );
        }

        $this->render(
            'view',
            array(
                'model' => $model,
                'authItemDp' => $authItemDp,
                'formModel' => $formModel,
                'assignmentOptions' => $assignmentOptions,
            )
        );
    }
44538
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        $ruleKeyword = new ReplyRuleKeyword();
        $ruleKeywords = $model->keywords;
        if ($model->load(Yii::$app->request->post())) {
            $model->wid = $this->getWechat()->id;
            if ($this->save($model, $ruleKeyword, $ruleKeywords)) {
                return $this->flash('修改成功!', 'success', ['update', 'id' => $model->id]);
            }
        }
        return $this->render('update', [
            'model' => $model,
            'ruleKeyword' => $ruleKeyword,
            'ruleKeywords' => $ruleKeywords
        ]);
    }
393473
public function actionUpdate($id)
    {
        if (request()->post('_asnew') == '1') {
            $model = new User();
        }else{
            $model = $this->findModel($id);
        }

        if (!is_role('admin')) {
            throw new \yii\web\HttpException(403, t('app', 'You are not allowed to perform this action.'));
        }

        if ($model->loadAll(request()->post())) {
            if ($model->saveAll()) {
                set_flash_has_been_saved();
                return $this->redirect(['update', 'id' => $model->id]);
            } else {
                set_flash_has_not_been_saved();
            }
        }

        return $this->render('update', [
            'model' => $model,
        ]);
    }
537883
public function actionDisconnect($id) {
    $account = Account::find()->byId($id)->one();

    if ($account === null) {
      throw new NotFoundHttpException();
    }
    if ($account->userId != Yii::$app->user->id) {
      throw new ForbiddenHttpException();
    }

    $event = $this->getConnectEvent($account, $account->user);

    $this->trigger(self::EVENT_BEFORE_DISCONNECT, $event);
    $account->delete();
    $this->trigger(self::EVENT_AFTER_DISCONNECT, $event);

    return $this->redirect(['networks']);
  }
874202
public function delete($id) {
        if (!$this->Model->admin['deletable']) {
            throw new ForbiddenException(__d('admin', 'Delete Access Protected'));
        }

        if ($this->overrideAction('delete', $id)) {
            return;
        }

        $this->Model->id = $id;

        $result = $this->AdminToolbar->getRecordById($this->Model, $id);

        if (!$result) {
            throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName));
        }

        if ($this->request->is('post')) {
            if ($this->Model->delete($id, true)) {
                $this->AdminToolbar->logAction(ActionLog::DELETE, $this->Model, $id);

                $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully deleted %s with ID %s', array(mb_strtolower($this->Model->singularName), $id)));
                $this->AdminToolbar->redirectAfter($this->Model);

            } else {
                $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to delete %s with ID %s', array(mb_strtolower($this->Model->singularName), $id)), 'is-error');
            }
        }

        $this->set('result', $result);
        $this->overrideView('delete');
    }
1285454
public function actionCreate($id)
    {
        $model = new Item();
        $model->pid = $id;
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            Yii::$app->session->setFlash('success', Yii::t('modules/page', 'Success'));
            return $this->redirect(['update', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
1182509
public function actionUpdate($id)
    {
        if (!empty($id)) {
            $model = Currency::findOne($id);
        }
        else {
            $model = new Currency();
        }

        if (Yii::$app->request->isPost) {
            if ($model->load(Yii::$app->request->post())) {

                if ($model->validate()) {
                    $model->save();
                }
                return $this->redirect(\Yii::$app->request->referrer);
            }
            else {
                throw new Exception();
            }
        }
        return $this->render('update', [
            'model' => $model
        ]);
    }
171542
public function actionView($id)
    {
        $user = $this->findModel(Yii::$app->user->id);
        /** @var DatabaseNotification $notification */
        if (($notification = $user->getNotifications()->andWhere(['id' => $id])->one()) != null) {
            $notification->setRead();
            return $notification;
        } else {
            throw new NotFoundHttpException("Notification not found: $id");
        }
    }
582036
public function actionView($id)
    {
        $model = $this->findModel($id);
        /** @var Answer $query 回答列表 */
        $query = $model->getAnswers()->with('user');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        return $this->render('view', [
            'model' => $model,
            'dataProvider' => $dataProvider
        ]);
    }
1037543
public function actionDelete($id)
    {
        if (!\Yii::$app->user->can('delete'))
            throw new ForbiddenHttpException(Module::t('core', 'Access denied.'));

        $model = $this->findModel($id);

        // delete selected tag in all posts
        foreach(Post::find()->where(['like', 'tags', $model->name])->all() as $post) {
            $a = $model->string2array($post->tags);
            $i = array_search($model->name, $a);
            unset($a[$i]);
            $post->tags = $model->array2string($a);
            $post->save();
        }
        $model->delete();

        return $this->redirect(['index']);
    }
1272338
public function actionIndex($id)
    {
        // TODO 群发事件推送群发处理
        // TODO 模板消息事件推送处理
        // TODO 用户上报地理位置事件推送处理
        // TODO 自定义菜单事件推送处理
        // TODO 微信小店订单付款通知处理
        // TODO 微信卡卷(卡券通过审核、卡券被用户领取、卡券被用户删除)通知处理
        // TODO 智能设备接口
        // TODO 多客服转发处理
        $request = Yii::$app->request;
        $wechat = $this->findWechat($id);
        if (!$wechat->getSdk()->checkSignature()) {
            return 'Sign check fail!';
        }
        switch ($request->getMethod()) {
            case 'GET':
                if ($wechat->status == Wechat::STATUS_INACTIVE) { // 激活公众号
                    $wechat->updateAttributes(['status' => Wechat::STATUS_ACTIVE]);
                }
                return $request->get('echostr');
            case 'POST':
                $this->setWechat($wechat);
                $this->message = $this->parseRequest();
                $result = null;
                if($this->beforeProcess()) {
                    $result = $this->resolveProcess(); // 处理请求
                    $this->afterProcess($result);
                }
                return is_array($result) ? $this->createResponse($result) : $result;
            default:
                throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
756283
public function actionEdit($id = null)
    {
        if ($id === null) {
            $model = new CountryLanguage;
        } else {
            $model = $this->findModel($id);
        }
        $isLoaded = $model->load(Yii::$app->request->post());
        $hasAccess = ($model->isNewRecord && Yii::$app->user->can('multilingual-create-country-language'))
            || (!$model->isNewRecord && Yii::$app->user->can('multilingual-edit-country-language'));
        if ($isLoaded && !$hasAccess) {
            throw new ForbiddenHttpException;
        }
        if ($isLoaded && $model->save()) {
            return $this->redirect(['edit', 'id' => $model->id]);
        } else {
            return $this->render(
                'edit',
                [
                    'hasAccess' => $hasAccess,
                    'model' => $model,
                ]
            );
        }
    }