2021-12-11 09:59:02 +00:00
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"time"
)
var product_spot_checkCtr = Ctr {
"info" : func ( that * Context ) {
adminID := that . Session ( "id" ) . ToInt ( )
if adminID == 0 {
that . Display ( 2 , "登录失效,请重新登录" )
return
}
id := ObjToInt ( that . Req . FormValue ( "id" ) )
if id == 0 {
that . Display ( 3 , "请求参数不足,请检查参数" )
return
}
re := that . Db . Get ( "product_spot_check" ,
Map { "[><]product" : "product_spot_check.product_id=product.id" ,
"[><]produce" : "product_spot_check.produce_id=produce.id" ,
} ,
"id,img,product_id,product.name AS product_name,admin_id," +
"modify_time,state,rule,produce_id,produce.name AS produce_name" , Map { "id" : id } )
if re == nil {
that . Display ( 4 , "找不到对应信息" )
return
}
that . Display ( 0 , re )
} ,
"add" : func ( that * Context ) {
adminID := that . Session ( "id" ) . ToInt ( )
if adminID == 0 {
that . Display ( 2 , "登录失效,请重新登录" )
return
}
2021-12-15 01:24:41 +00:00
//img := that.Req.FormValue("img")
sn := that . Req . FormValue ( "sn" )
rule := that . Req . FormValue ( "rule_spot_check" )
description := that . Req . FormValue ( "description" )
2021-12-11 09:59:02 +00:00
produceProductId := ObjToInt ( that . Req . FormValue ( "produce_product_id" ) )
2021-12-15 01:24:41 +00:00
//count := ObjToInt(that.Req.FormValue("count"))
2021-12-11 09:59:02 +00:00
state := ObjToInt ( that . Req . FormValue ( "state" ) )
2021-12-15 01:24:41 +00:00
if rule == "" || produceProductId == 0 {
2021-12-11 09:59:02 +00:00
that . Display ( 3 , "参数不足,请补充参数" )
return
}
2021-12-15 01:24:41 +00:00
2021-12-11 09:59:02 +00:00
produceProduct := that . Db . Get ( "produce_product" , "*" , Map { "id" : produceProductId } )
2021-12-27 10:21:41 +00:00
if produceProduct == nil {
that . Display ( 4 , "找不到成品记录,无法进行抽检" )
return
}
//判断是否已经抽检了
alreadyCheck := that . Db . Get ( "product_spot_check" , "id" , Map { "produce_product_id" : produceProductId } )
2021-12-11 09:59:02 +00:00
2021-12-27 10:21:41 +00:00
if alreadyCheck == nil {
2021-12-11 09:59:02 +00:00
2021-12-27 10:21:41 +00:00
that . Db . Update ( "product" , Map { "spot_check_count[#]" : "spot_check_count+1" } ,
Map { "id" : produceProduct . GetCeilInt ( "product_id" ) } )
that . Db . Update ( "produce" , Map { "spot_check_count[#]" : "spot_check_count+1" } ,
Map { "id" : produceProduct . GetCeilInt ( "produce_id" ) } )
}
2021-12-11 09:59:02 +00:00
data := Map {
2021-12-15 01:24:41 +00:00
"sn" : sn ,
2021-12-11 09:59:02 +00:00
"rule" : rule ,
"admin_id" : adminID ,
"create_time" : time . Now ( ) . Unix ( ) ,
"modify_time" : time . Now ( ) . Unix ( ) ,
2021-12-15 01:24:41 +00:00
"product_id" : produceProduct . GetCeilInt ( "product_id" ) ,
2021-12-11 09:59:02 +00:00
"produce_id" : produceProduct . GetCeilInt ( "produce_id" ) ,
"produce_product_id" : produceProductId ,
2021-12-15 01:24:41 +00:00
"description" : description ,
2021-12-11 09:59:02 +00:00
"state" : state ,
}
id := that . Db . Insert ( "product_spot_check" , data )
if id == 0 {
that . Display ( 4 , "添加抽检记录失败,请重新添加" )
return
}
data [ "id" ] = id
that . Display ( 0 , data )
} ,
"search" : func ( that * Context ) {
adminID := that . Session ( "id" ) . ToInt ( )
if adminID == 0 {
that . Display ( 2 , "登录失效,请重新登录" )
return
}
page := ObjToInt ( that . Req . FormValue ( "page" ) )
pageSize := ObjToInt ( that . Req . FormValue ( "pageSize" ) )
2021-12-11 20:22:30 +00:00
productId := ObjToInt ( that . Req . FormValue ( "id" ) )
2021-12-11 09:59:02 +00:00
if page < 1 {
page = 1
}
if pageSize <= 0 {
2021-12-11 20:22:30 +00:00
pageSize = 10
2021-12-11 09:59:02 +00:00
}
2021-12-11 20:22:30 +00:00
columnStr := "product_spot_check.id,product_spot_check.product_id,product_spot_check.sn,product.name,product_spot_check.img,product_spot_check.admin_id,admin.name AS admin_name,product_spot_check.modify_time,product_spot_check.state"
2021-12-11 09:59:02 +00:00
leftJoin := Map { "[><]product" : "product_spot_check.product_id=product.id" ,
"[><]admin" : "product_spot_check.admin_id=admin.id" ,
}
2021-12-11 20:22:30 +00:00
where := Map { "ORDER" : "id DESC" }
if productId != 0 {
where [ "product_id" ] = productId
}
count := that . Db . Count ( "product_spot_check" , where )
2021-12-11 09:59:02 +00:00
reData := that . Db . Page ( page , pageSize ) .
PageSelect ( "product_spot_check" , leftJoin , columnStr , where )
that . Display ( 0 , Map { "count" : count , "data" : reData } )
} ,
}