コード例 #1
0
ファイル: Shipping.php プロジェクト: styleyoung/taoshop
 public function uninstall($code)
 {
     $row = (new \yii\db\Query())->select(['id', 'shipping_name', 'print_bg'])->from(self::tableName())->where(['shipping_code' => $code])->limit(1)->one();
     if (!$row) {
         return true;
     }
     $shipping_id = $row['id'];
     $shipping_name = $row['shipping_name'];
     //获取配送地区id
     $rows = (new \yii\db\Query())->select(['id'])->from(ShippingArea::tableName())->where(['shipping_id' => $shipping_id])->all();
     $all = UtilD::getCol($rows);
     $in = UtilD::db_create_in(join(',', $all));
     $conn = \Yii::$app->getDb();
     $transaction = $conn->beginTransaction();
     try {
         $sql1 = "DELETE FROM " . AreaRegion::tableName() . " WHERE shipping_area_id " . $in;
         $sql2 = "DELETE FROM " . ShippingArea::tableName() . " WHERE id=" . $shipping_id;
         $sql3 = "DELETE FROM " . Shipping::tableName() . " WHERE id=" . $shipping_id;
         $conn->createCommand($sql1)->execute();
         $conn->createCommand($sql2)->execute();
         $conn->createCommand($sql3)->execute();
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         return false;
     }
     //删除上传的非默认快递单
     if ($row['print_bg'] != '' && !UtilD::is_print_bg_default($row['print_bg'])) {
         @unlink(\Yii::getAlias('@web') . DIRECTORY_SEPARATOR . $row['print_bg']);
     }
     AdminLog::admin_log(addslashes($shipping_name), 'uninstall', 'shipping');
     return true;
 }
コード例 #2
0
ファイル: WebUserD.php プロジェクト: styleyoung/taoshop
 /**
  * get user row data 
  * @return array userInfo
  */
 private function getUserInfo()
 {
     $user_id = $this->getId();
     $key = md5(self::USER_KEY . $user_id);
     $data = UtilD::getCache(__CLASS__, $key);
     if (!$data) {
         $data = Yii::$app->getDb()->createCommand("SELECT * FROM {{%admin}} WHERE id=" . $user_id . " AND status=" . Admin::STATUS_ACTIVE)->queryOne();
         if ($data) {
             UtilD::setCache(__CLASS__, $key, $data);
         }
     }
     return $data;
 }
コード例 #3
0
 /**
  * 对访问的方法进行权限验证
  */
 protected function Permission()
 {
     $route = strtolower($this->getRouteAbsolute());
     if (\Yii::$app->user->isGuest) {
         if (!in_array($route, \yii::$app->params['notNeedLogin'])) {
             //判断是否是ajax访问
             if (\Yii::$app->request->getIsAjax()) {
                 exit(UtilD::toJson(false, '未登录,无操作权限'));
             } else {
                 return $this->redirect('/admin/login');
             }
         }
     }
 }
コード例 #4
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')));
 }
コード例 #5
0
 public function actionPost()
 {
     if (!\Yii::$app->request->getIsPost()) {
         throw new yii\base\InvalidCallException("无效请求");
     }
     $model = new LoginForm();
     $model->username = $_POST['username'];
     $model->password = $_POST['password'];
     $model->rememberMe = isset($_POST['rememberMe']) && $_POST['rememberMe'] == 'on' ? true : false;
     $model->verifyCode = $_POST['verifyCode'];
     if ($model->login()) {
         exit(UtilD::handleResult(true, '登陆成功'));
     } else {
         exit(UtilD::handleResult(false, '登陆失败,账号或密码错误'));
     }
 }
コード例 #6
0
ファイル: ShippingArea.php プロジェクト: styleyoung/taoshop
 public function getShipingAreaList($shipping_id, $page = 1, $pageSize = 10)
 {
     $q = (new yii\db\Query())->select('*')->from(self::tableName());
     if ($shipping_id) {
         $q->where(['id' => $shipping_id]);
     }
     $pages = new Pagination(['totalCount' => $q->count(), 'defaultPageSize' => $pageSize]);
     $result = $q->offset($pages->offset)->limit($pages->limit)->all();
     $list = [];
     foreach ($result as $key => $row) {
         $sql = "SELECT r.area_name FROM " . AreaRegion::tableName() . " AS a, " . Area::tableName() . " AS r " . " WHERE a.region_area = r.area_code " . " AND a.shipping_area_id = {$shipping_id}";
         $regions = UtilD::getCol(\Yii::$app->getDb()->createCommand($sql)->queryAll());
         $row['shipping_area_regions'] = empty($regions) ? '<a href="' . Url::toRoute(['/shipping-area/region', 'id' => $row['shipping_area_id']]) . '" style="color:red">' . \Yii::t('shipping', 'empty_regions') . '</a>' : $regions;
         $list[] = $row;
     }
     return $list;
 }
