Просмотр исходного кода

商城优惠券兑换接口添加

zengjiebin лет назад: 7
Родитель
Сommit
70f1d191b6

+ 15 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -1571,5 +1571,20 @@ public interface ApiService {
     @GET(ApiKey.getPackageVersion)
     Observable<BaseMessage> getPackageVersion(@Query("package_name") String package_name, @Query("type") String type, @Query("version") int version);
 //---------------------------end 插件配置相关-------------------------------------
+//---------------------------start 商城相关-------------------------------------
+    /**
+     * 领取商城优惠券
+     * type * integer (query) 代金券类型 1:新手任务完成领取 2:h5任务领取 默认1
+     * amount * (query) 代金券金额
+     */
+    @POST("app/yf_shop/receive_coupons")
+    Observable<BaseMessage> postYfShopReceiveCoupons(@Query("type") int type, @Query("amount") float amount);
+    /**
+     * 查询领取商城优惠券
+     * type * integer (query) 代金券类型 1:新手任务完成领取 2:h5任务领取 默认1
+     */
+    @GET("app/yf_shop/receive_coupons/check")
+    Observable<BaseMessage> getYfShopReceiveCouponsCheck(@Query("type") int type);
+//---------------------------end 商城相关-------------------------------------
 
 }

+ 35 - 0
app/src/main/java/com/sheep/gamegroup/module/yf_shop/model/ReceiveCouponsCheckResq.java

