final_material_settle.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. package final
  2. import (
  3. "encoding/base64"
  4. "errors"
  5. "fmt"
  6. "log"
  7. "regexp"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "zhiyuan/pkg/db"
  12. "zhiyuan/services/admin"
  13. "github.com/gin-gonic/gin"
  14. "github.com/xuri/excelize/v2"
  15. )
  16. type FinalMaterialSettle struct {
  17. ID int64 `json:"id" prop:"add:false"`
  18. ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"add:false" default:"0" search:"="`
  19. SupplierId int64 `json:"supplier_id" label:"材料商" type:"int" prop:"add:false" default:"0" search:"="`
  20. CollectId int64 `json:"collect_id" label:"汇总" type:"int" prop:"add:false" default:"0" search:"="`
  21. Amount float64 `json:"amount" label:"订单金额" type:"float" prop:"add:false" search:"="`
  22. Deduction float64 `json:"deduction" label:"扣款金额" type:"float" prop:"add:false" search:"="`
  23. Total float64 `json:"total" label:"合计金额" type:"float" prop:"add:false" search:"="`
  24. State int64 `json:"state" label:"状态" type:"int" prop:"add:false" default:"0" search:"="`
  25. Orders string `json:"orders" label:"订单" type:"string" prop:"add:false" search:"find_in_set"`
  26. CreatedId int64 `json:"created_id" label:"创建人员" type:"int" prop:"add:false" search:"="`
  27. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  28. CreatedAt int64 `json:"created_at" prop:"add:false"`
  29. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  30. db.BaseModel
  31. }
  32. func (FinalMaterialSettle) TableName() string {
  33. return "zy_final_material_settle"
  34. }
  35. func (FinalMaterialSettle) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  36. return errors.New("没有权限")
  37. }
  38. func (FinalMaterialSettle) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
  39. }
  40. func (model FinalMaterialSettle) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  41. return true
  42. }
  43. func (FinalMaterialSettle) OnePrivilege(c *gin.Context, id int64) bool {
  44. return true
  45. }
  46. func (FinalMaterialSettle) Page() bool {
  47. return false
  48. }
  49. func (FinalMaterialSettle) Count() bool {
  50. return true
  51. }
  52. type FinalMaterialSettleMobile struct {
  53. SupplierName string `json:"supplier_name" type:"string" prop:"select:supplier.name" search:"like"`
  54. SupplierAdminId string `json:"supplier_admin_id" type:"string" prop:"select:supplier.adminId"`
  55. Prepayment int64 `json:"prepayment" type:"int" prop:"select:supplier.prepayment"`
  56. AccountName string `json:"account_name" prop:"select:account.account_name"`
  57. AccountBank string `json:"account_bank" prop:"select:account.account_bank"`
  58. AccountNo string `json:"account_no" prop:"select:account.account_no"`
  59. ShopName string `json:"shop_name" prop:"select:shop.shop_name"`
  60. CollectInfo string `json:"collect_info" prop:"select:shop.collect_info"`
  61. FinalMaterialSettle
  62. }
  63. func (model FinalMaterialSettleMobile) GroupBy() string {
  64. return fmt.Sprintf("`%s`.`id`", model.TableName())
  65. }
  66. func (model FinalMaterialSettleMobile) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  67. if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  68. adminID := s.Param(c.GetInt("adminID"))
  69. where := fmt.Sprintf("`supplier`.`adminId` = %s OR `%s`.`created_id` = %s", adminID, model.TableName(), adminID)
  70. if admin.CheckAuth([]string{"final:verify"}, c.GetInt("adminID")) {
  71. info, _ := admin.GetInfoByID(c.GetInt("adminID"), nil, nil)
  72. if info == nil {
  73. return false
  74. }
  75. where = where + fmt.Sprintf(" OR FIND_IN_SET(`%s`.`shop_id`, %s)", model.TableName(), s.Param(info.ShopIds))
  76. }
  77. s.Where = append(s.Where, fmt.Sprintf("(%s)", where))
  78. }
  79. return model.FinalMaterialSettle.ListPrivilege(c, data, s)
  80. }
  81. func (model FinalMaterialSettleMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  82. return append(model.FinalMaterialSettle.LeftJoin(data, s), db.JoinModel{
  83. Model: FinalSupplier{},
  84. As: "supplier",
  85. On: []string{"`supplier`.`id` = " + model.TableName() + ".`supplier_id`"},
  86. }, db.JoinModel{
  87. Model: FinalSupplierAccount{},
  88. As: "account",
  89. On: []string{"`account`.`id` = " + model.TableName() + ".`account_id`"},
  90. }, db.JoinModel{
  91. Model: JoinShop{},
  92. As: "shop",
  93. On: []string{"`shop`.`id` = " + model.TableName() + ".`shop_id`"},
  94. })
  95. }
  96. type FinalMaterialSettlePC struct {
  97. FinalMaterialSettleMobile
  98. }
  99. func (model FinalMaterialSettlePC) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} {
  100. orderids := make([]int64, 0)
  101. orderidsMap := make(map[int64][]int64)
  102. for _, v := range list {
  103. ids := make([]int64, 0)
  104. id, _ := db.ToInt64(v["id"])
  105. orders := db.ToString(v["orders"])
  106. s := strings.Split(orders, ",")
  107. for _, i := range s {
  108. if n, ok := db.ToInt64(i); ok {
  109. ids = append(ids, n)
  110. }
  111. }
  112. orderids = append(orderids, ids...)
  113. orderidsMap[id] = ids
  114. }
  115. datas, _ := db.GetModelMap(db.Type(FinalMaterialOrderMobile{}), map[string]interface{}{
  116. fmt.Sprintf("`%s`.`id` in", FinalMaterialOrderMobile{}.TableName()): orderids,
  117. fmt.Sprintf("`%s`.`deleted_at`", FinalMaterialOrderMobile{}.TableName()): 0,
  118. }, nil)
  119. FinalMaterialOrderMobile{}.ListAfter(c, data, datas)
  120. for n, settle := range list {
  121. id, _ := db.ToInt64(settle["id"])
  122. if orderids, ok := orderidsMap[id]; ok {
  123. for _, v := range datas {
  124. orderid, _ := db.ToInt64(v["id"])
  125. is := false
  126. for _, s := range orderids {
  127. if s == orderid {
  128. is = true
  129. break
  130. }
  131. }
  132. if is {
  133. order := make([]map[string]interface{}, 0)
  134. if s, ok := list[n]["order"].([]map[string]interface{}); ok {
  135. order = s
  136. }
  137. order = append(order, v)
  138. list[n]["order"] = order
  139. }
  140. }
  141. }
  142. }
  143. return list
  144. }
  145. func (model FinalMaterialSettlePC) ExportSpan() []string {
  146. return []string{"order", "items"}
  147. }
  148. func (model FinalMaterialSettlePC) ExportFields() []db.ExportField {
  149. return []db.ExportField{
  150. {
  151. Label: "ID",
  152. Name: "id",
  153. },
  154. {
  155. Label: "门店",
  156. Name: "shop_name",
  157. },
  158. {
  159. Label: "订单号",
  160. Name: "order.order_no",
  161. Width: 30,
  162. },
  163. {
  164. Label: "工地",
  165. Name: "order.address",
  166. Width: 20,
  167. },
  168. {
  169. Label: "材料名称",
  170. Name: "order.items.mat_name",
  171. Width: 30,
  172. },
  173. {
  174. Label: "单价",
  175. Name: "order.items.mat_price",
  176. },
  177. {
  178. Label: "数量",
  179. Name: "order.items.num",
  180. },
  181. {
  182. Label: "总价",
  183. Name: "order.items.total",
  184. },
  185. {
  186. Label: "备注",
  187. Name: "order.items.remark",
  188. },
  189. {
  190. Label: "订单金额",
  191. Name: "order.total",
  192. },
  193. {
  194. Label: "订单合计",
  195. Name: "amount",
  196. },
  197. {
  198. Label: "扣款金额",
  199. Name: "deduction",
  200. },
  201. {
  202. Label: "材料商",
  203. Name: "supplier_name",
  204. Width: 20,
  205. },
  206. {
  207. Label: "预付款",
  208. Name: "prepayment",
  209. },
  210. {
  211. Label: "开户名",
  212. Name: "account_name",
  213. Width: 30,
  214. },
  215. {
  216. Label: "开户行",
  217. Name: "account_bank",
  218. Width: 20,
  219. },
  220. {
  221. Label: "账号",
  222. Name: "account_no",
  223. Width: 30,
  224. },
  225. {
  226. Label: "结算金额",
  227. Name: "total",
  228. },
  229. {
  230. Label: "状态",
  231. Name: "state",
  232. },
  233. {
  234. Label: "财务审核",
  235. Name: "",
  236. },
  237. {
  238. Label: "店长审核",
  239. Name: "",
  240. },
  241. {
  242. Label: "财务审核",
  243. Name: "",
  244. },
  245. }
  246. }
  247. func (FinalMaterialSettlePC) ExportValue(row map[string]interface{}, rowIndex int, field db.ExportField, data []map[string]interface{}) string {
  248. states := []string{"未提交", "工程队长审核", "财务审核", "店长审核", "财务付款", "已完成"}
  249. prepayments := []string{"否", "是"}
  250. switch field.Name {
  251. case "order.address":
  252. worksite := /*db.ToString(v["address"]) + " " +*/ db.ToString(row["order.village"]) + "" + db.ToString(row["order.room_no"])
  253. if worksite == "" {
  254. worksite = db.ToString(row["order.address"])
  255. }
  256. return worksite
  257. case "order.items.num":
  258. return db.ToString(row["order.items.num"]) + " " + db.ToString(row["order.items.unit"])
  259. case "prepayment":
  260. prepayment := int64(0)
  261. if t, ok := db.ToInt64(row["prepayment"]); ok {
  262. prepayment = t
  263. }
  264. return prepayments[prepayment]
  265. case "state":
  266. state := int64(0)
  267. if t, ok := db.ToInt64(row["state"]); ok {
  268. state = t
  269. }
  270. return states[state]
  271. }
  272. return db.ToString(row[field.Name])
  273. }
  274. func (FinalMaterialSettlePC) ExportAfter(data []map[string]interface{}, file *excelize.File) {
  275. ids := []interface{}{}
  276. collects := []interface{}{}
  277. for _, v := range data {
  278. ids = append(ids, v["id"])
  279. collects = append(collects, v["collect_id"])
  280. }
  281. collectMap := map[string]map[string]string{}
  282. ps, err := db.GetModelMap(db.Type(FinalMaterialSettleProcess{}), map[string]interface{}{
  283. "collect_id in": collects,
  284. }, nil)
  285. if err != nil {
  286. return
  287. }
  288. for _, v := range ps {
  289. if _, ok := collectMap[db.ToString(v["collect_id"])]; !ok {
  290. collectMap[db.ToString(v["collect_id"])] = map[string]string{}
  291. }
  292. collectMap[db.ToString(v["collect_id"])][db.ToString(v["type"])] = db.ToString(v["signature"])
  293. }
  294. for i, v := range data {
  295. //file.SetRowHeight("Sheet1", i+2, 40)
  296. if collect, ok := collectMap[db.ToString(v["collect_id"])]; ok {
  297. if signature, ok := collect[db.ToString(2)]; ok && signature != "" {
  298. signature = strings.Replace(signature, "data:image/png;base64,", "", 1)
  299. de, err := base64.StdEncoding.DecodeString(signature)
  300. if err == nil {
  301. cell, _ := excelize.CoordinatesToCellName(20, i+2)
  302. file.AddPictureFromBytes("Sheet1", cell, &excelize.Picture{
  303. Extension: ".png",
  304. File: de,
  305. Format: &excelize.GraphicOptions{AutoFit: true},
  306. })
  307. }
  308. }
  309. if signature, ok := collect[db.ToString(3)]; ok && signature != "" {
  310. signature = strings.Replace(signature, "data:image/png;base64,", "", 1)
  311. de, err := base64.StdEncoding.DecodeString(signature)
  312. if err == nil {
  313. cell, _ := excelize.CoordinatesToCellName(21, i+2)
  314. file.AddPictureFromBytes("Sheet1", cell, &excelize.Picture{
  315. Extension: ".png",
  316. File: de,
  317. Format: &excelize.GraphicOptions{AutoFit: true},
  318. })
  319. }
  320. }
  321. if signature, ok := collect[db.ToString(4)]; ok && signature != "" {
  322. signature = strings.Replace(signature, "data:image/png;base64,", "", 1)
  323. de, err := base64.StdEncoding.DecodeString(signature)
  324. if err == nil {
  325. cell, _ := excelize.CoordinatesToCellName(22, i+2)
  326. file.AddPictureFromBytes("Sheet1", cell, &excelize.Picture{
  327. Extension: ".png",
  328. File: de,
  329. Format: &excelize.GraphicOptions{AutoFit: true},
  330. })
  331. }
  332. }
  333. }
  334. }
  335. }
  336. type FinalMaterialSettleCollect struct {
  337. FinalMaterialSettlePC
  338. }
  339. func (model FinalMaterialSettleCollect) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  340. if shopId, _ := db.ToInt64(data["shop_id"]); shopId == 0 {
  341. s.Where = append(s.Where, "(1!=1)")
  342. }
  343. return model.FinalMaterialSettleMobile.ListPrivilege(c, data, s)
  344. }
  345. type FinalMaterialSettleExport struct {
  346. FinalMaterialSettleMobile
  347. }
  348. func (model FinalMaterialSettleExport) ExportFields() []db.ExportField {
  349. return []db.ExportField{
  350. {
  351. Label: "申请部门",
  352. Name: "shop_name",
  353. },
  354. {
  355. Label: "申请日期",
  356. Name: "created_at",
  357. },
  358. {
  359. Label: "收款单位",
  360. Name: "account_name",
  361. Width: 30,
  362. },
  363. {
  364. Label: "开户银行",
  365. Name: "account_bank",
  366. Width: 20,
  367. },
  368. {
  369. Label: "开户账号",
  370. Name: "account_no",
  371. Width: 30,
  372. },
  373. {
  374. Label: "申请金额",
  375. Name: "dxtotal",
  376. },
  377. {
  378. Label: "小写",
  379. Name: "total",
  380. },
  381. }
  382. }
  383. func ConvertNumToCny(num float64) string {
  384. strnum := strconv.FormatFloat(num*100, 'f', 0, 64)
  385. sliceUnit := []string{"仟", "佰", "拾", "亿", "仟", "佰", "拾", "万", "仟", "佰", "拾", "元", "角", "分"}
  386. // log.Println(sliceUnit[:len(sliceUnit)-2])
  387. s := sliceUnit[len(sliceUnit)-len(strnum) : len(sliceUnit)]
  388. upperDigitUnit := map[string]string{"0": "零", "1": "壹", "2": "贰", "3": "叁", "4": "肆", "5": "伍", "6": "陆", "7": "柒", "8": "捌", "9": "玖"}
  389. str := ""
  390. for k, v := range strnum[:] {
  391. str = str + upperDigitUnit[string(v)] + s[k]
  392. }
  393. reg, err := regexp.Compile(`零角零分$`)
  394. str = reg.ReplaceAllString(str, "整")
  395. reg, err = regexp.Compile(`零角`)
  396. str = reg.ReplaceAllString(str, "零")
  397. reg, err = regexp.Compile(`零分$`)
  398. str = reg.ReplaceAllString(str, "整")
  399. reg, err = regexp.Compile(`零[仟佰拾]`)
  400. str = reg.ReplaceAllString(str, "零")
  401. reg, err = regexp.Compile(`零{2,}`)
  402. str = reg.ReplaceAllString(str, "零")
  403. reg, err = regexp.Compile(`零亿`)
  404. str = reg.ReplaceAllString(str, "亿")
  405. reg, err = regexp.Compile(`零万`)
  406. str = reg.ReplaceAllString(str, "万")
  407. reg, err = regexp.Compile(`零*元`)
  408. str = reg.ReplaceAllString(str, "元")
  409. reg, err = regexp.Compile(`亿零{0, 3}万`)
  410. str = reg.ReplaceAllString(str, "^元")
  411. reg, err = regexp.Compile(`零元`)
  412. str = reg.ReplaceAllString(str, "零")
  413. if err != nil {
  414. log.Fatal(err)
  415. }
  416. return str
  417. }
  418. func (FinalMaterialSettleExport) ExportValue(row map[string]interface{}, rowIndex int, field db.ExportField, data []map[string]interface{}) string {
  419. switch field.Name {
  420. case "created_at":
  421. created_at := int64(0)
  422. if t, ok := db.ToInt64(row["created_at"]); ok {
  423. created_at = t
  424. }
  425. t := time.Unix(created_at, 0)
  426. return t.Format("2006.01.02")
  427. case "dxtotal":
  428. total := float64(0)
  429. if t, ok := db.ToFloat64(row["total"]); ok {
  430. total = t
  431. }
  432. return ConvertNumToCny(total)
  433. }
  434. return db.ToString(row[field.Name])
  435. }
  436. type FinalMaterialSettlePC1 struct {
  437. FinalMaterialSettleMobile
  438. }
  439. func (model FinalMaterialSettlePC1) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} {
  440. orderids := make([]int64, 0)
  441. orderidsMap := make(map[int64][]int64)
  442. for _, v := range list {
  443. ids := make([]int64, 0)
  444. id, _ := db.ToInt64(v["id"])
  445. orders := db.ToString(v["orders"])
  446. s := strings.Split(orders, ",")
  447. for _, i := range s {
  448. if n, ok := db.ToInt64(i); ok {
  449. ids = append(ids, n)
  450. }
  451. }
  452. orderids = append(orderids, ids...)
  453. orderidsMap[id] = ids
  454. }
  455. datas, _ := db.GetModelMap(db.Type(FinalMaterialOrderMobile{}), map[string]interface{}{
  456. fmt.Sprintf("`%s`.`id` in", FinalMaterialOrderMobile{}.TableName()): orderids,
  457. fmt.Sprintf("`%s`.`deleted_at`", FinalMaterialOrderMobile{}.TableName()): 0,
  458. }, nil)
  459. FinalMaterialOrderMobile{}.ListAfter(c, data, datas)
  460. for n, settle := range list {
  461. id, _ := db.ToInt64(settle["id"])
  462. if orderids, ok := orderidsMap[id]; ok {
  463. for _, v := range datas {
  464. orderid, _ := db.ToInt64(v["id"])
  465. is := false
  466. for _, s := range orderids {
  467. if s == orderid {
  468. is = true
  469. break
  470. }
  471. }
  472. if is {
  473. order := make([]map[string]interface{}, 0)
  474. if s, ok := list[n]["order"].([]map[string]interface{}); ok {
  475. order = s
  476. }
  477. order = append(order, v)
  478. list[n]["order"] = order
  479. }
  480. }
  481. }
  482. }
  483. return list
  484. }
  485. func (model FinalMaterialSettlePC1) ExportSpan() []string {
  486. return []string{"order"}
  487. }
  488. func (model FinalMaterialSettlePC1) ExportFields() []db.ExportField {
  489. return []db.ExportField{
  490. {
  491. Label: "ID",
  492. Name: "id",
  493. },
  494. {
  495. Label: "门店",
  496. Name: "shop_name",
  497. },
  498. {
  499. Label: "订单号",
  500. Name: "order.order_no",
  501. Width: 30,
  502. },
  503. {
  504. Label: "工地",
  505. Name: "order.address",
  506. Width: 20,
  507. },
  508. {
  509. Label: "订单金额",
  510. Name: "order.total",
  511. },
  512. {
  513. Label: "订单合计",
  514. Name: "amount",
  515. },
  516. {
  517. Label: "扣款金额",
  518. Name: "deduction",
  519. },
  520. {
  521. Label: "材料商",
  522. Name: "supplier_name",
  523. Width: 20,
  524. },
  525. {
  526. Label: "预付款",
  527. Name: "prepayment",
  528. },
  529. {
  530. Label: "开户名",
  531. Name: "account_name",
  532. Width: 30,
  533. },
  534. {
  535. Label: "开户行",
  536. Name: "account_bank",
  537. Width: 20,
  538. },
  539. {
  540. Label: "账号",
  541. Name: "account_no",
  542. Width: 30,
  543. },
  544. {
  545. Label: "结算金额",
  546. Name: "total",
  547. },
  548. {
  549. Label: "状态",
  550. Name: "state",
  551. },
  552. {
  553. Label: "财务审核",
  554. Name: "",
  555. },
  556. {
  557. Label: "店长审核",
  558. Name: "",
  559. },
  560. {
  561. Label: "财务审核",
  562. Name: "",
  563. },
  564. }
  565. }
  566. func (FinalMaterialSettlePC1) ExportValue(row map[string]interface{}, rowIndex int, field db.ExportField, data []map[string]interface{}) string {
  567. states := []string{"未提交", "工程队长审核", "财务审核", "店长审核", "财务付款", "已完成"}
  568. prepayments := []string{"否", "是"}
  569. switch field.Name {
  570. case "order.address":
  571. worksite := /*db.ToString(v["address"]) + " " +*/ db.ToString(row["order.village"]) + "" + db.ToString(row["order.room_no"])
  572. if worksite == "" {
  573. worksite = db.ToString(row["order.address"])
  574. }
  575. return worksite
  576. case "order.items.num":
  577. return db.ToString(row["order.items.num"]) + " " + db.ToString(row["order.items.unit"])
  578. case "prepayment":
  579. prepayment := int64(0)
  580. if t, ok := db.ToInt64(row["prepayment"]); ok {
  581. prepayment = t
  582. }
  583. return prepayments[prepayment]
  584. case "state":
  585. if state, ok := db.ToInt64(row["state"]); ok {
  586. return states[state]
  587. }
  588. return ""
  589. }
  590. return db.ToString(row[field.Name])
  591. }
  592. func (FinalMaterialSettlePC1) ExportAfter(data []map[string]interface{}, file *excelize.File) {
  593. ids := []interface{}{}
  594. collects := []interface{}{}
  595. for _, v := range data {
  596. ids = append(ids, v["id"])
  597. collects = append(collects, v["collect_id"])
  598. }
  599. collectMap := map[string]map[string]string{}
  600. ps, err := db.GetModelMap(db.Type(FinalMaterialSettleProcess{}), map[string]interface{}{
  601. "collect_id in": collects,
  602. }, nil)
  603. if err != nil {
  604. return
  605. }
  606. for _, v := range ps {
  607. if _, ok := collectMap[db.ToString(v["collect_id"])]; !ok {
  608. collectMap[db.ToString(v["collect_id"])] = map[string]string{}
  609. }
  610. collectMap[db.ToString(v["collect_id"])][db.ToString(v["type"])] = db.ToString(v["signature"])
  611. }
  612. for i, v := range data {
  613. //file.SetRowHeight("Sheet1", i+2, 40)
  614. if collect, ok := collectMap[db.ToString(v["collect_id"])]; ok {
  615. if signature, ok := collect[db.ToString(2)]; ok && signature != "" {
  616. signature = strings.Replace(signature, "data:image/png;base64,", "", 1)
  617. de, err := base64.StdEncoding.DecodeString(signature)
  618. if err == nil {
  619. cell, _ := excelize.CoordinatesToCellName(15, i+2)
  620. file.AddPictureFromBytes("Sheet1", cell, &excelize.Picture{
  621. Extension: ".png",
  622. File: de,
  623. Format: &excelize.GraphicOptions{AutoFit: true},
  624. })
  625. }
  626. }
  627. if signature, ok := collect[db.ToString(3)]; ok && signature != "" {
  628. signature = strings.Replace(signature, "data:image/png;base64,", "", 1)
  629. de, err := base64.StdEncoding.DecodeString(signature)
  630. if err == nil {
  631. cell, _ := excelize.CoordinatesToCellName(16, i+2)
  632. file.AddPictureFromBytes("Sheet1", cell, &excelize.Picture{
  633. Extension: ".png",
  634. File: de,
  635. Format: &excelize.GraphicOptions{AutoFit: true},
  636. })
  637. }
  638. }
  639. if signature, ok := collect[db.ToString(4)]; ok && signature != "" {
  640. signature = strings.Replace(signature, "data:image/png;base64,", "", 1)
  641. de, err := base64.StdEncoding.DecodeString(signature)
  642. if err == nil {
  643. cell, _ := excelize.CoordinatesToCellName(17, i+2)
  644. file.AddPictureFromBytes("Sheet1", cell, &excelize.Picture{
  645. Extension: ".png",
  646. File: de,
  647. Format: &excelize.GraphicOptions{AutoFit: true},
  648. })
  649. }
  650. }
  651. }
  652. }
  653. }
  654. type FinalMaterialSettleCollect1 struct {
  655. FinalMaterialSettlePC1
  656. }
  657. func (model FinalMaterialSettleCollect1) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  658. if shopId, _ := db.ToInt64(data["shop_id"]); shopId == 0 {
  659. s.Where = append(s.Where, "(1!=1)")
  660. }
  661. return model.FinalMaterialSettleMobile.ListPrivilege(c, data, s)
  662. }