admin
2022-08-09 399ac289f80b7a40aa4210341db6b447cacdcf14
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
package com.tejia.lijin.app.ui.mine;
 
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.tejia.lijin.app.ShoppingApplication;
import com.tejia.lijin.app.util.user.UserUtil;
import com.wpc.library.util.common.StringUtils;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.callBack.GeneralBackCallback;
import com.tejia.lijin.app.ui.BaseActivity;
import com.tejia.lijin.app.ui.dialog.GiveRedpacketDialog;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.util.KeFuUtil;
import com.tejia.lijin.app.util.MultipleContentPopUps;
import com.tejia.lijin.app.util.ToolUtil;
import com.tejia.lijin.app.util.TopStatusSettings;
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
 
import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 推广红包
 */
 
public class PromotionRedenvelopeActivity extends BaseActivity implements View.OnClickListener {
    private TextView Cs;//跳转客服
    private ImageView help;//帮助
    private TextView tv_left, tv_middle;//返回 标题
    private TextView promotionredenvelop_rebate;//红包金额
    private LinearLayout promotionredenvelop_recordingsum;//创建记录
    private TextView promotionredenvelop_todaymonth;//今日获得
    private TextView promotionredenvelop_todaymonth2;//今日消耗
    private TextView promotionredenvelop_Yestermonth;//昨日获得
    private TextView promotionredenvelop_Yestermonth2;//昨日消耗
    private TextView promotionredenvelop_thismonth;//本月获得
    private TextView promotionredenvelop_thismonth2;//本月消耗
    private TextView promotionredenvelop_onmonth;//今日获得
    private TextView promotionredenvelop_onmonth2;//今日消耗
    private TextView tv_top_bar_right;
    private TextView promotionredenvelop_use;//去使用
    private TextView promotionredenvelop_send;//赠送
    private LinearLayout ll_notice;//小黄条
    private TextView tv_notice_content;
    private ImageView iv_close;
    private TextView tv_available_withdrawal;
    private TextView tv_send_count;//赠送数量
 
 
    //赚取红包链接
    private String hongBaoLink;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_promotionredenvelope);
        TopStatusSettings.setStatusViewAndDeepColor(this);
        inintview();
        clickListener();
        getAppPageNotification();//小黄条
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        getcountHongBao();// 红包获得及使用情况
    }
 
    private void inintview() {
        ll_notice = findViewById(R.id.ll_notice);
        tv_notice_content = findViewById(R.id.tv_notice_content);
        iv_close = findViewById(R.id.iv_close);
        Cs = findViewById(R.id.promotionredenvelop_cs);
        help = findViewById(R.id.promotionredenvelop_help);
        tv_left = findViewById(R.id.tv_top_bar_left);
        tv_middle = findViewById(R.id.tv_top_bar_middle);
        tv_top_bar_right = findViewById(R.id.tv_top_bar_right);
        promotionredenvelop_rebate = findViewById(R.id.promotionredenvelop_rebate);
        promotionredenvelop_recordingsum = findViewById(R.id.promotionredenvelop_recordingsum);
        promotionredenvelop_todaymonth = findViewById(R.id.promotionredenvelop_todaymonth);
        promotionredenvelop_todaymonth2 = findViewById(R.id.promotionredenvelop_todaymonth2);
        promotionredenvelop_Yestermonth = findViewById(R.id.promotionredenvelop_Yestermonth);
        promotionredenvelop_Yestermonth2 = findViewById(R.id.promotionredenvelop_Yestermonth2);
        promotionredenvelop_thismonth = findViewById(R.id.promotionredenvelop_thismonth);
        promotionredenvelop_thismonth2 = findViewById(R.id.promotionredenvelop_thismonth2);
        promotionredenvelop_onmonth = findViewById(R.id.promotionredenvelop_onmonth);
        promotionredenvelop_onmonth2 = findViewById(R.id.promotionredenvelop_onmonth2);
        promotionredenvelop_use = findViewById(R.id.promotionredenvelop_use);
        promotionredenvelop_send = findViewById(R.id.promotionredenvelop_send);
        tv_available_withdrawal = findViewById(R.id.tv_available_withdrawal);
        tv_send_count = findViewById(R.id.tv_send_count);
        Spanned spanned = Html.fromHtml("如有疑问,请咨询<font color= #FF3333>人工客服</font>>");
        Cs.setText(spanned);
        tv_middle.setText("红包");
        tv_top_bar_right.setVisibility(View.VISIBLE);
        tv_top_bar_right.setText("明细");
        ViewGroup.LayoutParams params = tv_top_bar_right.getLayoutParams();
        ViewGroup.MarginLayoutParams marginParams = null;
        //获取view的margin设置参数
        if (params instanceof ViewGroup.MarginLayoutParams) {
            marginParams = (ViewGroup.MarginLayoutParams) params;
        } else {
            //不存在时创建一个新的参数
            marginParams = new ViewGroup.MarginLayoutParams(params);
        }
        //设置margin
        marginParams.setMargins(0, 0, 30, 0);
        tv_top_bar_right.setLayoutParams(marginParams);
 
        findViewById(R.id.ll_make_hongbao).setVisibility(View.GONE);
    }
 
    private void clickListener() {
        Cs.setOnClickListener(this);
        help.setOnClickListener(this);
        tv_left.setOnClickListener(this);
        promotionredenvelop_recordingsum.setOnClickListener(this);
        tv_top_bar_right.setOnClickListener(this);
        promotionredenvelop_use.setOnClickListener(this);
        promotionredenvelop_send.setOnClickListener(this);
        findViewById(R.id.ll_make_hongbao).setOnClickListener(this);
        findViewById(R.id.ll_send_history).setOnClickListener(this);
    }
 
    MultipleContentPopUps ups;//多内容弹窗
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //客服
            case R.id.promotionredenvelop_cs:
                KeFuUtil.jumpKeFu(this, "推广红包");
 
                break;
            //帮助
            case R.id.promotionredenvelop_help:
                //此问号,是一个H5网页,问题由阿瑞提供;
                if (helpLink != null) {
                    Intent intent1 = new Intent(this, ShareBrowserActivity.class);
                    intent1.putExtra("title", "推广红包是什么?");
                    intent1.putExtra("url", helpLink);
                    startActivity(intent1);
                }
                break;
            //返回
            case R.id.tv_top_bar_left:
                finish();
                break;
            //使用红包
            case R.id.promotionredenvelop_recordingsum:
                if (useLink != null) {
                    Intent intent1 = new Intent(this, ShareBrowserActivity.class);
                    intent1.putExtra("url", useLink);
                    startActivity(intent1);
                }
                break;
            //明细
            case R.id.tv_top_bar_right:
                Intent intent3 = new Intent(this, PromotionDetailActivity.class);
                startActivity(intent3);
                break;
            //提现
            case R.id.promotionredenvelop_use:
                if (ups != null) {
                    ups.dialog_dismiss();
                    ups = null;
                }
                if (StringUtils.isEmpty(balance) || StringUtils.isEmpty(giveMin)) {
                    Toast.makeText(PromotionRedenvelopeActivity.this, "未获取到红包余额,请稍后再试", Toast.LENGTH_LONG).show();
                    break;
                }
                // 提现金额 不足最低提现
                if (Double.parseDouble(extractBanlenMin) > Double.parseDouble(balance)) {
                    ups = new MultipleContentPopUps(this);
                    ups.onShowDialogDual("红包提现", extractShortage, "使用红包"
                            , useLink,
                            "web", null, null,
                            "知道了", "", "", null, null);
                } else {
                    GiveRedpacketDialog.Builder builder = new GiveRedpacketDialog.Builder(this);
                    builder.setTitle("红包提现")
                            .setMessage(extractDesc)
                            .setBalance(balance)
                            .setPositiveButton("确认提现", new GeneralBackCallback() {
                                @Override
                                public void onSuccess(Object var1, Object var2) {
                                    if (Double.parseDouble(var2.toString()) < Double.parseDouble(extractMin) ||
                                            Double.parseDouble(var2.toString()) > Double.parseDouble(extractMax)) {
                                        Toast.makeText(PromotionRedenvelopeActivity.this, "红包提现至少" + extractMin + "元至多" + extractMax + "元", Toast.LENGTH_LONG).show();
                                        return;
                                    }
                                    ((Dialog) var1).dismiss();
                                    ShoppingApi.exchangeCash(PromotionRedenvelopeActivity.this, UserUtil.getUid(ShoppingApplication.application), var2.toString(), new BasicTextHttpResponseHandler() {
                                        @Override
                                        public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                                            super.onSuccessPerfect(statusCode, headers, jsonObject);
                                            if (jsonObject.optInt("code") == 0) {
                                                Toast.makeText(PromotionRedenvelopeActivity.this, jsonObject.optString("data"), Toast.LENGTH_LONG).show();
                                                getcountHongBao();
                                            } else {
                                                Toast.makeText(PromotionRedenvelopeActivity.this, jsonObject.optString("msg"),
                                                        Toast.LENGTH_LONG).show();
                                            }
                                        }
                                    });
                                }
                            });
                    Dialog dialog = builder.create();
                    dialog.setCanceledOnTouchOutside(false);
                    dialog.show();
                }
                break;
            //赠送
            case R.id.promotionredenvelop_send:
                if (StringUtils.isEmpty(balance) || StringUtils.isEmpty(giveMin)) {
                    Toast.makeText(PromotionRedenvelopeActivity.this, "未获取到红包余额,请稍后再试",
                            Toast.LENGTH_LONG).show();
                    break;
                }
                if (Double.parseDouble(balance) < Double.parseDouble(giveMin)) {
                    Toast.makeText(PromotionRedenvelopeActivity.this, "红包余额不足" + giveMin + "元,不可赠送",
                            Toast.LENGTH_LONG).show();
                    break;
                }
                GiveRedpacketDialog.Builder builder = new GiveRedpacketDialog.Builder(this);
                builder.setTitle("设置赠送金额")
                        .setMessage(giveDesc)
                        .setBalance(balance)
                        .setGiveMin(giveMin)
                        .setGiveMax(giveMax)
                        .setHint("赠送金额输入有误")
                        .setPositiveButton("确认赠送", new GeneralBackCallback() {
                            @Override
                            public void onSuccess(Object var1, Object var2) {
                                if (Double.parseDouble(var2.toString()) < Double.parseDouble(giveMin) ||
                                        Double.parseDouble(var2.toString()) > Double.parseDouble(giveMax)) {
                                    Toast.makeText(PromotionRedenvelopeActivity.this, "赠送红包金额至少" + giveMin + "元至多" + giveMax + "元", Toast.LENGTH_LONG).show();
                                    return;
                                }
                                ((Dialog) var1).dismiss();
                                ShoppingApi.giveTLJ(PromotionRedenvelopeActivity.this, UserUtil.getUid(ShoppingApplication.application), var2.toString(), new BasicTextHttpResponseHandler() {
                                    @Override
                                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                                        super.onSuccessPerfect(statusCode, headers, jsonObject);
                                        if (jsonObject.optInt("code") == 0) {
//                                            Toast.makeText(PromotionRedenvelopeActivity.this, "赠送成功", Toast.LENGTH_LONG).show();
 
 
                                            ClipboardUtil.copy(getApplicationContext(), jsonObject.optString("data"));
                                            Toast.makeText(PromotionRedenvelopeActivity.this, "分享口令,已复制成功",
                                                    Toast.LENGTH_LONG).show();
 
                                            getcountHongBao();
                                        } else {
                                            Toast.makeText(PromotionRedenvelopeActivity.this, jsonObject.optString("msg"),
                                                    Toast.LENGTH_LONG).show();
                                        }
                                    }
                                });
                            }
                        });
                Dialog dialog = builder.create();
                dialog.setCanceledOnTouchOutside(false);
                dialog.show();
                break;
 
            case R.id.ll_make_hongbao:
                startActivity(new Intent(this, ShareBrowserActivity.class).putExtra("url", hongBaoLink));
                break;
            case R.id.ll_send_history:
                startActivity(new Intent(this, HongBaoSendRecordActivity.class));
                break;
            default:
                break;
        }
    }
 
    private String helpLink;// 帮助链接
    private String balance;
    private String giveDesc;
    private String giveMin;
    private String giveMax;
    private String useLink;// 使用连接
    private String extractBanlenMin;//   提现最低余额限制\
    private String extractMin;//   每次提现最少金额
    private String extractMax;//   每次提现最大金额
    private String extractDesc;// 提现提示
    private List<String> extractShortage = new ArrayList<>();// 提现不足提示
 
 
    /**
     * 统计红包获得及使用情况
     */
    private void getcountHongBao() {
        ShoppingApi.getcountHongBao(this, UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    balance = data.optString("balance");
                    giveDesc = data.optString("giveDesc");
                    giveMin = data.optString("giveMin");
                    giveMax = data.optString("giveMax");
                    // 帮助链接
                    helpLink = data.optString("helpLink");
                    //赚取红包链接
                    hongBaoLink = data.optString("winLink");
                    int sendCount = data.optInt("giveTotal");
                    if (sendCount <= 0) {
                        tv_send_count.setText("");
                    } else
                        tv_send_count.setText(String.format("共%s条", sendCount));
                    // 使用连接
                    useLink = data.optString("useLink");
                    // 提现最低余额限制
                    extractBanlenMin = data.optString("extractBanlenMin");
                    // 提现提示
                    extractDesc = data.optString("extractDesc");
                    // 每次提现最少金额
                    extractMin = data.optString("extractMin");
                    //  每次提现最大金额
                    extractMax = data.optString("extractMax");
                    // 提现不足提示
                    JSONArray array = data.optJSONArray("extractShortage");
                    extractShortage.clear();
                    if (array != null)
                        for (int i = 0; i < array.length(); i++) {
                            extractShortage.add(array.get(i).toString());
                        }
 
                    promotionredenvelop_rebate.setText("¥ " + balance);// 余额
                    promotionredenvelop_todaymonth.setText("¥ " + data.optString("todayWin")); // 今日获得
                    promotionredenvelop_todaymonth2.setText("¥ " + data.optString("todayUse")); // 今日
                    promotionredenvelop_Yestermonth.setText("¥ " + data.optString("yesterdayWin")); // 昨日获得
                    promotionredenvelop_Yestermonth2.setText("¥ " + data.optString("yesterdayUse")); //
                    promotionredenvelop_thismonth.setText("¥ " + data.optString("thisMonthWin")); // 本月获得
                    promotionredenvelop_thismonth2.setText("¥ " + data.optString("thisMonthUse")); //
                    promotionredenvelop_onmonth.setText("¥ " + data.optString("lastMonthWin")); // 上月获得
                    promotionredenvelop_onmonth2.setText("¥ " + data.optString("lastMonthUse")); //
 
                    String extractingInfo = data.optString("extractingInfo");
                    if (!StringUtils.isEmpty(extractingInfo)) {
                        tv_available_withdrawal.setText(extractingInfo);
                    } else {
                        tv_available_withdrawal.setText("");
                    }
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
 
            }
        });
    }
 
    private String TYPE = "hongbao_balance";//"hongbao_balance";
 
    /*************小黄条*******/
    private void getAppPageNotification() {
        ShoppingApi.getAppPageNotification(this, TYPE, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                ToolUtil.setAppPageNotification(ll_notice, tv_notice_content, iv_close, jsonObject);
            }
        });
    }
 
    @Override
    protected void onPause() {
        super.onPause();
        if (ups != null) {
            ups.dialog_dismiss();
            ups = null;
        }
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (ups != null) {
            ups.dialog_dismiss();
            ups = null;
        }
    }
}