Quellcode durchsuchen

feat: 增加免费版选项

zhangweicheng vor 2 Jahren
Ursprung
Commit
a57911792b

+ 3 - 1
modules/all_models/compilation.js

@@ -77,6 +77,8 @@ let modelSchema = {
     categoryID: {
         type: Number,
         default: 12 // 总部id
-    }
+    },
+    defaultLocation:String,//默认工程所在地
+    freeUse:Boolean
 };
 mongoose.model(collectionName, new Schema(modelSchema, { versionKey: false, collection: collectionName }));

+ 6 - 0
modules/common/const/locationList.js

@@ -0,0 +1,6 @@
+const locationList = ['北京','天津','河北','山西','内蒙古','辽宁',
+'吉林','黑龙江','上海','江苏','浙江','安徽','福建','江西','山东','河南',
+'湖北','湖南','四川','贵州','云南','西藏','陕西','甘肃','青海','宁夏','新疆',
+'广东','广西','海南','重庆']
+
+export default locationList

+ 51 - 0
modules/users/controllers/compilation_controller.js

@@ -31,6 +31,8 @@ import economicFacade from "../../economic_lib/facade/economic_facade";
 import overHeightFacade from "../../over_height_lib/facade/over_height_facade";
 import progressiveFacade from "../../progressive_interval_lib/facade/progressive_facade";
 import {default as category, List as categoryList} from "../../common/const/category_const.js";
+import locationList from  "../../common/const/locationList";
+
 let config = require("../../../config/config.js");
 const fs = require('fs');
 let _ = require('lodash');
@@ -76,6 +78,7 @@ class CompilationController extends BaseController {
             id: id,
             compilationList: compilationList,
             categoryList: categoryList,
+            locationList:locationList,
             selectedCompilation: selectedCompilation,
             layout: 'users/views/layout/layout',
             LicenseKey:config.getLicenseKey(process.env.NODE_ENV)
@@ -801,6 +804,54 @@ class CompilationController extends BaseController {
         }
     }
 
+
+     /**
+     * 更改编办默认工程所在工
+     *
+     * @param request
+     * @param response
+     * @return {Promise.<void>}
+     */
+      async changeLocation(request, response) {
+        let compilationId = request.body.id;
+        let location = request.body.location;
+        try {
+            let compilationModel = new CompilationModel();
+            let result = await compilationModel.updateLocation(compilationId, location);
+            if (result) {
+                response.json({error: 0, message: '', data: null});
+            } else {
+                response.json({error: 1, message: '更新数据错误', data: null});
+            }
+        } catch(error) {
+            response.json({error: 1, message: '更新数据错误', data: null});
+        }
+    }
+
+
+     /**
+     * 更改编办默认工程所在工
+     *
+     * @param request
+     * @param response
+     * @return {Promise.<void>}
+     */
+      async changeFreeUse(request, response) {
+        let compilationId = request.body.id;
+        let freeUse = request.body.freeUse;
+        try {
+            let compilationModel = new CompilationModel();
+            let result = await compilationModel.updateFreeUse(compilationId, freeUse);
+            if (result) {
+                response.json({error: 0, message: '', data: null});
+            } else {
+                response.json({error: 1, message: '更新数据错误', data: null});
+            }
+        } catch(error) {
+            response.json({error: 1, message: '更新数据错误', data: null});
+        }
+    }
+
 }
 
 export default CompilationController;

+ 25 - 2
modules/users/models/compilation_model.js

