OrderModel.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { gameMethod } from "../../common/gameMethod";
  2. import { KindItem, OrderList, SevBack } from "../../common/Xys";
  3. import Config from "../../Config";
  4. import { PayProductParam, ConstItem, PlatFormDevType, DayTipsKey } from "../const/TypeConst";
  5. import GameDataCenter from "../GameDataCenter";
  6. import UIHelp, { DialogJintiaoTipsParams, DialogParams } from "../../logic/ui/UIHelp";
  7. import { I18n } from "../../utils/I18nUtil";
  8. import FguiMgr from "../../frameWork/fgui/FguiMgr";
  9. import { DialogViewView } from "../../logic/fgui/Common/DialogView/DialogViewView";
  10. import IDataModel from "../../frameWork/model/IDataModel";
  11. const { ccclass, property } = cc._decorator;
  12. export default class OrderModel extends IDataModel {
  13. constructor() {
  14. super('order');
  15. }
  16. doEvent(result: SevBack): void {
  17. }
  18. //免费,钻石,代金券,支付,广告统一调用接口
  19. // dcData.need 空数组 免费, 1货币&普通道具, 10充值(包含代金券支付), 11广告
  20. commonSendCharge(kid: string, orderList: OrderList, dcData: { title: string, need: KindItem }, sendUrl: string, sendParam: any, cb?: (isSucc: boolean, sevBack?: SevBack) => void, count: number = 1) {
  21. //请求对应的下单接口
  22. if (dcData?.need?.[0] == 10 && dcData?.need?.[1] > 0 && kid != "actShopJinTiao" && GameDataCenter.item.getItemCount(ConstItem.voucher) >= dcData?.need?.[1]) {
  23. if (GameDataCenter.dialog.checkSetToday(DayTipsKey.chargeByDaiJinQuan)) {
  24. //勾选了今日不再提醒,直接使用代金券
  25. sendParam["daibi"] = 1;
  26. this.SendCharge(kid, orderList, dcData, sendUrl, sendParam, cb, count);
  27. } else {
  28. //代金券足够并且不是直接购买代金券的商品,弹出二次确认框是否使用代金券
  29. let costItemInfo = GameDataCenter.item.getItemCfgBase(ConstItem.voucher);
  30. let costItem: KindItem = [];
  31. costItem[0] = ConstItem.voucher?.[0] ?? 1;
  32. costItem[1] = ConstItem.voucher?.[1];
  33. costItem[2] = orderList.daibi * count;
  34. let data: DialogParams = {
  35. content: I18n.getI18nText('dialogJintiaoTipsView_txtContent', costItemInfo.name),
  36. txtCancel: this.isCanCharge(kid) ? I18n.getI18nText('dialogJintiaoTipsView_txt_zf') : I18n.getI18nText('buyDjq', costItemInfo.name),
  37. costItem: costItem,
  38. showToggle: true,
  39. dayTipsKey: DayTipsKey.chargeByDaiJinQuan,
  40. maskCloseOnly: true,
  41. cbConfirm: () => {
  42. sendParam["daibi"] = 1;
  43. this.SendCharge(kid, orderList, dcData, sendUrl, sendParam, cb, count);
  44. },
  45. cbCancel: () => {
  46. if (this.isCanCharge(kid)) {
  47. sendParam["daibi"] = 0;
  48. this.SendCharge(kid, orderList, dcData, sendUrl, sendParam, cb, count);
  49. }
  50. else{
  51. GameDataCenter.page.openShopVoucher();
  52. }
  53. }
  54. }
  55. FguiMgr.Instance.openUI(DialogViewView, ViewZorder.POP, null, data);
  56. }
  57. } else {
  58. this.SendCharge(kid, orderList, dcData, sendUrl, sendParam, cb, count);
  59. }
  60. }
  61. //发送支付
  62. SendCharge(kid: string, orderList: OrderList, dcData: { title: string, need: KindItem }, sendUrl: string, sendParam: any, cb?: (isSucc: boolean, sevBack?: SevBack) => void, count: number = 1) {
  63. this.send(sendUrl, sendParam, (result: SevBack) => {
  64. if (result.type == 1) {
  65. if (!gameMethod.isEmpty(result.order10Id)) {
  66. if (!this.canPay) {
  67. console.log("后台配置关闭支付了")
  68. return
  69. }
  70. if (gameMethod.isEmpty(dcData?.title)) {
  71. //如果没有传商品标题,给个默认值防止充值失败,服务端必须要传!!!!!
  72. dcData.title = "默认礼包"
  73. }
  74. console.log(`支付kid:${kid},orderList:${JSON.stringify(orderList)},dcData:${JSON.stringify(dcData)}`)
  75. //特殊平台不能支付,需要走代金券
  76. if (this.isCanCharge(kid)) {
  77. //有下单的id,拉取平台支付
  78. let data: PayProductParam = {
  79. price: orderList.rmb * count,
  80. productId: orderList.iid,
  81. productName: dcData.title,
  82. productDesc: orderList.desc
  83. }
  84. this.showPlatPay(result.order10Id, result.order10cs, data)
  85. } else {
  86. //消耗代金券,弹窗提示
  87. console.log("不能直接购买,需要购买代金券")
  88. let itemCfg = GameDataCenter.item.getItemCfgBase(ConstItem.voucher);
  89. let data: DialogParams = {
  90. content: I18n.getI18nText("buyDjqTips", itemCfg.name, itemCfg.name),
  91. title: I18n.getI18nText("common_dialogtitle_1"),
  92. cbConfirm: () => {
  93. GameDataCenter.page.openShopVoucher();
  94. }
  95. }
  96. FguiMgr.Instance.openUI(DialogViewView, ViewZorder.POP, null, data);
  97. }
  98. } else if (!gameMethod.isEmpty(result.order11Id)) {
  99. //广告
  100. GameDataCenter.adVideo.sendSeeVideo(kid, result.order11Id, result.order11cs, cb)
  101. } else {
  102. //货币&普通道具
  103. if (cb) {
  104. cb(true, result);
  105. }
  106. }
  107. }
  108. })
  109. }
  110. isCanCharge(kid: string): boolean {
  111. if (!gameMethod.isEmpty(GameDataCenter?.sevBack?.switch?.djqPay) && kid != "actShopJinTiao") {
  112. //17wan、微信小游戏的安卓不能直接支付
  113. return false;
  114. }
  115. return true
  116. }
  117. showPlatPay(order10Id: string, order10cs: string, data: PayProductParam) {
  118. console.log("掉起支付接口")
  119. GameDataCenter.plat.instance.pay(order10Id, order10cs, data)
  120. }
  121. // 是否可以支付 (正常支付或下单直接领奖)
  122. get canPay(): boolean {
  123. // 无配置,走正常支付
  124. if (gameMethod.isEmpty(GameDataCenter.sevBack?.switch?.openPays?.[Config.pid])) {
  125. return true
  126. }
  127. return GameDataCenter.sevBack?.switch?.openPays[Config.pid] == 2
  128. }
  129. //ios是否开启支付
  130. get isOpenPay(): boolean {
  131. if (GameDataCenter.plat.instance.deviceOS == PlatFormDevType.ios || GameDataCenter.plat.instance.deviceOS == PlatFormDevType.mac) {
  132. //审核包关闭ios支付及所有入口
  133. if (gameMethod.isEmpty(GameDataCenter?.sevBack?.switch?.iosPay)) {
  134. return false
  135. }
  136. }
  137. return true
  138. }
  139. }