public function bootstrap($app) { if ($app->id == 'frontend') { Kiwi::registerClass(['class' => ['user' => 'yincart\\customer\\models\\Customer']]); } $this->accessControl(); }
public function actionClearAll() { if (Kiwi::getShoppingCart()->clearAll()) { echo Json::encode(['message' => 'remove success', 'redirect' => 'index']); } else { echo Json::encode(['message' => 'remove fail', 'redirect' => 'index']); } }
public function actionList($type) { $articleQuery = Kiwi::getArticle()->find()->where(['type' => $type])->orderBy(['updated_at' => SORT_DESC]); $countQuery = clone $articleQuery; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '4']); $articleModels = $articleQuery->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('list', ['articleModels' => $articleModels, 'pages' => $pages]); }
public function actionIndex($key) { $page = Kiwi::getPage()->find()->where(['key' => $key, 'status' => 1])->one(); if (!$page) { $page = Kiwi::getPage(); } return $this->render('index', array('page' => $page)); }
public function bootstrap($app) { $customerClass = Kiwi::getCustomerClass(); Event::on($customerClass, $customerClass::EVENT_INIT, function ($event) { /** @var \yincart\customer\models\Customer $customer */ $customer = $event->sender; $customer->attachBehavior('group', Kiwi::getGroupBehaviorClass()); }); }
/** * Finds the Item model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return \yincart\item\models\Item the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $itemClass = Kiwi::getItemClass(); if (($model = $itemClass::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates a new PropValue model. * If creation is successful, the browser will be redirected to the 'view' page. * @param $itemPropId * @return mixed */ public function actionCreate($itemPropId) { $model = Kiwi::getPropValue(['item_prop_id' => $itemPropId]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['item-prop/update', 'id' => $model->item_prop_id]); } else { return $this->render('create', ['model' => $model, 'itemProp' => Kiwi::getItemProp()->findOne($itemPropId)]); } }
/** * Finds the CustomerSeller model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CustomerSeller the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $model = Kiwi::getCustomerSeller(); if (($model = $model::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function addAdminUser() { $admins = $this->getAdmins(); foreach ($admins as $admin) { /** @var \core\user\forms\SignupForm $user */ $user = Kiwi::getSignupForm($admin); $user->signup(); } }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { /** @var User $userClass */ $userClass = Kiwi::getUserClass(); $this->_user = $userClass::findByUsername($this->username); } return $this->_user; }
public function getBlockPage($key) { $content = ''; $block = Kiwi::getBlock()->find()->where(['key' => $key, 'status' => 1])->one(); if ($block) { $content = $block->content; } return $content; }
public function actionIndex() { /** @var \core\setting\models\SettingKVModel $settingKVModel */ $settingKVModel = Kiwi::getSettingKVModel(); if (\Yii::$app->getRequest()->getIsPost()) { $settingKVModel->load(\Yii::$app->getRequest()->post()); $settingKVModel->save(); } return $this->render('index', ['settingKVModel' => $settingKVModel]); }
/** * Finds the UrlRewrite model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return \core\rewrite\models\UrlRewrite the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { /** @var \core\rewrite\models\UrlRewrite $modelClass */ $modelClass = Kiwi::getUrlRewriteClass(); if (($model = $modelClass::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function safeUp() { $newTag = Kiwi::getTag(); $newTag->name = '首页标签'; /** @var $tagModel \creocoder\behaviors\NestedSet */ $tagModel = Kiwi::getTag()->find()->where(['root' => 1])->one(); $tagModel->append($newTag); $this->createTable('{{%customer_seller}}', ['customer_id' => Schema::TYPE_INTEGER . ' PRIMARY KEY ', 'money' => Schema::TYPE_DECIMAL . '(10, 2) NOT NULL', 'pin_password' => Schema::TYPE_STRING . ' NOT NULL', 'referrer' => Schema::TYPE_STRING . ' NOT NULL', 'status' => Schema::TYPE_INTEGER, 'integral' => Schema::TYPE_DECIMAL . '(10, 2)', 'reference_no' => Schema::TYPE_INTEGER, 'level' => Schema::TYPE_INTEGER . ' NOT NULL']); $this->createTable('{{%seller_money_log}}', ['seller_money_log_id' => Schema::TYPE_INTEGER, 'money' => Schema::TYPE_DECIMAL . '(10, 2) NOT NULL', 'type' => Schema::TYPE_STRING . ' NOT NULL', 'info' => Schema::TYPE_STRING . ' NOT NULL', 'created_at' => Schema::TYPE_STRING . ' NOT NULL']); }
public function attachEvents() { $itemClass = Kiwi::getItemClass(); Event::on($itemClass, $itemClass::EVENT_INIT, function ($event) { /** @var \yincart\item\models\Item $item */ $item = $event->sender; $item->attachBehavior('category', Kiwi::getCategoryBehaviorClass()); $item->attachBehavior('tag', Kiwi::getTagBehaviorClass()); }); }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { /** @var \core\auth\models\Admin $userClass */ $userClass = Kiwi::getAdminClass(); if (($model = $userClass::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Updates an existing Role model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $authManager = Yii::$app->getAuthManager(); $role = $authManager->getRole($id); $model = Kiwi::getRoleModel(['role' => $role]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } return $this->render('/role/update', ['model' => $model]); }
public function actionIntegral() { $dataProvider = new ActiveDataProvider(['query' => Kiwi::getDealLog()->find()->innerJoinWith('customerSales')->where(['customer_sales.user_id' => \Yii::$app->user->id])]); /** @var \yincart\customer\models\Customer $customer */ $customer = \Yii::$app->user->identity; $customerSellers = Kiwi::getCustomerSeller()->find()->where(['referrer' => $customer->username])->all(); $sellerIds = ArrayHelper::getColumn($customerSellers, 'customer_id'); $referrerProvider = new ActiveDataProvider(['query' => Kiwi::getDealLog()->find()->innerJoinWith('customerSales')->where(['customer_sales.user_id' => $sellerIds])]); return $this->render('integral', ['dataProvider' => $dataProvider, 'referrerProvider' => $referrerProvider]); }
public function actionList() { $name = htmlspecialchars(Yii::$app->request->get('name')); $treeModel = $this->treeModel()->find()->where(['name' => $name])->one(); $itmTreeQuery = Kiwi::getItemTree()->find()->where(['tree_id' => $treeModel->id]); $countQuery = clone $itmTreeQuery; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '6']); $itmTreeModels = $itmTreeQuery->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('list', ['itmTreeModels' => $itmTreeModels, 'pages' => $pages]); }
public static function getSalesOrderBy($categoryId = '') { $where = ''; if ($categoryId) { $items = Kiwi::getItemCategory()->find()->where(['tree_id' => $categoryId])->all(); $itemIds = ArrayHelper::getColumn($items, 'item_id'); $where = ' where item_id in (' . implode(',', $itemIds) . ') '; } $sql = 'SELECT name, count(item_id) as count FROM `order_item` ' . $where . ' group by item_id order by count desc'; return Yii::$app->db->createCommand($sql)->queryAll(); }
public function attacheEvents() { $customerClass = Kiwi::getCustomerClass(); Event::on($customerClass, $customerClass::EVENT_INIT, function ($event) { /** @var \yincart\customer\models\Customer $customer */ $customer = $event->sender; $customer->attachBehavior('category', Kiwi::getCustomerBehaviorClass()); }); $orderClass = Kiwi::getOrderClass(); Event::on($orderClass, $orderClass::EVENT_AFTER_INSERT, [Kiwi::getCustomerSellerClass(), 'updateSeller']); }
/** * Creates a form model given a token. * * @param string $token * @param array $config name-value pairs that will be used to initialize the object properties * @throws \yii\base\InvalidParamException if token is empty or not valid */ public function __construct($token, $config = []) { $userClass = Kiwi::getUserClass(); if (empty($token) || !is_string($token)) { throw new InvalidParamException('Password reset token cannot be blank.'); } $this->_user = $userClass::findByPasswordResetToken($token); if (!$this->_user) { throw new InvalidParamException('Wrong password reset token.'); } parent::__construct($config); }
public function bootstrap($app) { $views = $this->getViews(); /** @var \core\theme\models\Theme $theme */ $themes = Kiwi::getTheme()->find()->where(['is_active' => 1, 'scope' => \Yii::$app->id])->orderBy('sort')->all(); foreach ($themes as $theme) { if (isset($views[$theme->key])) { $this->loadViewPathMap($views[$theme->key]); } } $this->loadViewPathMap($views['default']); }
/** * @inheritdoc */ public function attributeLabels() { if (!$this->user) { $this->user = Kiwi::getAdmin(); $this->user->generateAuthKey(); } if (!$this->_attributeLabels) { $this->_attributeLabels = ['roles' => '角色', 'password' => '密码']; $this->_attributeLabels = ArrayHelper::merge($this->user->attributeLabels(), $this->_attributeLabels); } return $this->_attributeLabels; }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = Kiwi::getUser(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->save(); return $user; } return null; }
public function actionRequestPasswordReset() { /** @var \core\user\forms\PasswordResetRequestForm $model */ $model = Kiwi::getPasswordResetRequestForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail()) { Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.'); return $this->goHome(); } else { Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); } } return $this->render('requestPasswordResetToken', ['model' => $model]); }
/** * user center customerSales index * @author Cangzhou.Wu(wucangzhou@gmail.com) * @return string|\yii\web\Response */ public function actionIndex() { //make a request for bing a seller $model = Kiwi::getCustomerSeller()->find()->where(['customer_id' => Yii::$app->user->id])->one() ?: Kiwi::getCustomerSeller(); if (!$model->isNewRecord && $model->status == 1) { // show CustomerSales data $dataProvider = new ActiveDataProvider(['query' => Kiwi::getCustomerSales()->find()->where(['user_id' => Yii::$app->user->id])]); return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]); } if ($model->load(Yii::$app->request->post()) && $model->save()) { // return $this->redirect(['index']); } return $this->render('form', ['model' => $model]); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { $userClass = Kiwi::getUserClass(); /* @var $user User */ $user = $userClass::findOne(['status' => $userClass::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!$userClass::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * @param \yii\base\ModelEvent $event * @throws \yii\db\Exception */ public function addDealLog($event) { /** @var \yincart\order\models\Order $order */ $order = $event->sender; foreach ($order->orderItems as $orderItem) { $deal_log = Kiwi::getDealLog(); $deal_log->user_id = $order->user_id; $deal_log->order_id = $order->order_id; $deal_log->item_id = $orderItem->item_id; $deal_log->sale_price = $orderItem->price; $deal_log->memo = $orderItem->name; $deal_log->key = $orderItem->data['key']; $deal_log->deal_time = $order->create_at; $deal_log->percent = 0.35 + 0.05 * ($deal_log->customerSales->customer->customerSeller->level - 1); $deal_log->created_at = time(); if (!$deal_log->save()) { throw new Exception(\Yii::t('app', 'add deal log fail'), $deal_log->getErrors()); } } }
public function parseRequest($manager, $request) { $pathInfo = $request->getPathInfo(); $suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix); if ($suffix !== '' && $pathInfo !== '') { $n = strlen($suffix); if (substr_compare($pathInfo, $suffix, -$n, $n) === 0) { $pathInfo = substr($pathInfo, 0, -$n); if ($pathInfo === '') { return false; } } else { return false; } } /** @var \core\rewrite\models\UrlRewrite $urlRewriteClass */ $urlRewriteClass = Kiwi::getUrlRewriteClass(); $urlRewrite = $urlRewriteClass::findOne(['request_path' => $pathInfo]); if ($urlRewrite) { return [$urlRewrite->route, $urlRewrite->getParamsArray($urlRewrite->params)]; } return false; // this rule does not apply }