admin
2020-06-20 9cd218f0bebc19b86efeca2b33abe3adf093990c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Text;
using WindowsFormsApp1.entity;
using WindowsFormsApp1.utils;
 
namespace WindowsFormsApp1
{
    class DocUtil
    {
 
        public static List<FirstOrderSubInfo> ydGoodsList=new List<FirstOrderSubInfo>();
        public static List<FirstOrderSubInfo> spGoodsList = new List<FirstOrderSubInfo>();
 
        public static void AddYDGoods(FirstOrderSubInfo info) {
            foreach (FirstOrderSubInfo i in ydGoodsList) {
                if (i.GoodsId == info.GoodsId)
                    return;
            }
            ydGoodsList.Add(info);
        }
 
        public static void AddYDGoods(List<FirstOrderSubInfo> infoList)
        {
            if(infoList!=null)
            foreach (FirstOrderSubInfo i in infoList)
            {
                    AddYDGoods(i);
            }
        }
 
 
        public static void AddSPGoods(FirstOrderSubInfo info)
        {
            foreach (FirstOrderSubInfo i in spGoodsList)
            {
                if (i.GoodsId == info.GoodsId)
                    return;
            }
            spGoodsList.Add(info);
        }
 
 
        public static void AddSPGoods(List<FirstOrderSubInfo> infoList)
        {
            foreach (FirstOrderSubInfo i in infoList)
            {
                AddSPGoods(i);
            }
        }
 
 
        //表达式是否正确
        public static bool IsRight(String doc) {
            //匹配两个中括号
           int start1=  doc.IndexOf("[");
            if (start1 <= -1) {
                return false;
            }
 
           int end1 = doc.IndexOf("]", start1);
           if (end1 <= -1) {
                return false;
           }
 
            int start2 = doc.IndexOf("[", end1);
            if (start2 <= -1)
            {
                return false;
            }
 
            int end2 = doc.IndexOf("]", start2);
            if (end2 <= -1)
            {
                return false;
            }
 
            return true;
        }
 
        /**
         * 获取模板
         * 返回引单与实拍单的模板
         */
        public static String[] GetOutSideTemplate(String doc) {
            //匹配两个中括号
            int start1 = doc.IndexOf("[");
            if (start1 <= -1)
            {
                return null;
            }
 
            int end1 = doc.IndexOf("]", start1);
            if (end1 <= -1)
            {
                return null;
            }
 
            int start2 = doc.IndexOf("[", end1);
            if (start2 <= -1)
            {
                return null;
            }
 
            int end2 = doc.IndexOf("]", start2);
            if (end2 <= -1)
            {
                return null;
            }
            String[] sts = new string[] { doc.Substring(start1+1, end1-(start1+1)), doc.Substring(start2+1, end2-(start2+1)) };
 
            return sts;
        }
 
        //生成文案
        public static String BuildDoc() {
            String courseUrl = "http://www.baidu.com";
             Config config =     SQLiteDataBaseUtil.getInstance().GetConfig("sdlj_doc_template_own");
            if (config == null) {
                config = SQLiteDataBaseUtil.getInstance().GetConfig("sdlj_doc_template");
            }
 
            String template = config.Value;
 
            String[] sts= GetOutSideTemplate(template);
            if (sts == null||sts.Length<2)
                return null;
            //引单商品填充
            StringBuilder ydSt = new StringBuilder();
            for (int i = 0; i < ydGoodsList.Count; i++)
            {
                ydSt.Append(sts[0].Replace("{引单商品链接}", ydGoodsList[i].ItemUrl).Replace("{引单礼金面额}", ydGoodsList[i].LijinAmount).Replace("{引单教程链接}", courseUrl).Replace("{引单商品口令}", ydGoodsList[i].Tkl).Replace("{链接位置}", (i + 1) + ""));
                if(i< ydGoodsList.Count-1)
                    ydSt.Append("\r\n");
            }
 
            StringBuilder spSt = new StringBuilder();
 
            for (int i = 0; i < spGoodsList.Count; i++)
            {
                spSt.Append(sts[1].Replace("{实拍商品到手价}", spGoodsList[i].ActualPrice).Replace("{实拍商品标题}", spGoodsList[i].Title).Replace("{实拍商品链接}", spGoodsList[i].ItemUrl).Replace("{实拍商品口令}", spGoodsList[i].Tkl) + "\r\n");
            }
 
            return template.Replace("[" + sts[0] + "]", ydSt.ToString()).Replace("[" + sts[1] + "]", spSt.ToString());
        }
    }
}