LiveModel.ets 2.81 KB
import { HttpUrlUtils, ResponseDTO } from 'wdNetwork';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { Logger, ToastUtils } from 'wdKit';
import { LiveDetailsBean, ReserveBean } from 'wdBean/Index';

const TAG = 'LiveModel'

export class LiveModel {
  /**
   * 直播内容详情
   * @param contentId
   * @param relId 关系id
   * @param relType 关系类型;1.频道关系;2.专题关系;
   * @returns
   */
  static getLiveDetails(contentId: string, relId: string, relType: string) {
    return new Promise<Array<LiveDetailsBean>>((success, fail) => {
      HttpRequest.get<ResponseDTO<Array<LiveDetailsBean>>>(
        HttpUrlUtils.getLiveDetailsUrl() + `?relId=${relId}&relType=${relType}&contentId=${contentId}`,
      ).then((data: ResponseDTO<Array<LiveDetailsBean>>) => {
        if (!data || !data.data) {
          fail("数据为空")
          return
        }
        if (data.code != 0) {
          fail(data.message)
          return
        }
        success(data.data)
      }, (error: Error) => {
        fail(error.message)
        Logger.debug(TAG + ":error ", error.toString())
      })
    })
  }

  /**
   * 直播预约/取消预约
   * @param relationId
   * @param mLiveId
   * @param isSubscribe
   * @returns
   */
  static liveAppointment(relationId: string, liveId: string, isSubscribe: boolean) {
    let params: Record<string, string> = {};
    params['relationId'] = relationId
    params['liveId'] = liveId
    params['isSubscribe'] = `${isSubscribe}`
    return new Promise<ResponseDTO<string>>((success, fail) => {
      HttpRequest.post<ResponseDTO<string>>(
        HttpUrlUtils.getLiveAppointmentUrl(),
        params,
      ).then((data: ResponseDTO<string>) => {
        if (data.code != 0) {
          fail(data.message)
          ToastUtils.shortToast(data.message)
          return
        }
        success(data)
      }, (error: Error) => {
        fail(error.message)
        Logger.debug(TAG + ":error ", error.toString())
      })
    })
  }

  /**
   * 查询预约状态
   *
   [{"relationId":"500002824823","liveId":"20000120522"},{"relationId":"500002845517","liveId":"20000120782"}]
   * @returns
   * @returns
   */
  static getAppointmentStatus(reserveBean: ReserveBean[]) {
    // let params: Record<string, ArrayList<ReserveBean>> = {};
    // params = reserveBean
    return new Promise<ResponseDTO<string>>((success, fail) => {
      HttpRequest.post<ResponseDTO<string>>(
        HttpUrlUtils.getAppointmentStatusUrl(),
        reserveBean,
      ).then((data: ResponseDTO<string>) => {
        if (data.code != 0) {
          fail(data.message)
          ToastUtils.shortToast(data.message)
          return
        }
        success(data)
      }, (error: Error) => {
        fail(error.message)
        Logger.debug(TAG + ":error ", error.toString())
      })
    })
  }
}