Explorar o código

feat: 增加是否提供免费版选项

zhangweicheng hai 1 ano
pai
achega
d6206843c1

+ 4 - 1
modules/all_models/compilation.js

@@ -76,6 +76,8 @@ let modelSchema = {
     overWriteUrl:String,
     //例题建设项目ID
     example: Array,
+    // 版本号
+    edition: String,
     // 发布时间
     release_time: {
         type: Number,
@@ -96,6 +98,7 @@ let modelSchema = {
         type: Number,
         default: 12 // 总部id
     },
-    defaultLocation:String//默认工程所在地
+    defaultLocation:String,//默认工程所在地
+    freeUse:Boolean
 };
 mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));

+ 38 - 2
modules/users/controllers/compilation_controller.js

@@ -763,11 +763,11 @@ class CompilationController extends BaseController {
      * @return {Promise.<void>}
      */
     async changeLocation(request, response) {
-        let valuationId = request.body.id;
+        let compilationId = request.body.id;
         let location = request.body.location;
         try {
             let compilationModel = new CompilationModel();
-            let result = await compilationModel.updateLocation(valuationId, location);
+            let result = await compilationModel.updateLocation(compilationId, location);
             if (result) {
                 response.json({error: 0, message: '', data: null});
             } else {
@@ -778,6 +778,42 @@ class CompilationController extends BaseController {
         }
     }
 
+
+     /**
+     * 更改编办默认工程所在工
+     *
+     * @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});
+        }
+    }
+
+    async setEdition(request, response){
+        let compilationId = request.body.id;
+        let edition = request.body.edition;
+        try{
+            let compilationModel = new CompilationModel();
+            await compilationModel.setEdition(compilationId, edition);
+            response.json({err: 0, msg: '', data: null});
+        }
+        catch (err){
+            response.json({err: 1, msg: err, data: null});
+        }
+    }
 }
 
 export default CompilationController;

+ 23 - 1
modules/users/models/compilation_model.js

@@ -36,7 +36,7 @@ class CompilationModel extends BaseModel {
      */
     async getCompilationList(fields = null) {
         // 筛选字段
-        let field = fields == null ? {_id: 1, name: 1, is_release: 1,release_time:1, defaultLocation:1,categoryID: 1, description: 1,overWriteUrl: 1,example: 1,
+        let field = fields == null ? {_id: 1, name: 1, is_release: 1,release_time:1, defaultLocation:1,categoryID: 1, description: 1,overWriteUrl: 1,example: 1,edition: 1,freeUse:1,
             "ration_valuation.id": 1, "ration_valuation.name": 1, "ration_valuation.enable": 1,
             "suggestion_valuation.id": 1, "suggestion_valuation.name": 1, "suggestion_valuation.enable": 1,
             "feasibility_valuation.id": 1, "feasibility_valuation.name": 1, "feasibility_valuation.enable": 1,
@@ -470,6 +470,28 @@ class CompilationModel extends BaseModel {
         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});
+    }
+
+  /*
+    * 设置版本号
+    *
+    * @param {String} compilationId
+    * @param {String} edition
+    * @return {Promise}
+    * */
+  async setEdition(compilationId, edition){
+    return await this.updateById(compilationId, {edition: edition});
+   }
+
 }
 
 export default CompilationModel;

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

@@ -36,5 +36,7 @@ module.exports = function (app) {
 
     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);
+    router.post('/setEdition', compilationController.auth, compilationController.init, compilationController.setEdition);
     app.use("/compilation", router);
 };

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

@@ -588,6 +588,37 @@ $(document).ready(function() {
             }
         });
     })
+
+    // 修改是否提供免费版
+    $('#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('更改失败');
+                }
+            }
+        });
+    })
+
+    //更改版本号
+    $('#edition').change(function () {
+        let edition = $(this).val();
+        $.ajax({
+            url: '/compilation/setEdition',
+            type: 'post',
+            dataType: "json",
+            data: { id: id, edition: edition },
+            success: function (response) {
+                if (response.err !== 0) {
+                    alert('更改失败');
+                }
+            }
+        });
+    });
 });
 
 /**

+ 6 - 0
web/users/views/compilation/index.html

@@ -300,6 +300,12 @@
                             <% }) %>
                     </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">