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; }
/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = AdminLog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'level' => $this->level, 'log_time' => $this->log_time, 'message' => $this->message]); $query->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'prefix', $this->prefix]); return $dataProvider; }
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, '删除成功')); }
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')); } }
public function actionUserLog() { $searchModel = new UserLogSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if (strcasecmp(Yii::$app->request->method, 'delete') == 0) { AdminLog::deleteAll($dataProvider->query->where); return $this->refresh(); } $dataProvider->sort = ['defaultOrder' => ['log_time' => SORT_DESC]]; return $this->render('user-log', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }
public function actionDoEditPrintTemplate() { $print_model = \yii::$app->request->post('print_model', 0); $shipping_id = \Yii::$app->request->post('shipping', 0); $config_lable = \Yii::$app->request->post('config_lable'); $shipping_print = \Yii::$app->request->post('shipping_print', ''); if ($print_model == 2) { //所见所得模式 $sql = "UPDATE " . Shipping::tableName() . " SET config_lable='{$config_lable}',print_model='{$print_model}' WHERE id={$shipping_id}"; \yii::$app->getDb()->createCommand($sql)->execute(); } elseif ($print_model == 1) { //代码模式 $template = $shipping_print; $sql = "UPDATE " . Shipping::tableName() . " SET shipping_print='{$template}',print_model='{$print_model}' WHERE id={$shipping_id}"; \Yii::$app->getDb()->createCommand($sql)->execute(); } AdminLog::admin_log(addslashes($_POST['shipping_name']), 'edit', 'shipping'); $this->redirect('/shipping/list'); }
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'); }