final_mat.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. package final
  2. import (
  3. "fmt"
  4. _ "image/gif"
  5. _ "image/jpeg"
  6. _ "image/png"
  7. "strings"
  8. "time"
  9. "zhiyuan/pkg/db"
  10. "zhiyuan/pkg/utils"
  11. "zhiyuan/services/admin"
  12. "github.com/gin-gonic/gin"
  13. )
  14. type FinalMat struct {
  15. ID int64 `json:"id" prop:"add:false"`
  16. Name string `json:"name" label:"名称" type:"string" prop:"add:false select:concat(zy_final_mat.brand,'\\t',zy_final_mat.series,'\\t',zy_final_mat.model,'\\t',zy_final_mat.specs,'\\t',zy_final_mat.color)" search:"like"`
  17. TypeId int64 `json:"type_id" label:"类型" type:"int" prop:"add edit"`
  18. AreaId int64 `json:"area_id" label:"区域" type:"int" prop:"add" search:"="`
  19. SupplierId int64 `json:"supplier_id" label:"材料商ID" type:"int" prop:"add edit" search:"="`
  20. Price float64 `json:"price" label:"单价" type:"float" prop:"edit" default:"0"`
  21. ControlPrice float64 `json:"control_price" label:"控价" type:"float" prop:"edit" default:"-1"`
  22. SalesPrice float64 `json:"sales_price" label:"销售价" type:"float" prop:"edit" default:"-1"`
  23. PurchasePrice float64 `json:"purchase_price" label:"代购价" type:"float" prop:"edit" default:"-1"`
  24. SKU string `json:"sku" label:"SKU" type:"string" prop:"edit" search:"like"`
  25. Brand string `json:"brand" label:"品牌" type:"string" prop:"add edit" search:"like"`
  26. Series string `json:"series" label:"系列" type:"string" prop:"edit" search:"like"`
  27. Model string `json:"model" label:"型号" type:"string" prop:"add edit" search:"like"`
  28. Specs string `json:"specs" label:"规格" type:"string" prop:"edit" search:"like"`
  29. Color string `json:"color" label:"颜色" type:"string" prop:"edit" search:"like"`
  30. ControlPriceUse float64 `json:"control_price_use" label:"控价" type:"float" prop:"add:false select:if(zy_final_mat.control_price<0,zy_final_mat.price,zy_final_mat.control_price)"`
  31. SalesPriceCalc float64 `json:"sales_price_calc" label:"销售价" type:"float" prop:"add:false select:ROUND(if(zy_final_mat.control_price<0,zy_final_mat.price,zy_final_mat.control_price)/0.73,2)"`
  32. SalesPriceUse float64 `json:"sales_price_use" label:"销售价" type:"float" prop:"add:false select:if(zy_final_mat.sales_price<0,ROUND(if(zy_final_mat.control_price<0,zy_final_mat.price,zy_final_mat.control_price)/0.73,2),zy_final_mat.sales_price)"`
  33. PurchasePriceCalc float64 `json:"purchase_price_calc" label:"销售价" type:"float" prop:"add:false select:ROUND(if(zy_final_mat.control_price<0,zy_final_mat.price,zy_final_mat.control_price)/0.84,2)"`
  34. PurchasePriceUse float64 `json:"purchase_price_use" label:"代购价" type:"float" prop:"add:false select:if(zy_final_mat.purchase_price<0,ROUND(if(zy_final_mat.control_price<0,zy_final_mat.price,zy_final_mat.control_price)/0.84,2),zy_final_mat.purchase_price)"`
  35. State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0" search:"="`
  36. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  37. CreatedAt int64 `json:"created_at" prop:"add:false"`
  38. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  39. db.BaseModel
  40. }
  41. func (FinalMat) TableName() string {
  42. return "zy_final_mat"
  43. }
  44. func ControlPrice(controlPrice float64, price float64) float64 {
  45. if controlPrice < 0 {
  46. return price
  47. }
  48. return controlPrice
  49. }
  50. func SalesCalculatePrice(controlPrice float64) float64 {
  51. return utils.FloatDiv(controlPrice, 0.73, 2)
  52. }
  53. func SalesPrice(salesPrice float64, controlPrice float64) float64 {
  54. if salesPrice < 0 {
  55. return SalesCalculatePrice(controlPrice)
  56. }
  57. return salesPrice
  58. }
  59. func PurchaseCalculatePrice(controlPrice float64) float64 {
  60. return utils.FloatDiv(controlPrice, 0.84, 2)
  61. }
  62. func PurchasePrice(purchasePrice float64, controlPrice float64) float64 {
  63. if purchasePrice < 0 {
  64. return PurchaseCalculatePrice(controlPrice)
  65. }
  66. return purchasePrice
  67. }
  68. func (model FinalMat) ControlPrices() float64 {
  69. return ControlPrice(model.ControlPrice, model.Price)
  70. }
  71. func (model FinalMat) SalesPrices() float64 {
  72. return SalesPrice(model.SalesPrice, ControlPrice(model.ControlPrice, model.Price))
  73. }
  74. func (model FinalMat) PurchasePrices() float64 {
  75. return PurchasePrice(model.PurchasePrice, ControlPrice(model.ControlPrice, model.Price))
  76. }
  77. func (model FinalMat) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  78. if typeid, ok := data["type_id"]; ok {
  79. ids := make([]int64, 0)
  80. typid, _ := db.ToInt64(typeid)
  81. ids = append(ids, typid)
  82. var typ FinalMatType
  83. db.GetModel(map[string]interface{}{
  84. "id": typid,
  85. "deleted_at": 0,
  86. }, &typ)
  87. if typ.ID != 0 {
  88. path := typ.Path + db.ToString(typ.ID) + ","
  89. types := make([]FinalMatType, 0)
  90. db.GetModel(map[string]interface{}{
  91. "path like": path + "%",
  92. "deleted_at": 0,
  93. }, &types)
  94. for _, v := range types {
  95. ids = append(ids, v.ID)
  96. }
  97. s.Where = append(s.Where, fmt.Sprintf("`%s`.`type_id` in %s", model.TableName(), s.Param(ids)))
  98. }
  99. }
  100. typeIds := make([]int64, 0)
  101. if type_ids, ok := data["type_ids"]; ok {
  102. typeids := strings.Split(db.ToString(type_ids), ",")
  103. for _, v := range typeids {
  104. if v != "" {
  105. if t, ok := db.ToInt64(v); ok {
  106. typeIds = append(typeIds, t)
  107. }
  108. }
  109. }
  110. }
  111. if len(typeIds) > 0 {
  112. ids := make([]int64, 0)
  113. for _, typeId := range typeIds {
  114. ids = append(ids, typeId)
  115. var typ FinalMatType
  116. db.GetModel(map[string]interface{}{
  117. "id": typeId,
  118. "deleted_at": 0,
  119. }, &typ)
  120. if typ.ID != 0 {
  121. path := typ.Path + db.ToString(typ.ID) + ","
  122. types := make([]FinalMatType, 0)
  123. db.GetModel(map[string]interface{}{
  124. "path like": path + "%",
  125. "deleted_at": 0,
  126. }, &types)
  127. for _, v := range types {
  128. ids = append(ids, v.ID)
  129. }
  130. }
  131. }
  132. s.Where = append(s.Where, fmt.Sprintf("`%s`.`type_id` in %s", model.TableName(), s.Param(ids)))
  133. }
  134. if supplier_ids, ok := data["supplier_ids"]; ok {
  135. supplierIds := make([]int64, 0)
  136. supplierids := strings.Split(db.ToString(supplier_ids), ",")
  137. for _, v := range supplierids {
  138. if v != "" {
  139. if t, ok := db.ToInt64(v); ok {
  140. supplierIds = append(supplierIds, t)
  141. }
  142. }
  143. }
  144. if len(supplierIds) != 0 {
  145. s.Where = append(s.Where, fmt.Sprintf("`%s`.`supplier_id` in %s", model.TableName(), s.Param(supplierIds)))
  146. }
  147. }
  148. if exclude_ids, ok := data["exclude_ids"]; ok {
  149. excludeIds := make([]int64, 0)
  150. excludeids := strings.Split(db.ToString(exclude_ids), ",")
  151. for _, v := range excludeids {
  152. if v != "" {
  153. if t, ok := db.ToInt64(v); ok {
  154. excludeIds = append(excludeIds, t)
  155. }
  156. }
  157. }
  158. if len(excludeIds) != 0 {
  159. s.Where = append(s.Where, fmt.Sprintf("`%s`.`id` not in %s", model.TableName(), s.Param(excludeIds)))
  160. }
  161. }
  162. return true
  163. }
  164. func (model FinalMat) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} {
  165. /*for n, item := range list {
  166. price, _ := db.ToFloat64(item["price"])
  167. controlPrice, _ := db.ToFloat64(item["control_price"])
  168. salesPrice, _ := db.ToFloat64(item["sales_price"])
  169. purchasePrice, _ := db.ToFloat64(item["purchase_price"])
  170. list[n]["control_price_use"] = ControlPrice(controlPrice, price)
  171. list[n]["sales_price_use"] = SalesPrice(salesPrice, price)
  172. list[n]["purchase_price_use"] = PurchasePrice(purchasePrice, price)
  173. }*/
  174. return list
  175. }
  176. func (FinalMat) OnePrivilege(c *gin.Context, id int64) bool {
  177. return true
  178. }
  179. func (FinalMat) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  180. return nil
  181. }
  182. func (FinalMat) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
  183. }
  184. func (FinalMat) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  185. if _, ok := data["price"]; ok {
  186. data["state"] = 0
  187. }
  188. if state, ok := data["state"]; ok {
  189. state, _ := db.ToInt64(state)
  190. if state == 0 {
  191. db.UpdateModels(db.Type(FinalMaterialCart{}), map[string]interface{}{
  192. "mat_id": id,
  193. }, map[string]interface{}{
  194. "deleted_at": time.Now().Unix(),
  195. })
  196. }
  197. }
  198. return nil
  199. }
  200. func (FinalMat) DelPrivilege(c *gin.Context, id int64) error {
  201. return nil
  202. }
  203. func (FinalMat) Page() bool {
  204. return false
  205. }
  206. func (FinalMat) Count() bool {
  207. return true
  208. }
  209. type FinalMatMobile struct {
  210. Typename string `json:"type_name" label:"类型名称" prop:"select:finalmattype.name" search:"like"`
  211. Type int64 `json:"type" label:"类型" type:"int" prop:"select:finalmattype.type" search:"="`
  212. Typepath string `json:"type_path" prop:"select:finalmattype.path"`
  213. Unit string `json:"unit" label:"单位" prop:"select:finalmattype.unit" search:"like"`
  214. IsCustom int64 `json:"is_custom" label:"是否定制" prop:"select:finalmattype.is_custom" search:"="`
  215. SupplierName string `json:"supplier_name" type:"string" prop:"select:supplier.name"`
  216. SupplierAdminId int64 `json:"supplier_admin_id" type:"int" prop:"select:supplier.adminId"`
  217. SupplierPhone string `json:"supplier_phone" type:"string" prop:"select:admin.phone"`
  218. SupplierHeadImgUrl string `json:"supplier_headimgurl" type:"string" prop:"select:admin.headimgurl"`
  219. FinalMat
  220. }
  221. func (model FinalMatMobile) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  222. if site_id, ok := data["site_id"]; ok {
  223. var site FinalSite
  224. db.GetModel(map[string]interface{}{
  225. "id": site_id,
  226. "deleted_at": 0,
  227. }, &site)
  228. if site.AreaId != 0 {
  229. s.Where = append(s.Where, fmt.Sprintf("`%s`.`area_id` = %s", model.TableName(), s.Param(site.AreaId)))
  230. } else {
  231. s.Where = append(s.Where, "1=2")
  232. }
  233. } else {
  234. if _, ok := data["area_id"]; !ok {
  235. s.Where = append(s.Where, "1=2")
  236. }
  237. }
  238. s.Where = append(s.Where, fmt.Sprintf("`supplier`.`state` = %s", s.Param(1)))
  239. s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` = %s", model.TableName(), s.Param(1)))
  240. where := "1=2"
  241. if admin.CheckAuth([]string{"final:material:take1"}, c.GetInt("adminID")) || admin.CheckAuth([]string{"final:verify:audit"}, c.GetInt("adminID")) {
  242. where = where + fmt.Sprintf(" OR `finalmattype`.`type` = %s", s.Param(1))
  243. }
  244. suppliers := make([]FinalSupplier, 0)
  245. db.GetModel(map[string]interface{}{
  246. "adminId": c.GetInt("adminID"),
  247. "state": 1,
  248. "deleted_at": 0,
  249. }, &suppliers)
  250. supplierids := make([]int64, 0)
  251. for _, v := range suppliers {
  252. supplierids = append(supplierids, v.ID)
  253. }
  254. if len(supplierids) != 0 {
  255. where = where + fmt.Sprintf(" OR `%s`.`supplier_id` in %s", model.TableName(), s.Param(supplierids))
  256. }
  257. where1 := "1=1"
  258. typeids := make([]int64, 0)
  259. if material, ok := data["material"]; ok {
  260. material, _ = db.ToInt64(material)
  261. if material != 0 {
  262. var mmodel FinalMaterial
  263. db.GetModel(map[string]interface{}{
  264. "id": material,
  265. "deleted_at": 0,
  266. }, &mmodel)
  267. var auxiliary FinalMatAuxiliary
  268. db.GetModel(map[string]interface{}{
  269. "id": mmodel.TypeId,
  270. "deleted_at": 0,
  271. }, &auxiliary)
  272. for _, v := range strings.Split(auxiliary.MatTypeIds, ",") {
  273. id, _ := db.ToInt64(v)
  274. typeids = append(typeids, id)
  275. var typ FinalMatType
  276. db.GetModel(map[string]interface{}{
  277. "id": id,
  278. "deleted_at": 0,
  279. }, &typ)
  280. path := typ.Path + db.ToString(typ.ID) + ","
  281. types := make([]FinalMatType, 0)
  282. db.GetModel(map[string]interface{}{
  283. "path like": path + "%",
  284. "deleted_at": 0,
  285. }, &types)
  286. for _, v := range types {
  287. typeids = append(typeids, v.ID)
  288. }
  289. }
  290. }
  291. }
  292. if len(typeids) == 0 {
  293. where1 += " and 1=2"
  294. } else {
  295. where1 += fmt.Sprintf(" and `%s`.`type_id` in %s", model.TableName(), s.Param(typeids))
  296. }
  297. supplier_ids := make([]int64, 0)
  298. if brand, ok := data["auxiliary_brand"]; ok {
  299. brand, _ = db.ToInt64(brand)
  300. if brand != 0 {
  301. var bmodel FinalMatAuxiliaryBrand
  302. db.GetModel(map[string]interface{}{
  303. "id": brand,
  304. "deleted_at": 0,
  305. }, &bmodel)
  306. for _, v := range strings.Split(bmodel.SupplierIds, ",") {
  307. id, _ := db.ToInt64(v)
  308. supplier_ids = append(supplier_ids, id)
  309. }
  310. }
  311. }
  312. if len(supplier_ids) == 0 {
  313. where1 += " and 1=2"
  314. } else {
  315. where1 += fmt.Sprintf(" and `%s`.`supplier_id` in %s", model.TableName(), s.Param(supplier_ids))
  316. }
  317. if admin.CheckAuth([]string{"final:material:take0"}, c.GetInt("adminID")) || admin.CheckAuth([]string{"final:verify:audit"}, c.GetInt("adminID")) {
  318. //where = where + fmt.Sprintf(" OR `finalmattype`.`type` = %s", s.Param(0))
  319. where = where + fmt.Sprintf(" OR (%s)", where1)
  320. }
  321. s.Where = append(s.Where, where)
  322. return model.FinalMat.ListPrivilege(c, data, s)
  323. }
  324. func (model FinalMatMobile) GroupBy() string {
  325. return fmt.Sprintf("`%s`.`id`", model.TableName())
  326. }
  327. func (model FinalMatMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  328. return append(model.FinalMat.LeftJoin(data, s), db.JoinModel{
  329. Model: FinalMatType{},
  330. As: "finalmattype",
  331. On: []string{"`finalmattype`.`id` = " + model.TableName() + ".`type_id`"},
  332. }, db.JoinModel{
  333. Model: FinalSupplier{},
  334. As: "supplier",
  335. On: []string{"`supplier`.`id` = " + model.TableName() + ".`supplier_id`"},
  336. }, db.JoinModel{
  337. Model: JoinAdmin{},
  338. As: "admin",
  339. On: []string{"`admin`.`id` = `supplier`.`adminId`"},
  340. })
  341. }
  342. type FinalMatPC struct {
  343. Typename string `json:"type_name" label:"类型名称" prop:"select:finalmattype.name" search:"like"`
  344. Type int64 `json:"type" label:"类型" type:"int" prop:"select:finalmattype.type" search:"="`
  345. Typepath string `json:"type_path" prop:"select:finalmattype.path"`
  346. Unit string `json:"unit" label:"单位" prop:"select:finalmattype.unit" search:"like"`
  347. SupplierId int64 `json:"supplier_id" type:"int" prop:"select:supplier.id"`
  348. SupplierName string `json:"supplier_name" type:"string" prop:"select:supplier.name"`
  349. SupplierAdminId string `json:"supplier_admin_id" type:"string" prop:"select:supplier.adminId"`
  350. FinalMat
  351. }
  352. func (model FinalMatPC) ExportFields() []db.ExportField {
  353. return []db.ExportField{
  354. {
  355. Label: "品牌",
  356. Name: "brand",
  357. Width: 20,
  358. },
  359. {
  360. Label: "系列",
  361. Name: "series",
  362. Width: 20,
  363. },
  364. {
  365. Label: "型号",
  366. Name: "model",
  367. Width: 30,
  368. },
  369. {
  370. Label: "规格",
  371. Name: "specs",
  372. Width: 20,
  373. },
  374. {
  375. Label: "颜色",
  376. Name: "color",
  377. Width: 20,
  378. },
  379. {
  380. Label: "SKU",
  381. Name: "sku",
  382. },
  383. {
  384. Label: "类型",
  385. Name: "type_name",
  386. Width: 30,
  387. },
  388. {
  389. Label: "材料商",
  390. Name: "supplier_name",
  391. Width: 30,
  392. },
  393. {
  394. Label: "供货价",
  395. Name: "price",
  396. Width: 20,
  397. },
  398. {
  399. Label: "控价",
  400. Name: "control_price",
  401. Width: 20,
  402. },
  403. {
  404. Label: "销售核算价",
  405. Name: "sales_price_calc",
  406. Width: 20,
  407. },
  408. {
  409. Label: "销售价",
  410. Name: "sales_price",
  411. Width: 20,
  412. },
  413. {
  414. Label: "代购核算价",
  415. Name: "purchase_price_calc",
  416. Width: 20,
  417. },
  418. {
  419. Label: "代购价",
  420. Name: "purchase_price",
  421. Width: 20,
  422. },
  423. }
  424. }
  425. func (FinalMatPC) ExportValue(row map[string]interface{}, rowIndex int, field db.ExportField, data []map[string]interface{}) string {
  426. switch field.Name {
  427. case "type_name":
  428. ids := make([]int64, 0)
  429. for _, v := range strings.Split(db.ToString(row["type_path"]), ",") {
  430. if id, ok := db.ToInt64(v); ok && id != 0 {
  431. ids = append(ids, id)
  432. }
  433. }
  434. id, _ := db.ToInt64(db.ToString(row["type_id"]))
  435. ids = append(ids, id)
  436. types := make([]FinalMatType, 0)
  437. db.GetModel(map[string]interface{}{
  438. "id in": ids,
  439. "deleted_at": 0,
  440. }, &types)
  441. typeMap := make(map[int64]FinalMatType)
  442. for _, v := range types {
  443. typeMap[v.ID] = v
  444. }
  445. names := make([]string, 0)
  446. for _, id := range ids {
  447. if typ, ok := typeMap[id]; ok {
  448. names = append(names, typ.Name)
  449. }
  450. }
  451. return strings.Join(names, "/")
  452. case "control_price":
  453. price, _ := db.ToFloat64(row["control_price"])
  454. if price < 0 {
  455. return ""
  456. }
  457. return db.ToString(price)
  458. case "sales_price":
  459. price, _ := db.ToFloat64(row["sales_price"])
  460. if price < 0 {
  461. return ""
  462. }
  463. return db.ToString(price)
  464. case "purchase_price":
  465. price, _ := db.ToFloat64(row["purchase_price"])
  466. if price < 0 {
  467. return ""
  468. }
  469. return db.ToString(price)
  470. }
  471. return db.ToString(row[field.Name])
  472. }
  473. func (model FinalMatPC) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  474. //if _, ok := data["area_id"]; !ok {
  475. // s.Where = append(s.Where, "1=2")
  476. //}
  477. if control_price, ok := data["control_price"]; ok {
  478. controlPrice, _ := db.ToFloat64(control_price)
  479. convertSql := ""
  480. convert1Sql := ""
  481. if convert, ok := data["convert"]; ok {
  482. if mp, ok := convert.(map[string]interface{}); ok && len(mp) != 0 {
  483. convertSql = "*(CASE finalmattype.name "
  484. for name, v := range mp {
  485. c, _ := db.ToFloat64(v)
  486. convertSql += fmt.Sprintf("WHEN %s THEN %s ", s.Param(name), s.Param(c))
  487. }
  488. convertSql += "ELSE 1 END)"
  489. } else {
  490. c, _ := db.ToFloat64(convert)
  491. if c != 0 {
  492. convertSql = fmt.Sprintf("*%s", s.Param(c))
  493. }
  494. }
  495. }
  496. if convert, ok := data["converts"]; ok {
  497. if mp, ok := convert.(map[string]interface{}); ok && len(mp) != 0 {
  498. convertSql = "*(CASE finalmattype.id "
  499. for name, v := range mp {
  500. c, _ := db.ToFloat64(v)
  501. convertSql += fmt.Sprintf("WHEN %s THEN %s ", s.Param(name), s.Param(c))
  502. }
  503. convertSql += "ELSE 1 END)"
  504. } else {
  505. c, _ := db.ToFloat64(convert)
  506. if c != 0 {
  507. convertSql = fmt.Sprintf("*%s", s.Param(c))
  508. }
  509. }
  510. }
  511. if convert, ok := data["converts1"]; ok {
  512. if mp, ok := convert.(map[string]interface{}); ok && len(mp) != 0 {
  513. convert1Sql = "*(CASE finalmattype.id "
  514. for name, v := range mp {
  515. c, _ := db.ToFloat64(v)
  516. convert1Sql += fmt.Sprintf("WHEN %s THEN %s ", s.Param(name), s.Param(c))
  517. }
  518. convert1Sql += "ELSE 1 END)"
  519. } else {
  520. c, _ := db.ToFloat64(convert)
  521. if c != 0 {
  522. convert1Sql = fmt.Sprintf("*%s", s.Param(c))
  523. }
  524. }
  525. }
  526. s.Select["upgrade_unit"] = "finalmattype.unit"
  527. if upgrade_unit, ok := data["upgrade_unit"]; ok {
  528. s.Select["upgrade_unit"] = fmt.Sprintf("%s", s.Param(upgrade_unit))
  529. }
  530. s.Select["upgrade_price"] = fmt.Sprintf("if(if(`%s`.`control_price`<0,`%s`.`price`,`%s`.`control_price`)%s>%s,CEILING(ROUND((if(`%s`.`control_price`<0,`%s`.`price`,`%s`.`control_price`)%s-%s)/0.84%s,4)*100)/100,0)", model.TableName(), model.TableName(), model.TableName(), convertSql, s.Param(controlPrice), model.TableName(), model.TableName(), model.TableName(), convertSql, s.Param(controlPrice), convert1Sql)
  531. if standard, ok := data["standard"]; ok {
  532. standards, _ := db.ToInt64(standard)
  533. if standards == 1 {
  534. s.Where = append(s.Where, fmt.Sprintf("if(`%s`.`control_price`<0,`%s`.`price`,`%s`.`control_price`)%s<=%s", model.TableName(), model.TableName(), model.TableName(), convertSql, s.Param(controlPrice)))
  535. }
  536. }
  537. }
  538. return model.FinalMat.ListPrivilege(c, data, s)
  539. }
  540. func (model FinalMatPC) GroupBy() string {
  541. return fmt.Sprintf("`%s`.`id`", model.TableName())
  542. }
  543. func (model FinalMatPC) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  544. return append(model.FinalMat.LeftJoin(data, s), db.JoinModel{
  545. Model: FinalMatType{},
  546. As: "finalmattype",
  547. On: []string{"`finalmattype`.`id` = " + model.TableName() + ".`type_id`"},
  548. }, db.JoinModel{
  549. Model: FinalSupplier{},
  550. As: "supplier",
  551. On: []string{"`supplier`.`id` = " + model.TableName() + ".`supplier_id`"},
  552. })
  553. }
  554. type FinalMatPCSupplier struct {
  555. FinalMatPC
  556. }
  557. func (model FinalMatPCSupplier) GroupBy() string {
  558. return "`supplier`.`id`"
  559. }