admin
2021-07-06 abce02c7a61820f5d580f87364d542e817be429c
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
package com.tejia.lijin.app.ui.mine;
 
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.ShoppingApplication;
import com.tejia.lijin.app.entity.UserInfo;
import com.tejia.lijin.app.ui.BaseActivity;
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
import com.tejia.lijin.app.util.TopStatusSettings;
import com.tejia.lijin.app.util.user.UserUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
/**
 * 订单统计
 */
public class OrderSatisticsActivity extends BaseActivity implements View.OnClickListener {
 
    private TextView tv_left, tv_middle, tv_user_id, tv_all_order_form_num, tv_rebate_order_num,
            tv_share_order_num, tv_invite_order_num;
    //今天
    private TextView tv_all_order_num_today, tv_rebate_order_num_today,
            tv_share_order_num_today, tv_invite_order_num_today;
 
    //昨天
    private TextView tv_all_order_num_yestoday,
            tv_rebate_order_num_yestoday, tv_share_order_num_yestoday, tv_invite_order_num_yestoday;
 
    //本月
    private TextView tv_all_order_num_month,
            tv_rebate_order_num_month, tv_share_order_num_month, tv_invite_order_num_month;
    //上月
    private TextView tv_all_order_num_last_month,
            tv_rebate_order_num_last_month, tv_share_order_num_last_month, tv_invite_order_num_last_month;
 
 
    private TextView tv_filter_all_order, tv_filter_tb_order, tv_filter_jd_order, tv_filter_pdd_order, tv_filter_vip_order, tv_filter_suning_order;
    private FrameLayout fl_filter_all_order, fl_filter_tb_order, fl_filter_jd_order, fl_filter_pdd_order, fl_filter_vip_order, fl_filter_suning_order;
    private View v_filter_all_order, v_filter_tb_order, v_filter_jd_order, v_filter_pdd_order, v_filter_vip_order, v_filter_suning_order;
    private ImageView iv_portrait, iv_level, iv_user_level;
    private DisplayImageOptions options;
    ShapeLoadingDialog dialog;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_statistics);
        TopStatusSettings.setStatusViewAndDeepColor(this);
        initView();
        addListener();
 
        getOrderStatistics();
    }
 
    private void initView() {
        tv_left = findViewById(R.id.tv_top_bar_left);
        tv_middle = findViewById(R.id.tv_top_bar_middle);
        tv_user_id = findViewById(R.id.tv_user_id);
        tv_all_order_form_num = findViewById(R.id.tv_all_order_form_num);
        tv_rebate_order_num = findViewById(R.id.tv_rebate_order_num);
        tv_share_order_num = findViewById(R.id.tv_share_order_num);
        tv_invite_order_num = findViewById(R.id.tv_invite_order_num);
        tv_all_order_num_today = findViewById(R.id.tv_all_order_num_today);
        tv_rebate_order_num_today = findViewById(R.id.tv_rebate_order_num_today);
        tv_share_order_num_today = findViewById(R.id.tv_share_order_num_today);
        tv_invite_order_num_today = findViewById(R.id.tv_invite_order_num_today);
        tv_all_order_num_yestoday = findViewById(R.id.tv_all_order_num_yestoday);
        tv_rebate_order_num_yestoday = findViewById(R.id.tv_rebate_order_num_yestoday);
        tv_share_order_num_yestoday = findViewById(R.id.tv_share_order_num_yestoday);
        tv_invite_order_num_yestoday = findViewById(R.id.tv_invite_order_num_yestoday);
 
        tv_all_order_num_month = findViewById(R.id.tv_all_order_num_month);
        tv_rebate_order_num_month = findViewById(R.id.tv_rebate_order_num_month);
        tv_share_order_num_month = findViewById(R.id.tv_share_order_num_month);
        tv_invite_order_num_month = findViewById(R.id.tv_invite_order_num_month);
 
        tv_all_order_num_last_month = findViewById(R.id.tv_all_order_num_last_month);
        tv_rebate_order_num_last_month = findViewById(R.id.tv_rebate_order_num_last_month);
        tv_share_order_num_last_month = findViewById(R.id.tv_share_order_num_last_month);
        tv_invite_order_num_last_month = findViewById(R.id.tv_invite_order_num_last_month);
 
 
        tv_filter_all_order = findViewById(R.id.tv_filter_all_order);
        tv_filter_tb_order = findViewById(R.id.tv_filter_tb_order);
        tv_filter_jd_order = findViewById(R.id.tv_filter_jd_order);
        tv_filter_pdd_order = findViewById(R.id.tv_filter_pdd_order);
        tv_filter_vip_order = findViewById(R.id.tv_filter_vip_order);
        tv_filter_suning_order = findViewById(R.id.tv_filter_suning_order);
        fl_filter_all_order = findViewById(R.id.fl_filter_all_order);
        fl_filter_tb_order = findViewById(R.id.fl_filter_tb_order);
        fl_filter_jd_order = findViewById(R.id.fl_filter_jd_order);
        fl_filter_pdd_order = findViewById(R.id.fl_filter_pdd_order);
        fl_filter_vip_order = findViewById(R.id.fl_filter_vip_order);
        fl_filter_suning_order = findViewById(R.id.fl_filter_suning_order);
        v_filter_all_order = findViewById(R.id.v_filter_all_order);
        v_filter_tb_order = findViewById(R.id.v_filter_tb_order);
        v_filter_jd_order = findViewById(R.id.v_filter_jd_order);
        v_filter_pdd_order = findViewById(R.id.v_filter_pdd_order);
        v_filter_vip_order = findViewById(R.id.v_filter_vip_order);
        v_filter_suning_order = findViewById(R.id.v_filter_suning_order);
 
 
        iv_portrait = findViewById(R.id.iv_portrait);
        iv_level = findViewById(R.id.iv_level);
        iv_user_level = findViewById(R.id.iv_user_level);
 
        tv_middle.setText("订单统计");
        this.options = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.ic_default_portrait_light)
                .showImageOnFail(R.drawable.ic_default_portrait_light)
                .showImageOnLoading(R.drawable.ic_default_portrait_light)
                .resetViewBeforeLoading(true)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .considerExifParams(true)
                .displayer(new CircleBitmapDisplayer(300))
                .build();
    }
 
    private void addListener() {
        tv_left.setOnClickListener(this);
        iv_user_level.setOnClickListener(this);
        fl_filter_all_order.setOnClickListener(this);
        fl_filter_tb_order.setOnClickListener(this);
        fl_filter_jd_order.setOnClickListener(this);
        fl_filter_pdd_order.setOnClickListener(this);
        fl_filter_vip_order.setOnClickListener(this);
        fl_filter_suning_order.setOnClickListener(this);
    }
 
    /**
     * 获取订单统计数据
     */
    private void getOrderStatistics() {
        if (null == dialog)
            dialog = new ShapeLoadingDialog.Builder(OrderSatisticsActivity.this).build();
        dialog.show();
        ShoppingApi.getOrderStatistics(this, UserUtil.getUid(ShoppingApplication.application), 0, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() {
                    }.getType());
                    Glide.with(OrderSatisticsActivity.this).load(info.getRankIcon()).into(iv_level);
                    ImageLoader.getInstance().displayImage(info.getPortrait(), iv_portrait, options);
                    Glide.with(OrderSatisticsActivity.this).load(info.getRankNamePicture()).into(iv_user_level);
                    tv_user_id.setText("ID:" + info.getId());
                    tv_all_order_form_num.setText("共" + jsonObject.optJSONObject("data").optString("total") + "单");
                    tv_rebate_order_num.setText(jsonObject.optJSONObject("data").optString("self"));
                    tv_share_order_num.setText(jsonObject.optJSONObject("data").optString("shared"));
                    tv_invite_order_num.setText(jsonObject.optJSONObject("data").optString("invite"));
 
                    initDateOrderData(jsonObject);
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                dialog.dismiss();
            }
        });
 
    }
 
    /**
     * 设置日期订单统计数据
     *
     * @param jsonObject
     */
    private void initDateOrderData(JSONObject jsonObject) {
        tv_all_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("total"));
        tv_rebate_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("self"));
        tv_share_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("shared"));
        tv_invite_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("invite"));
 
        tv_all_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("total"));
        tv_rebate_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("self"));
        tv_share_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("shared"));
        tv_invite_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("invite"));
 
 
        tv_all_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("total"));
        tv_rebate_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("self"));
        tv_share_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("shared"));
        tv_invite_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("invite"));
 
        tv_all_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("total"));
        tv_rebate_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("self"));
        tv_share_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("shared"));
        tv_invite_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("invite"));
    }
 
    /*
    订单统计:今日、昨日
     */
    private void getNearOrderNum(int goodsType) {
        if (null == dialog)
            dialog = new ShapeLoadingDialog.Builder(OrderSatisticsActivity.this).build();
        dialog.show();
 
        ShoppingApi.getOrderStatistics(this, UserUtil.getUid(ShoppingApplication.application), goodsType, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    initDateOrderData(jsonObject);
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                dialog.dismiss();
            }
        });
 
 
    }
 
    private void orderPlatformFilter(int goodsType) {
        tv_filter_all_order.setTextColor(goodsType == 0 ? getResources()
                .getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
        v_filter_all_order.setVisibility(goodsType == 0 ? View.VISIBLE : View.GONE);
        tv_filter_tb_order.setTextColor(goodsType == 1 ? getResources()
                .getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
        v_filter_tb_order.setVisibility(goodsType == 1 ? View.VISIBLE : View.GONE);
        tv_filter_jd_order.setTextColor(goodsType == 2 ? getResources()
                .getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
        v_filter_jd_order.setVisibility(goodsType == 2 ? View.VISIBLE : View.GONE);
        tv_filter_pdd_order.setTextColor(goodsType == 3 ? getResources()
                .getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
        v_filter_pdd_order.setVisibility(goodsType == 3 ? View.VISIBLE : View.GONE);
 
        tv_filter_vip_order.setTextColor(goodsType == 4 ? getResources()
                .getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
        v_filter_vip_order.setVisibility(goodsType == 4 ? View.VISIBLE : View.GONE);
 
        tv_filter_suning_order.setTextColor(goodsType == 5 ? getResources()
                .getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
        v_filter_suning_order.setVisibility(goodsType == 5 ? View.VISIBLE : View.GONE);
 
 
        if (goodsType == 0) {
            getOrderStatistics();
        } else {
            getNearOrderNum(goodsType);
        }
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_top_bar_left:
                finish();
                break;
            case R.id.iv_user_level:
                startActivity(new Intent(OrderSatisticsActivity.this, AccountGradeActivity.class));
                break;
            case R.id.fl_filter_all_order:
                orderPlatformFilter(0);
                break;
            case R.id.fl_filter_tb_order:
                orderPlatformFilter(1);
                break;
            case R.id.fl_filter_jd_order:
                orderPlatformFilter(2);
                break;
            case R.id.fl_filter_pdd_order:
                orderPlatformFilter(3);
                break;
            case R.id.fl_filter_vip_order:
                orderPlatformFilter(4);
                break;
            case R.id.fl_filter_suning_order:
                orderPlatformFilter(5);
                break;
        }
    }
}