@@ -0,0 +1,35 @@
+package com.sheep.gamegroup.module.yf_shop.model;
+
+/**
+ * Created by realicing on 2018/12/24.
+ * realicing@sina.com
+ * 查询领取商城优惠券
+ *
+ * amount:	number ($double)
+ * 代金券领取金额
+ * status:	integer ($int64)
+ * 代金券领取状态 1:已领取 2:未领取
+ */
+public class ReceiveCouponsCheckResq {
+    private float amount;
+    private int status;
+
+    public float getAmount() {
+        return amount;
+    }
+
+    public void setAmount(float amount) {
+        this.amount = amount;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+//    代金券类型 1:新手任务完成领取 2:h5任务领取 默认1
+    public static final int TYPE_NEW_TASK = 1;//新手任务完成领取
+    public static final int TYPE_H5_TASK = 2;//h5任务领取
+}

+ 41 - 0
app/src/main/java/com/sheep/gamegroup/module/yf_shop/model/ReceiveCouponsResp.java

@@ -0,0 +1,41 @@
+package com.sheep.gamegroup.module.yf_shop.model;
+
+/**
+ * Created by realicing on 2018/12/24.
+ * realicing@sina.com
+ * 领取商城优惠券
+ *
+ * amount:	number ($double) 代金券金额
+ * buy_url:	string 购买地址
+ * type:	integer ($int64) 代金券类型 1:新手任务完成领取 2:h5任务领取
+ */
+public class ReceiveCouponsResp {
+
+    private float amount;
+    private String buy_url;
+    private int type;
+
+    public float getAmount() {
+        return amount;
+    }
+
+    public void setAmount(float amount) {
+        this.amount = amount;
+    }
+
+    public String getBuy_url() {
+        return buy_url;
+    }
+
+    public void setBuy_url(String buy_url) {
+        this.buy_url = buy_url;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public void setType(int type) {
+        this.type = type;
+    }
+}

+ 13 - 0
app/src/main/java/com/sheep/gamegroup/util/ApiJSONUtil.java

@@ -22,10 +22,12 @@ public class ApiJSONUtil {
     public static final int COMMENT_TYPE_GAME = 1;
     public static final int COMMENT_TYPE_ARTICLE = 2;
     public static final int COMMENT_TYPE_VIDEO = 3;
+
     @IntDef({COMMENT_TYPE_GAME, COMMENT_TYPE_ARTICLE, COMMENT_TYPE_VIDEO})
     @Retention(RetentionPolicy.SOURCE)
     public @interface COMMENT_TYPE {
     }
+
     /**
      * 用户游戏评论
      * CommentType       int8    `description:"评论类型 1:游戏 2:资讯" json:"comment_type"`
@@ -57,6 +59,7 @@ public class ApiJSONUtil {
         jsonObject.put("content", content);
         return SheepApp.getInstance().getNetComponent().getApiService().postGameUserUserComment(jsonObject);
     }
+
     /**
      * 在自己的评论详情中,自己去回复 用户对自己的评论
      * UserCommentReq{
@@ -71,4 +74,14 @@ public class ApiJSONUtil {
         return SheepApp.getInstance().getNetComponent().getApiService().postGameUserReplyComment(jsonObject);
     }
 
+    /**
+     * @param type
+     * @param amount
+     */
+    public static Observable<BaseMessage> postYfShopReceiveCoupons(int type, float amount) {
+        return SheepApp.getInstance().getNetComponent().getApiService().postYfShopReceiveCoupons(type, amount)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread());
+
+    }
 }

+ 61 - 31
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -52,6 +52,7 @@ import com.sheep.gamegroup.module.login.ChangePasswordAct;
 import com.sheep.gamegroup.module.login.LoginAct;
 import com.sheep.gamegroup.module.plugin.model.Plugin;
 import com.sheep.gamegroup.module.plugin.util.SheepPluginUtil;
+import com.sheep.gamegroup.module.yf_shop.model.ReceiveCouponsCheckResq;
 import com.sheep.gamegroup.util.share.ShareLinkConfig;
 import com.sheep.gamegroup.view.activity.ActApprenticeRedPacket;
 import com.sheep.gamegroup.view.activity.ActArticleComment;
@@ -165,6 +166,9 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 
+import io.reactivex.Observable;
+import io.reactivex.ObservableEmitter;
+import io.reactivex.ObservableOnSubscribe;
 import io.reactivex.ObservableSource;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.functions.Function;
@@ -965,8 +969,8 @@ public class Jump2View {
         }
         //检查url是否是http开头并添加
         if (!url.startsWith("http")) {
-            if(url.contains("://")){
-                if(tryGotoDeepLink(url)){
+            if (url.contains("://")) {
+                if (tryGotoDeepLink(url)) {
                     return;
                 }
             } else {
@@ -979,8 +983,10 @@ public class Jump2View {
         intent.putExtra(IJumpWeb.KEY_NEEDJSINTERACT, true);
         context.startActivity(intent);
     }
+
     /**
      * 尝试通过深度链接跳转应用
+     *
      * @param url
      */
     public boolean tryGotoDeepLink(String url) {
@@ -998,6 +1004,7 @@ public class Jump2View {
             return false;
         }
     }
+
     /**
      * 跳到web页面
      *
@@ -1013,8 +1020,8 @@ public class Jump2View {
         }
         //检查url是否是http开头并添加
         if (!url.startsWith("http")) {
-            if(url.contains("://")){
-                if(tryGotoDeepLink(url)){
+            if (url.contains("://")) {
+                if (tryGotoDeepLink(url)) {
                     return;
                 }
             } else {
@@ -1496,36 +1503,59 @@ public class Jump2View {
         if (SysAppUtil.isNewSmallSheep()) {//新版本只显示引导页面,不展示弹窗和开屏广告
             return;
         }
-        CommonUtil.getInstance().callActionWithUserInfo(new Action1<UserEntity>() {
-            @Override
-            public void call(UserEntity userEntity) {
-                if(userEntity.alreadyFinishAllNewTask() && !userEntity.alreadyExchangeCoupon()){//已经完成所有新手任务且没有兑换过优惠券时,显示商城优惠券
-                    Advertising advertising = new Advertising();
-                    advertising.setName("兑换商城优惠券,优惠多多");
+        CommonUtil.getInstance().callActionWithUserInfo(userEntity ->
+                Observable.create((ObservableOnSubscribe<Boolean>) emitter -> {
+                    if (userEntity.alreadyFinishAllNewTask()) {//已经完成所有新手任务
+                        //没有兑换过优惠券时,显示商城优惠券
+                        SheepApp.getInstance().getNetComponent().getApiService().getYfShopReceiveCouponsCheck(ReceiveCouponsCheckResq.TYPE_NEW_TASK)
+                                .subscribeOn(Schedulers.io())
+                                .observeOn(AndroidSchedulers.mainThread())
+                                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                                    @Override
+                                    public void onNext(BaseMessage baseMessage) {
+                                        emitter.onNext(false);
+                                    }
+
+                                    @Override
+                                    public void onError(BaseMessage baseMessage) {
+                                        emitter.onNext(true);
+                                    }
+                                });
+                    } else {
+                        emitter.onNext(true);
+                    }
+                }).subscribeOn(Schedulers.io())
+                        .observeOn(AndroidSchedulers.mainThread())
+                        .subscribe(new AbsObserver<Boolean>() {
+                            @Override
+                            public void onNext(Boolean showAd) {
+                                if (showAd) {//显示开屏广告
+                                    SheepApp.getInstance().getNetComponent().getApiService().getAdvertising(2)
+                                            .subscribeOn(Schedulers.io())
+                                            .observeOn(AndroidSchedulers.mainThread())
+                                            .subscribe(new SheepSubscriber<BaseMessage>(activity) {
+                                                @Override
+                                                public void onNext(BaseMessage baseMessage) {
+                                                    Advertising advertising = baseMessage.getData(Advertising.class);
+                                                    ViewUtil.showHalfScreenAd(activity, advertising, container);
+                                                }
+
+                                                @Override
+                                                public void onError(BaseMessage baseMessage) {
+                                                    tryShowReservation(activity);
+                                                }
+                                            });
+                                } else {//显示商城
+                                    Advertising advertising = new Advertising();
+                                    advertising.setName("兑换商城优惠券,优惠多多");
 //                    advertising.setDesc("点击兑换商城优惠券,优惠多多");
-                    advertising.setDisplay_type(Advertising.TYPE_IMG);
-                    advertising.setDisplay_src(ViewUtil.getNetImgByName("homepage_xinshourw"));
-                    advertising.setLinkType(IDConstant.JUMP_EXCHANGE_COUPON);
-                    ViewUtil.showHalfScreenAd(activity, advertising, container);
-                } else {
-                    SheepApp.getInstance().getNetComponent().getApiService().getAdvertising(2)
-                            .subscribeOn(Schedulers.io())
-                            .observeOn(AndroidSchedulers.mainThread())
-                            .subscribe(new SheepSubscriber<BaseMessage>(activity) {
-                                @Override
-                                public void onNext(BaseMessage baseMessage) {
-                                    Advertising advertising = baseMessage.getData(Advertising.class);
+                                    advertising.setDisplay_type(Advertising.TYPE_IMG);
+                                    advertising.setDisplay_src(ViewUtil.getNetImgByName("homepage_xinshourw"));
+                                    advertising.setLinkType(IDConstant.JUMP_EXCHANGE_COUPON);
                                     ViewUtil.showHalfScreenAd(activity, advertising, container);
                                 }
-
-                                @Override
-                                public void onError(BaseMessage baseMessage) {
-                                    tryShowReservation(activity);
-                                }
-                            });
-                }
-            }
-        });
+                            }
+                        }));
     }
 
     public void tryShowReservation(final Activity activity) {

+ 6 - 5
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -442,11 +442,12 @@ public class SysAppUtil {
                 e.printStackTrace();
             }
         }
-        if(TestUtil.isSheep()) {
-            checkUpdateNewVersion(activity, ignoreMd5, action1);
-        } else if(!TestUtil.isDev()) {
-            TestUtil.checkUpdateFromJenkins(activity, ignoreMd5, action1);
-        }
+        checkUpdateNewVersion(activity, ignoreMd5, action1);
+//        if(TestUtil.isSheep()) {
+//            checkUpdateNewVersion(activity, ignoreMd5, action1);
+//        } else if(!TestUtil.isDev()) {
+//            TestUtil.checkUpdateFromJenkins(activity, ignoreMd5, action1);
+//        }
     }
     //通过接口检查更新
     public static void checkUpdateNewVersion(final Activity activity, final String ignoreMd5, final Action1<Integer> action1) {

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -860,7 +860,7 @@ public class TestUtil {
 
     //开启后可 测试充值与绑定微信和身份信息逻辑 等
     public static boolean isDev() {
-        return BuildConfig.DEBUG;
-//        return false;
+//        return BuildConfig.DEBUG;
+        return false;
     }
 }

+ 22 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/SplashAct.java

@@ -26,6 +26,10 @@ import com.sheep.gamegroup.model.entity.Advertising;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.RouserArticlesEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.module.yf_shop.model.ReceiveCouponsCheckResq;
+import com.sheep.gamegroup.module.yf_shop.model.ReceiveCouponsResp;
+import com.sheep.gamegroup.util.ApiJSONUtil;
+import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.IDConstant;
@@ -37,6 +41,7 @@ import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 
 import org.afinal.simplecache.ApiKey;
@@ -434,8 +439,23 @@ public class SplashAct extends BaseActivity implements EasyPermissions.Permissio
                     Jump2View.getInstance().goWatchFocus(activity, advertising.getLink_id());
                     break;
                 case IDConstant.JUMP_EXCHANGE_COUPON://绵羊币兑换商城优惠券
-                    //TODO 调用接口兑换商城优惠券, 然后跳转到对应的商城h5界面
-                    Jump2View.getInstance().goWeb(activity, "http://www.17xmy.com/", advertising.getName());
+                    //调用接口兑换商城优惠券, 然后跳转到对应的商城h5界面
+                    ApiJSONUtil.postYfShopReceiveCoupons(ReceiveCouponsCheckResq.TYPE_NEW_TASK, 6f)
+                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                            @Override
+                            public void onError(BaseMessage baseMessage) {
+                                G.showToast(baseMessage);
+                            }
+
+                            @Override
+                            public void onNext(BaseMessage baseMessage) {
+                                G.showToast(baseMessage);
+                                ReceiveCouponsResp data = baseMessage.getData(ReceiveCouponsResp.class);
+                                if(data != null){
+                                    Jump2View.getInstance().goWeb(activity, data.getBuy_url(), advertising.getName());
+                                }
+                            }
+                        });
                     break;
             }
         }