123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- package final
- import (
- "errors"
- "fmt"
- "zhiyuan/pkg/db"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/admin"
- "zhiyuan/services/user"
- "github.com/gin-gonic/gin"
- )
- type FinalSiteContract struct {
- ID int64 `json:"id" prop:"add:false"`
- PkgId int64 `json:"pkg_id" label:"套餐" type:"int" prop:"add edit" search:"="`
- TypeId int64 `json:"type_id" label:"开工类型" type:"int" prop:"add:false edit" search:"="`
- Username string `json:"username" label:"业主姓名" type:"string" prop:"add edit" search:"like"`
- Phone string `json:"phone" label:"手机号码" type:"string" prop:"add edit" search:"like"`
- AreaId int64 `json:"area_id" label:"区域" type:"int" prop:"add edit" search:"="`
- CustomerId int64 `json:"customer_id" label:"客户" type:"int" prop:"edit:false" search:"="`
- OrderId int64 `json:"order_id" label:"合同" type:"int" prop:"edit:false" search:"="`
- Village string `json:"village" label:"小区名称" type:"string" prop:"edit" search:"like"`
- Address string `json:"address" label:"房屋地址" type:"string" prop:"edit" search:"like"`
- RoomNo string `json:"room_no" label:"楼栋房号" type:"string" prop:"edit" search:"like"`
- Areacode string `json:"areacode" label:"区划代码" type:"string" prop:"edit" search:"rightlike"`
- Name string `json:"name" label:"名称" type:"string" prop:"add:false select:concat(zy_final_site.village,'\\t',zy_final_site.address,'\\t',zy_final_site.room_no)" search:"like"`
- Names string `json:"names" label:"名称" type:"string" prop:"add:false select:concat(zy_final_site.village,zy_final_site.address,zy_final_site.room_no)" search:"like"`
- Area float64 `json:"area" label:"面积" type:"float" prop:"add edit"`
- ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"edit" search:"="`
- ManagerId int64 `json:"manager_id" label:"项目经理" type:"int" prop:"add:false edit" search:"="`
- ProjectLeaderId int64 `json:"project_leader_id" label:"工程队长" type:"int" prop:"add:false edit" search:"="`
- DesignerId int64 `json:"designer_id" label:"设计师" type:"int" prop:"add edit" search:"="`
- StartTime int64 `json:"starttime" label:"开工日期" type:"int" prop:"add:false" search:"="`
- EndTime int64 `json:"endtime" label:"完工日期" type:"int" prop:"add:false" search:"="`
- CreatedId int64 `json:"created_id" label:"创建人员" type:"int" prop:"add:false" search:"="`
- ChangeState int64 `json:"change_state" label:"状态" type:"int" prop:"add:false edit" default:"0" search:"="`
- Remark string `json:"remark" label:"备注" type:"string" prop:"edit"`
- Activity string `json:"activity" label:"活动" type:"string" prop:"edit"`
- Attachment string `json:"attachment" label:"附件" type:"string" prop:"edit"`
- DeptId int64 `json:"dept_id" label:"归属部门" type:"int" prop:"edit" search:"="`
- SalesmanId int64 `json:"salesman_id" label:"业务员" type:"int" prop:"edit" search:"="`
- State int64 `json:"state" label:"状态" type:"int" prop:"add:false edit" default:"0" search:"="`
- StateId int64 `json:"state_id" label:"状态ID" type:"int" prop:"add:false"`
- Room1 int64 `json:"room_1" label:"户型" type:"int" prop:"add edit" search:"="`
- Room2 int64 `json:"room_2" label:"户型" type:"int" prop:"add edit" search:"="`
- Room3 int64 `json:"room_3" label:"户型" type:"int" prop:"add edit" search:"="`
- Room4 int64 `json:"room_4" label:"户型" type:"int" prop:"add edit" search:"="`
- Room5 int64 `json:"room_5" label:"户型" type:"int" prop:"edit" search:"="`
- ContactTime int64 `json:"contacttime" label:"接触时间" type:"int" prop:"edit" search:"="`
- StoreTime int64 `json:"storetime" label:"到店时间" type:"int" prop:"edit" search:"="`
- SignTime int64 `json:"signtime" label:"签订时间" type:"int" prop:"edit" search:"="`
- DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
- CreatedAt int64 `json:"created_at" prop:"add:false"`
- UpdatedAt int64 `json:"updated_at" prop:"add:false"`
- db.BaseModel
- }
- func (FinalSiteContract) TableName() string {
- return "zy_final_site"
- }
- func (model FinalSiteContract) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` != %s", model.TableName(), s.Param(2)))
- if !admin.IsSuperAdmin(c.GetInt("adminID")) && !admin.CheckAuth([]string{"final:finalsitecontract:all"}, c.GetInt("adminID")) {
- adminID := s.Param(c.GetInt("adminID"))
- where := fmt.Sprintf("`%s`.`designer_id` = %s OR `%s`.`created_id` = %s", model.TableName(), adminID, model.TableName(), adminID)
- if admin.CheckAuth([]string{"final:verify"}, c.GetInt("adminID")) {
- info, _ := admin.GetInfoByID(c.GetInt("adminID"), nil, nil)
- if info == nil {
- return false
- }
- where = fmt.Sprintf("%s OR FIND_IN_SET(`%s`.`shop_id`, %s)", where, model.TableName(), s.Param(info.ShopIds))
- }
- s.Where = append(s.Where, fmt.Sprintf("(%s)", where))
- }
- if search, ok := data["search"]; ok {
- search = s.Param(fmt.Sprintf("%%%s%%", search))
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`username` LIKE %s OR `%s`.`phone` LIKE %s OR concat(`%s`.`village`,`%s`.`address`,`%s`.`room_no`) LIKE %s", model.TableName(), search, model.TableName(), search, model.TableName(), model.TableName(), model.TableName(), search))
- }
- if signtime1s, ok := data["signtime1"]; ok {
- if signtime1, ok := db.ToInt64(signtime1s); ok {
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`signtime` >= %s", model.TableName(), s.Param(signtime1)))
- }
- }
- if signtime2s, ok := data["signtime2"]; ok {
- if signtime2, ok := db.ToInt64(signtime2s); ok {
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`signtime` < %s", model.TableName(), s.Param(signtime2+60*60*24)))
- }
- }
- return true
- }
- func (FinalSiteContract) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
- /*var model FinalSite
- db.GetModel(map[string]interface{}{
- "village": data["village"],
- "room_no": data["room_no"],
- "deleted_at": 0,
- }, &model)
- if model.ID != 0 {
- return errors.New("工地已存在")
- }
- user, err := user.GetOne(map[string]interface{}{"phone": data["phone"]}, nil, nil)
- if err != nil {
- return errors.New("获取用户信息失败")
- }
- if user == nil {
- return errors.New("用户未关注公众号")
- }*/
- data["created_id"] = c.GetInt("adminID")
- return nil
- }
- func (FinalSiteContract) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
- var site FinalSite
- db.GetModel(map[string]interface{}{
- "id": id,
- "deleted_at": 0,
- }, &site)
- from := make(map[string]float64)
- var fields []FinalPkgField
- db.GetModel(map[string]interface{}{"pkg_id": site.PkgId}, &fields)
- for _, v := range fields {
- value, _ := db.ToFloat64(v.Value)
- from[v.Name] = value
- }
- db.InsertModel(db.Type(FinalSiteAmount{}), map[string]interface{}{
- "site_id": id,
- "content": utils.JsonEncode(from),
- "created_id": c.GetInt("adminID"),
- })
- }
- func (FinalSiteContract) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
- var model FinalSiteContract
- db.GetModel(map[string]interface{}{
- "id": id,
- "deleted_at": 0,
- }, &model)
- if !admin.CheckShop(int(model.ShopId), c.GetInt("adminID")) && int(model.DesignerId) != c.GetInt("adminID") {
- return errors.New("没有权限")
- }
- /*if type_id, ok := data["type_id"]; ok {
- typeId, _ := db.ToInt64(type_id)
- if typeId != 0 {
- var model FinalSite
- db.GetModel(map[string]interface{}{
- "id": id,
- "deleted_at": 0,
- }, &model)
- if model.State == 1 {
- payments := make([]FinalSitePayment, 0)
- db.GetModel(map[string]interface{}{
- "site_id": id,
- "deleted_at": 0,
- }, &payments)
- if len(payments) == 0 {
- var typ FinalSiteType
- db.GetModel(map[string]interface{}{
- "id": typeId,
- "deleted_at": 0,
- }, &typ)
- settlements := make([]int64, 0)
- if typ.ID != 0 {
- for _, s := range strings.Split(typ.Settlement, ",") {
- if n, ok := db.ToInt64(s); ok {
- settlements = append(settlements, n)
- }
- }
- }
- ptypes := make([]FinalPaymentType, 0)
- db.GetModel(map[string]interface{}{
- "deleted_at": 0,
- }, &ptypes)
- for _, v := range ptypes {
- data := map[string]interface{}{
- "type_id": v.ID,
- "site_id": id,
- }
- for _, s := range settlements {
- if s == v.ID {
- data["state"] = 1
- }
- }
- id, err := db.InsertModel(db.Type(FinalSitePayment{}), data)
- if err == nil {
- FinalSitePayment{}.AddAfter(c, id, data, data)
- }
- }
- var order budget2.Order
- if model.OrderId != 0 {
- db.GetModel(map[string]interface{}{
- "id": model.OrderId,
- "deleted_at": 0,
- }, &order)
- }
- if order.ID == 0 {
- var pkg FinalPkg
- db.GetModel(map[string]interface{}{
- "id": model.PkgId,
- "deleted_at": 0,
- }, &pkg)
- types := make([]FinalType, 0)
- db.GetModel(map[string]interface{}{
- "state": 1,
- "deleted_at": 0,
- }, &types)
- for _, v := range types {
- data := map[string]interface{}{
- "type_id": v.ID,
- "site_id": id,
- }
- if v.CalcValue != "" {
- expression, err := govaluate.NewEvaluableExpression(v.CalcValue)
- if err == nil {
- parameters := make(map[string]interface{}, 8)
- parameters["面积"] = model.Area
- parameters["套餐"] = pkg.Name
- result, err := expression.Evaluate(parameters)
- if err == nil {
- data["budget"], _ = db.ToFloat64(result)
- }
- }
- }
- id, err := db.InsertModel(db.Type(FinalSiteControl{}), data)
- if err == nil {
- FinalSiteControl{}.AddAfter(c, id, data, data)
- }
- }
- mauxiliarys := make([]FinalMatAuxiliary, 0)
- db.GetModel(map[string]interface{}{
- "preset": 1,
- "deleted_at": 0,
- }, &mauxiliarys)
- for _, v := range mauxiliarys {
- if v.Name == "开工形象" && (model.ShopId == 18 || typeId == 4) {
- continue
- }
- data := map[string]interface{}{
- "type_id": v.ID,
- "site_id": id,
- }
- if v.CalcValue != "" {
- expression, err := govaluate.NewEvaluableExpression(v.CalcValue)
- if err == nil {
- parameters := make(map[string]interface{}, 8)
- parameters["面积"] = model.Area
- parameters["套餐"] = pkg.Name
- result, err := expression.Evaluate(parameters)
- if err == nil {
- data["budget"], _ = db.ToFloat64(result)
- }
- }
- }
- id, err := db.InsertModel(db.Type(FinalMaterial{}), data)
- if err == nil {
- FinalMaterial{}.AddAfter(c, id, data, data)
- }
- }
- address := model.Address
- if model.Village != " " {
- address += " " + model.Village
- }
- if model.RoomNo != " " {
- address += " " + model.RoomNo
- }
- switch model.ShopId {
- case 9, 13, 14, 18:
- SendSiteMessage(1003, id, address, "工地已创建,请及时下单")
- case 10, 12, 15:
- SendSiteMessage(1004, id, address, "工地已创建,请及时下单")
- case 6, 16:
- SendSiteMessage(1257, id, address, "工地已创建,请及时下单")
- case 7, 17:
- SendSiteMessage(1173, id, address, "工地已创建,请及时下单")
- }
- } else {
- o, err := order.LoadOrder()
- }
- }
- }
- }
- }*/
- if state, ok := data["state"]; ok {
- states, _ := db.ToInt64(state)
- if states == 1 {
- var model FinalSite
- db.GetModel(map[string]interface{}{
- "id": id,
- "deleted_at": 0,
- }, &model)
- if model.ID == 0 {
- return errors.New("工地不存在")
- }
- if model.ShopId == 0 {
- return errors.New("公司名称未填")
- }
- if model.DeptId == 0 {
- return errors.New("部门未填")
- }
- if model.SalesmanId == 0 {
- return errors.New("业务员未填")
- }
- if model.RoomNo == "" {
- return errors.New("楼栋房号未填")
- }
- if model.Areacode == "" {
- return errors.New("所在县区未填")
- }
- if model.ContactTime == 0 {
- return errors.New("接触时间未填")
- }
- if model.StoreTime == 0 {
- return errors.New("到店时间未填")
- }
- if model.SignTime == 0 {
- return errors.New("签订时间未填")
- }
- var site FinalSite
- db.GetModel(map[string]interface{}{
- "id !=": id,
- "village": model.Village,
- "room_no": model.RoomNo,
- "state": 1,
- "deleted_at": 0,
- }, &site)
- if site.ID != 0 {
- return errors.New("房屋地址重复")
- }
- user, err := user.GetOne(map[string]interface{}{"phone": model.Phone}, nil, nil)
- if err != nil {
- return errors.New("获取用户信息失败")
- }
- if user == nil {
- return errors.New("用户未关注公众号")
- }
- }
- var record FinalSiteStateRecord
- db.GetModel(map[string]interface{}{"id": id}, &record)
- if record.State != state {
- db.InsertModel(db.Type(FinalSiteStateRecord{}), map[string]interface{}{
- "site_id": id,
- "state": state,
- "created_id": c.GetInt("adminID"),
- })
- }
- }
- return nil
- }
- func (FinalSiteContract) DelPrivilege(c *gin.Context, id int64) error {
- return nil
- }
- func (FinalSiteContract) Page() bool {
- return false
- }
- func (FinalSiteContract) Count() bool {
- return true
- }
|