Ejemplo n.º 1
0
 /**
  * Finds the ShopConfig model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ShopConfig the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ShopConfig::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 2
0
 public function actionSavePost()
 {
     $today = date('Y-m-d');
     $domain = UtilD::getSiteDomain();
     $sm =& new GoogleSitemap();
     $smi =& new GoogleSitemapItem($domain, $today, $_POST['homepage_changefreq'], $_POST['homepage_priority']);
     $sm->add_item($smi);
     $config = ['homepage_changefreq' => $_POST['homepage_changefreq'], 'homepage_priority' => $_POST['homepage_priority'], 'category_changefreq' => $_POST['category_changefreq'], 'category_priority' => $_POST['category_priority'], 'content_changefreq' => $_POST['content_changefreq'], 'content_priority' => $_POST['content_priority']];
     $status = ShopConfig::updateConfigSitemap($config, $sm, $domain, $today);
     if (!$status) {
         exit(UtilD::handleResult(false, \Yii::t('common', 'attradd_error')));
     }
     exit(UtilD::handleResult(true, \Yii::t('common', 'attradd_succed')));
 }
Ejemplo n.º 3
0
 public function actionPost()
 {
     $allow_file_types = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'swf'];
     $values = \yii::$app->request->post('value', []);
     $type = \Yii::$app->request->post('type', '');
     /* 保存变量值 */
     $count = count($values);
     $arr = [];
     $sql = "SELECT id,value FROM " . ShopConfig::tableName();
     $res = \yii::$app->db->createCommand($sql)->queryAll();
     foreach ($res as $row) {
         $arr[$row['id']] = $row['value'];
     }
     foreach ($_POST['value'] as $key => $val) {
         //值更改则更新
         if ($arr[$key] != $val) {
             $sql = "UPDATE " . ShopConfig::tableName() . " SET value='" . trim($val) . "' WHERE id=" . $key;
             $rs = \yii::$app->db->createCommand($sql)->execute();
         }
     }
     /* 处理上传文件 */
     $file_var_list = [];
     $sql = "SELECT * FROM " . ShopConfig::tableName() . " WHERE parent_id > 0 AND type='file'";
     $res = \yii::$app->db->createCommand($sql)->queryAll();
     foreach ($res as $row) {
         $file_var_list[$row['code']] = $row;
     }
     foreach ($_FILES as $code => $file) {
         /* 判断用户是否选择了文件 */
         if (isset($file['error']) && $file['error'] == 0 || !isset($file['error']) && $file['tmp_name'] != 'none') {
             //检查上传的文件类型是否合法
             if (!UtilD::check_file_type($file['tmp_name'], $file['name'], $allow_file_types)) {
                 UtilD::toJavaScriptAlert('', 'back');
                 \yii::$app->end();
             } else {
                 $file_path = \yii::getAlias('@static') . DIRECTORY_SEPARATOR . $file_var_list[$code]['store_dir'];
                 //取得文件路径
                 if ($code == 'shop_logo') {
                     $ext = array_pop(explode('.', $file['name']));
                     $file_name = 'logo.' . $ext;
                 } elseif ($code == 'watermark') {
                     $ext = array_pop(explode('.', $file['name']));
                     $file_name = 'watermark.' . $ext;
                     if (file_exists($file_var_list[$code]['value'])) {
                         @unlink($file_var_list[$code]['value']);
                     }
                 } elseif ($code == 'wap_logo') {
                     $ext = array_pop(explode('.', $file['name']));
                     $file_name = 'wap_logo.' . $ext;
                     if (file_exists($file_var_list[$code]['value'])) {
                         @unlink($file_var_list[$code]['value']);
                     }
                 } else {
                     $file_name = $file['name'];
                 }
                 /* 判断是否上传成功 */
                 if (move_uploaded_file($file['tmp_name'], $file_path . $file_name)) {
                     $sql = "UPDATE " . ShopConfig::tableName() . " SET value='" . $file_name . "' WHERE code='" . $code . "'";
                     $rs = \yii::$app->db->createCommand($sql)->execute();
                 }
             }
         }
     }
     /* 处理发票类型及税率 */
     if (!empty($_POST['invoice_rate'])) {
         foreach ($_POST['invoice_rate'] as $key => $rate) {
             $rate = round(floatval($rate), 2);
             if ($rate < 0) {
                 $rate = 0;
             }
             $_POST['invoice_rate'][$key] = $rate;
         }
         $invoice = ['type' => $_POST['invoice_type'], 'rate' => $_POST['invoice_rate']];
         $sql = "UPDATE " . ShopConfig::tableName() . " SET value='" . serialize($invoice) . "' WHERE code ='invoice_type'";
         \yii::$app->db->createCommand($sql)->execute();
     }
     AdminLog::admin_log('', 'edit', 'shop_config');
     /* 清除缓存 */
     ShopConfig::clearCache();
     if ($type == 'mail_setting') {
         return $this->redirect(Url::to('/config/mail-settings'));
     } else {
         return $this->redirect(\yii\helpers\Url::to('/config/listedit'));
     }
 }