123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package controllers
- import (
- "Yunlot/lib"
- "Yunlot/models/Product"
- beego "github.com/beego/beego/v2/server/web"
- )
- type ProductProtController struct {
- beego.Controller
- }
- func (c *ProductProtController) ProductModeLists() {
- ProductProt_r, Total := Product.ProductModeLists()
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductProt_r, 0, 0, Total)}
- c.ServeJSON()
- return
- }
- func (c *ProductProtController) Get() {
- ProductProt := Product.ProductProt{}
- c.ParseForm(&ProductProt)
- if !ProductProt.Read() {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "ID E!"}
- c.ServeJSON()
- return
- }
- // 验证 TOKEY
- if ProductProt.T_tokey != c.GetString("T_tokey") {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductProt}
- c.ServeJSON()
- return
- }
- func (c *ProductProtController) List() {
- PageIndex, _ := c.GetInt("PageIndex", 0)
- PageSize, _ := c.GetInt("PageSize", 10)
- ProductProtr := Product.ProductProt{}
- c.ParseForm(&ProductProtr)
- // 验证 TOKEY
- if c.Ctx.Input.Host() != "127.0.0.1" {
- if len(ProductProtr.T_tokey) != 8 {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
- c.ServeJSON()
- return
- }
- }
- ProductProt_r, Total := ProductProtr.Lists(PageIndex, PageSize)
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductProt_r, PageIndex, PageSize, Total)}
- c.ServeJSON()
- return
- }
- func (c *ProductProtController) Add() {
- ProductProt_r := Product.ProductProt{}
- c.ParseForm(&ProductProt_r)
- if len(ProductProt_r.T_tokey) != 8 {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
- c.ServeJSON()
- return
- }
- ProductProt_r.Id = 0
- ProductProt_r.Add()
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductProt_r}
- c.ServeJSON()
- return
- }
- func (c *ProductProtController) Update() {
- Id, _ := c.GetInt("Id", 0)
- ProductProtr := Product.ProductProt{Id: Id}
- if !ProductProtr.Read() {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_ProductID E!"}
- c.ServeJSON()
- return
- }
- // 验证 TOKEY
- if ProductProtr.T_tokey != c.GetString("T_tokey") {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
- c.ServeJSON()
- return
- }
- c.ParseForm(&ProductProtr)
- if !ProductProtr.Update("T_name", "T_mode", "T_lang", "T_analysis", "T_text", "T_describe") {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *ProductProtController) Delete() {
- ProductProtr := Product.ProductProt{}
- c.ParseForm(&ProductProtr)
- if !ProductProtr.Read() {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "ID E!"}
- c.ServeJSON()
- return
- }
- // 验证 TOKEY
- if ProductProtr.T_tokey != c.GetString("T_tokey") {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
- c.ServeJSON()
- return
- }
- if !ProductProtr.Delete() {
- c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
- c.ServeJSON()
- return
- }
|