Esempio n. 1
0
 public function bootstrap($app)
 {
     if ($app->id == 'frontend') {
         Kiwi::registerClass(['class' => ['user' => 'yincart\\customer\\models\\Customer']]);
     }
     $this->accessControl();
 }
Esempio n. 2
0
 public function actionClearAll()
 {
     if (Kiwi::getShoppingCart()->clearAll()) {
         echo Json::encode(['message' => 'remove success', 'redirect' => 'index']);
     } else {
         echo Json::encode(['message' => 'remove fail', 'redirect' => 'index']);
     }
 }
Esempio n. 3
0
 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]);
 }
Esempio n. 4
0
 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));
 }
Esempio n. 5
0
 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());
     });
 }
Esempio n. 6
0
 /**
  * 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.');
     }
 }
Esempio n. 7
0
 /**
  * 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.');
     }
 }
Esempio n. 9
0
 public function addAdminUser()
 {
     $admins = $this->getAdmins();
     foreach ($admins as $admin) {
         /** @var \core\user\forms\SignupForm $user */
         $user = Kiwi::getSignupForm($admin);
         $user->signup();
     }
 }
Esempio n. 10
0
 /**
  * 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;
 }
Esempio n. 11
0
 public function getBlockPage($key)
 {
     $content = '';
     $block = Kiwi::getBlock()->find()->where(['key' => $key, 'status' => 1])->one();
     if ($block) {
         $content = $block->content;
     }
     return $content;
 }
Esempio n. 12
0
 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]);
 }
Esempio n. 13
0
 /**
  * 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.');
     }
 }
Esempio n. 14
0
 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']);
 }
Esempio n. 15
0
 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());
     });
 }
Esempio n. 16
0
 /**
  * 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.');
     }
 }
Esempio n. 17
0
 /**
  * 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]);
 }
Esempio n. 18
0
 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]);
 }
Esempio n. 19
0
 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]);
 }
Esempio n. 20
0
 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();
 }
Esempio n. 21
0
 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']);
 }
Esempio n. 22
0
 /**
  * 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);
 }
Esempio n. 23
0
 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']);
 }
Esempio n. 24
0
 /**
  * @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;
 }
Esempio n. 25
0
 /**
  * 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;
 }
Esempio n. 26
0
 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;
 }
Esempio n. 29
0
 /**
  * @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());
         }
     }
 }
Esempio n. 30
0
 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
 }