コード例 #7
0
 public function actionDeleteLink()
 {
     $id = (int) \Yii::$app->request->get('id', 0);
     if (!$id) {
         exit(UtilD::handleResult(false, '非法提交'));
     }
     $model = FriendLink::find()->where('id=' . $id)->one();
     if (strpos($model['link_logo'], 'http://') === false && strpos($model['link_logo'], 'https://') === false) {
         $img_name = basename($model['link_logo']);
         @unlink(\Yii::getAlias('static') . '/images/afficheimg/' . $img_name);
     }
     $model->delete();
     AdminLog::admin_log('', 'remove', 'friendlink');
     exit(UtilD::handleResult(true, '删除成功'));
 }
コード例 #8
0
ファイル: Area.php プロジェクト: styleyoung/taoshop
 private function getAllArea()
 {
     $key = md5(self::CACHE_KEY . 'AllData');
     $allArea = UtilD::getCache(__CLASS__, $key);
     if (!$allArea) {
         $sql = "SELECT id,area_code,area_name,depth,full_name,pid FROM " . self::tableName() . " WHERE sta=1 AND depth<=4 ORDER BY priority ASC,sort ASC,area_code ASC";
         $result = \yii::$app->getDb()->createCommand($sql)->queryAll();
         foreach ($result as $row) {
             $allArea[$row['area_code']] = $row;
             $fullName = explode(',', $allArea[$row['area_code']]['full_name']);
             if (count($fullName)) {
                 unset($fullName[0]);
                 $allArea[$row['area_code']]['full_name'] = implode(',', $fullName);
             } else {
                 $allArea[$row['area_code']]['full_name'] = str_replace('中国', '全国', $allArea[$row['area_code']]['full_name']);
             }
         }
         UtilD::setCache(__CLASS__, $key, $allArea);
     }
     return $allArea;
 }
コード例 #9
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'));
     }
 }
コード例 #10
0
 public function actionEditPost()
 {
     $id = (int) \Yii::$app->request->post('id');
     $item_name = Html::decode(\Yii::$app->request->post('item_name'));
     $item_url = Html::decode(\Yii::$app->request->post('item_url'));
     $item_ifshow = \Yii::$app->request->post('item_ifshow');
     $item_opennew = \Yii::$app->request->post('item_opennew');
     $item_type = \Yii::$app->request->post('item_type');
     $item_vieworder = (int) \Yii::$app->request->post('item_vieworder', 0);
     $row = Nav::find()->select(['ctype', 'cid', 'is_show', 'type'])->where($id)->one();
     $arr = Nav::analyse_uri($item_url);
     if ($arr) {
         if ($row['ctype'] == $arr['type'] && $row['cid'] == $arr['id']) {
             //如果没有修改分类
             if ($item_type != 'middle') {
                 //位置不在中部
                 Nav::setShowInNav($arr['type'], $arr['id'], 0);
             }
         } else {
             //修改了分类
             if ($row['is_show'] == 1 && $row['type'] == 'middle') {
                 Nav::setShowInNav($row['ctype'], $row['cid'], 0);
                 //设置成不显示
             }
         }
         //分类判断
         if ($item_ifshow != Nav::isShowInNav($arr['type'], $arr['id']) && $item_type == 'middle') {
             Nav::setShowInNav($arr['type'], $arr['id'], $item_ifshow);
         }
         Nav::updateAll(['name' => $item_name, 'ctype' => $arr['type'], 'cid' => $arr['id'], 'is_show' => $item_ifshow, 'view_order' => $item_vieworder, 'open_new' => $item_opennew, 'url' => $item_url, 'type' => $item_type], 'id=:id', [':id' => $id]);
     } else {
         if ($row['ctype'] && $row['cid']) {
             Nav::setShowInNav($row['ctype'], $row['cid'], 0);
         }
         Nav::updateAll(['name' => $item_name, 'ctype' => '', 'cid' => '', 'is_show' => $item_ifshow, 'view_order' => $item_vieworder, 'open_new' => $item_opennew, 'url' => $item_url, 'type' => $item_type], 'id=:id', [':id' => $id]);
     }
     exit(UtilD::handleResult(true, \Yii::t('common', 'edit_ok')));
 }
