Просмотр исходного кода

后台,广告管理,增加隐藏1858

theo 3 лет назад
Родитель
Сommit
39d959d763

+ 2 - 0
backendApi/config/urlManagerRules.php

@@ -514,6 +514,8 @@ return [
             'GET,POST add' => 'add',
             'GET,POST edit/<id>' => 'edit',
             'GET,POST ad-delete' => 'ad-delete',
+            'GET,POST ad-hide' => 'ad-hide',
+            'GET,POST ad-un-hide' => 'ad-un-hide',
             'GET location' => 'location',
             'GET sort' => 'sort',
             'GET status' => 'status',

+ 27 - 0
backendApi/modules/v1/controllers/AdController.php

@@ -126,6 +126,33 @@ class AdController extends BaseController
         return $result;
     }
 
+    /**
+     * 隐藏
+     * @return mixed
+     * @throws \yii\db\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionAdHide(){
+        $adForm = new AdForm();
+        $result = static::hide(Ad::class, 'hide', function ($selected) use ($adForm) {
+        }, function ($selected) use ($adForm) {
+        }, true);
+        return $result;
+    }
+
+    /**
+     * 取消隐藏
+     * @return mixed
+     * @throws \yii\db\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionAdUnHide(){
+        $adForm = new AdForm();
+        $result = static::hide(Ad::class, 'un-hide', function ($selected) use ($adForm) {
+        }, function ($selected) use ($adForm) {
+        }, true);
+        return $result;
+    }
     /**
      * 排序
      * @return mixed

+ 39 - 0
backendApi/modules/v1/controllers/BaseController.php

@@ -126,6 +126,45 @@ class BaseController extends \yii\rest\ActiveController {
         }
     }
 
+    /**
+     * 隐藏方法
+     *
+     */
+    public static function hide($modelClass, $statusTo, callable $beforeFun = null, callable $afterFun = null) {
+        $selected = \Yii::$app->request->get('selected');
+        if (!$selected) {
+            $selected = \Yii::$app->request->post('selected');
+        }
+        if (!$selected) {
+            return self::notice('must select one item to hide', 500); // 必须选择一条删除数据
+        }
+        if (is_array($selected)) {
+            $condition = ['AND', ['IN', 'ID', $selected]];
+            $params = [];
+        } else {
+            $condition = 'ID=:ID';
+            $params = [':ID' => $selected];
+        }
+        $transaction = \Yii::$app->db->beginTransaction();
+        try {
+            if (!is_array($selected)) {
+                $selected = [$selected];
+            }
+            if ($beforeFun) $beforeFun($selected);
+            if ($statusTo == 'hide') {
+                $modelClass::updateAll(['STATUS' => 0], $condition, $params);
+            } else {
+                $modelClass::updateAll(['STATUS' => 1], $condition, $params);
+            }
+            if ($afterFun) $afterFun($selected);
+            $transaction->commit();
+            return self::notice('hide successfully');//删除成功
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            return self::notice($e->getMessage(), 500);
+        }
+    }
+
     /**
      * 删除方法
      * @param $modelClass

+ 78 - 0
backendEle/src/views/ad/list.vue

@@ -70,6 +70,12 @@
             {{tool.formatDate(scope.row.UPDATED_AT)}}
           </template>
         </el-table-column>
+        <el-table-column label="Status"> <!-- 状态 -->
+          <template slot-scope="scope">
+            <div v-if="scope.row.STATUS === '1'">Show</div>
+            <div v-else>Hide</div>
+          </template>
+        </el-table-column>
         <el-table-column fixed="right" label="Action" width="180"> <!-- 操作 -->
           <template slot-scope="scope">
             <el-dropdown size="small" trigger="click" v-if="permission.hasPermission(`ad/ad-delete`) || permission.hasPermission(`ad/edit`)">
@@ -79,6 +85,8 @@
               <el-dropdown-menu slot="dropdown">
                 <el-dropdown-item command="edit" @click.native="handleEdit(scope.row)" v-if="permission.hasPermission(`ad/edit`)">Edit</el-dropdown-item>
                 <el-dropdown-item command="delete" @click.native="handleDelete(scope.row)" v-if="permission.hasPermission(`ad/ad-delete`)">Delete</el-dropdown-item>
+                <el-dropdown-item command="hide" @click.native="handleHide(scope.row)" v-if="permission.hasPermission(`ad/ad-hide`)">Hide</el-dropdown-item>
+                <el-dropdown-item command="un-hide" @click.native="handleUnHide(scope.row)" v-if="permission.hasPermission(`ad/ad-un-hide`)">UnHide</el-dropdown-item>
               </el-dropdown-menu>
             </el-dropdown>
           </template>
@@ -91,6 +99,8 @@
           </el-button>
           <el-dropdown-menu slot="dropdown">
             <el-dropdown-item command="delete" @click.native="handleMuliDel()">Delete</el-dropdown-item>
+            <el-dropdown-item command="hide" @click.native="handleMultiHide()">Hide</el-dropdown-item>
+            <el-dropdown-item command="un-hide" @click.native="handleMultiUnHide()">UnHide</el-dropdown-item>
           </el-dropdown-menu>
         </el-dropdown>
         <el-button type="primary" size="small" @click="handleAdd" icon="el-icon-plus" v-if="permission.hasPermission(`ad/add`)">Add Ad</el-button>
@@ -153,9 +163,21 @@ export default {
     handleDelete (row) {
       this.delData(row.ID)
     },
+    handleHide (row) {
+      this.hideData(row.ID)
+    },
+    handleUnHide(row) {
+      this.unHideData(row.ID)
+    },
     handleMuliDel () {
       this.delData()
     },
+    handleMultiHide () {
+      this.hideData()
+    },
+    handleMultiUnHide () {
+      this.unHideData()
+    },
     handleChangeSort (row, sort) {
       network.getData('/ad/sort', {id: row.ID, sort: sort}).then(response => {
         this.getData(this.currentPage, this.pageSize)
@@ -198,6 +220,62 @@ export default {
 
       })
     },
+    hideData (id = null) {
+      let obj = this
+      obj.$confirm('Are you sure to hide the selected data?', 'Notice', { // 确定删除选定的数据?
+        confirmButtonText: 'confirm', // 确定
+        cancelButtonText: 'cancel', // 取消
+        type: 'warning'
+      }).then(() => {
+        let selectedIds = []
+        if (id === null) {
+          for (let val of obj.multipleSelection) {
+            selectedIds.push(val.ID)
+          }
+        } else {
+          selectedIds.push(id)
+        }
+        return network.postData(`ad/ad-hide`, {
+          selected: selectedIds
+        })
+      }).then(response => {
+        this.$message({
+          message: response,
+          type: 'success'
+        })
+        obj.getData(obj.currentPage, obj.pageSize)
+      }).catch(response => {
+
+      })
+    },
+    unHideData (id = null) {
+      let obj = this
+      obj.$confirm('Are you sure to un-hide the selected data?', 'Notice', { // 确定删除选定的数据?
+        confirmButtonText: 'confirm', // 确定
+        cancelButtonText: 'cancel', // 取消
+        type: 'warning'
+      }).then(() => {
+        let selectedIds = []
+        if (id === null) {
+          for (let val of obj.multipleSelection) {
+            selectedIds.push(val.ID)
+          }
+        } else {
+          selectedIds.push(id)
+        }
+        return network.postData(`ad/ad-un-hide`, {
+          selected: selectedIds
+        })
+      }).then(response => {
+        this.$message({
+          message: response,
+          type: 'success'
+        })
+        obj.getData(obj.currentPage, obj.pageSize)
+      }).catch(response => {
+
+      })
+    },
     getImage(imageUrl) {
       return imageUrl.indexOf('http') > -1 ? imageUrl : SERVER_API_HTTP_TYPE + SERVER_API_DOMAIN + '/uploads/' + imageUrl;
     },