@@ -38,7 +38,7 @@ class CompilationModel extends BaseModel {
      */
     async getCompilationList(fields = null) {
         // 筛选字段
-        let field = fields == null ?{_id: 1, name: 1, is_release: 1, release_time:1,categoryID: 1, description: 1,overWriteUrl: 1,example: 1,edition: 1, "ration_valuation.id": 1, "ration_valuation.name": 1, "ration_valuation.enable": 1,
+        let field = fields == null ?{_id: 1, name: 1, is_release: 1, release_time:1,categoryID: 1, defaultLocation:1,description: 1,overWriteUrl: 1,example: 1,edition: 1,freeUse:1, "ration_valuation.id": 1, "ration_valuation.name": 1, "ration_valuation.enable": 1,
             "bill_valuation.id": 1, "bill_valuation.name": 1, "bill_valuation.enable": 1, "bill_valuation.fileTypes": 1}:fields;
         let compilationData = await this.findDataByCondition({name: {$ne: ''}}, field, false);
 
@@ -149,7 +149,7 @@ class CompilationModel extends BaseModel {
     * */
    async setEdition(compilationId, edition){
     return await this.updateById(compilationId, {edition: edition});
-}
+   }
     /*
         设置代码覆盖路径
      */
@@ -463,6 +463,29 @@ class CompilationModel extends BaseModel {
         return await this.updateById(compilationId, {categoryID: category});
     }
 
+    /*
+        * 设置工程默认所在地
+        *
+        * @param {String} compilationId
+        * @param {int} location
+        * @return {Promise}
+        * */
+    async updateLocation(compilationId, location) {
+        return await this.updateById(compilationId, {defaultLocation: location});
+    }
+
+    /*
+    * 设置是否提供免费版
+    *
+    * @param {String} compilationId
+    * @param {int} location
+    * @return {Promise}
+    * */
+    async updateFreeUse(compilationId, freeUse) {
+        return await this.updateById(compilationId, {freeUse: freeUse});
+    }
+
+
     // 拷贝计价规则
     async copyValuation(compilationID, valuationType, orgValuationID, newName) {
         const objectId = mongoose.Types.ObjectId(compilationID);

+ 2 - 1
modules/users/routes/compilation_route.js

@@ -37,6 +37,7 @@ module.exports = function (app) {
     router.post('/copyValuation', compilationController.auth, compilationController.init, compilationController.copyValuation);
 
     router.post('/changeCategory', compilationController.auth, compilationController.init, compilationController.changeCategory);
-
+    router.post('/changeLocation', compilationController.auth, compilationController.init, compilationController.changeLocation);
+    router.post('/changeFreeUse', compilationController.auth, compilationController.init, compilationController.changeFreeUse);
     app.use("/compilation", router);
 };

+ 31 - 0
web/users/js/compilation.js

@@ -666,6 +666,37 @@ $(document).ready(function () {
         });
     })
 
+
+     // 选择默认所在地
+     $('#location-select').change(function () {
+        $.ajax({
+            url: '/compilation/changeLocation',
+            type: 'post',
+            data: {id: id, location: $(this).val()},
+            dataType: "json",
+            success: function(response) {
+                if (response.error !== 0) {
+                    alert('更改失败');
+                }
+            }
+        });
+    })
+
+    // 修改是否提供免费版
+    $('#freeUse').change(function () {
+        $.ajax({
+            url: '/compilation/changeFreeUse',
+            type: 'post',
+            data: {id: id, freeUse: $(this).val()},
+            dataType: "json",
+            success: function(response) {
+                if (response.error !== 0) {
+                    alert('更改失败');
+                }
+            }
+        });
+    })
+
 });
 
 /**

+ 15 - 1
web/users/views/compilation/index.html

@@ -123,7 +123,21 @@
                         <% }) %>
                     </select>
                 </td></tr>
-                <tr><td><span>版本号:</span><input class="form-control" type="text" id="edition" value="<%= selectedCompilation.edition%>"></td></tr>
+              
+                <tr><td><p>默认工程所在地</p>
+                    <select class="form-control" style="width:200px" id="location-select">
+                        <option value=""></option>
+                        <% locationList.forEach(function(location) { %>
+                            <option value="<%= location %>" <% if (selectedCompilation.defaultLocation !== undefined && location === selectedCompilation.defaultLocation) { %>selected="selected"<% } %> ><%= location %></option>
+                            <% }) %>
+                    </select>
+                </td></tr>
+                <tr>
+                    <td>
+                        <p><span> 提供免费版:</span> <input type="checkbox" id="freeUse"  <% if (selectedCompilation.freeUse) { %> checked <% } %>></p>       
+                    </td>
+                </tr>
+                <tr><td><span>版本号:</span><input class="form-control" type="text" id="edition" value="<%= selectedCompilation.edition%>"></td></tr>  
             </table>
         </div>
         <input type="hidden" name="id" value="<%= selectedCompilation._id %>" id="compilation-id">