コード例 #11
0
ファイル: ShopConfig.php プロジェクト: styleyoung/taoshop
 /**
  * 更新配置文件的sitemap
  * @param string $config
  */
 public static function updateConfigSitemap($config, $sm, $domain, $today)
 {
     if (!static::updateAll(['value' => serialize($config)], "code='sitemap'")) {
         return false;
     }
     $res = Category::find()->select(['id', 'cat_name'])->orderBy('parent_id')->column();
     foreach ($res as $row) {
         $smi =& new GoogleSitemapItem($domain . UtilD::build_uri('category', [$row['id']], $row['cat_name']), $today, $config['category_changefreq'], $config['category_priority']);
         $sm->add_item($smi);
     }
     $res = ArticleCat::find()->select(['id', 'cat_name'])->where(['cat_type' => 1])->column();
     foreach ($res as $row) {
         $smi =& new GoogleSitemapItem($domain . UtilD::build_uri('article_cat', ['acid' => $row['id']], $row['cat_name']), $today, $config['category_changefreq'], $config['category_priority']);
         $sm->add_item($smi);
     }
     $res = Goods::find()->select(['id', 'goods_name'])->where('is_delete=0')->column();
     foreach ($res as $row) {
         $smi =& new GoogleSitemapItem($domain . UtilD::build_uri('goods', ['gid' => $row['id']], $row['goods_name']), $today, $config['content_changefreq'], $config['content_priority']);
         $sm->add_item($smi);
     }
     //文章
     $res = Article::find()->select(['id', 'title', 'file_url', 'open_type'])->where('is_open=1')->column();
     foreach ($res as $row) {
         $article_url = $row['open_type'] != 1 ? UtilD::build_uri('article', ['aid' => $row['id']], $row['title']) : trim($row['file_url']);
         $smi =& new GoogleSitemapItem($domain . $article_url, $today, $config['content_changefreq'], $config['content_priority']);
         $sm->add_item($smi);
     }
     $sm_file = 'sitemaps.xml';
     if ($sm->build($sm_file)) {
         return true;
     } else {
     }
 }
コード例 #12
0
 public function actionPrintUpload()
 {
     $allow_suffix = ['jpg', 'png', 'jpeg'];
     $shipping_id = \yii::$app->request->post('shipping', 0);
     $src = '';
     if (!empty($_FILES['bg']['name'])) {
         if (!in_array(UtilD::getFileSuffix($_FILES['bg']['name']), $allow_suffix)) {
             UtilD::toJavaScriptAlert(sprintf(\yii::t('shipping', 'js_languages_upload_falid'), implode(',', $allow_suffix)));
             \yii::$app->end();
         }
         $name = date('Ymd');
         for ($i = 0; $i < 6; $i++) {
             $name .= chr(mt_rand(97, 122));
         }
         $name .= '.' . end(explode('.', $_FILES['bg']['name']));
         $target = \yii::getAlias('@webroot') . '/images/receipt/' . $name;
         if (move_uploaded_file($_FILES['bg']['tmp_name'], $target)) {
             $src = '/images/receipt/' . $name;
         }
     }
     if (!empty($src)) {
         $sql = "UPDATE " . Shipping::tableName() . " SET print_bg = '{$src}' WHERE id = {$shipping_id}";
         if (\Yii::$app->getDb()->createCommand($sql)->execute()) {
             echo '<script language="javascript">';
             echo 'parent.call_flash("bg_add", "' . \Yii::$app->request->getHostInfo() . $src . '");';
             echo '</script>';
         }
     }
 }
コード例 #13
0
 public function actionUninstall()
 {
     $code = \yii::$app->request->get('code');
     if (empty($code)) {
         UtilD::toJavaScriptAlert(\yii::t('app', 'invalid_parameter'), 'back');
         \yii::$app->end();
     }
     $sta = Payment::uninstall($code);
     if ($sta) {
         AdminLog::admin_log($code, 'uninstall', 'payment');
     }
     $this->redirect('/payment/list');
 }