/*
 * @Author: YKH
 * @Date: 2021-12-11 21:34:38
 * @LastEditTime: 2022-10-08 13:31:10
 * @Description:
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\utils.ts
 */
import { ALL, Body, Get, Inject, Post, Provide } from '@midwayjs/decorator';
import { ILogger } from '@midwayjs/logger';
import { BaseController, CoolController } from 'midwayjs-cool-core';
import { ShuyouUtilsService } from '../../service/utils';
import { ShuyouXJFUtilsService } from '../../service/utils_xjf';

@Provide()
@CoolController()
export class ShuyouAdminUtilsController extends BaseController {
  @Inject()
  ShuyouUtilsService: ShuyouUtilsService;

  @Inject()
  ShuyouXJFUtilsService: ShuyouXJFUtilsService;

  @Inject()
  logger: ILogger;

  /**
   *
   *http://127.0.0.1:8001/app/shuyou/utils/getWeatherCD
   * @return {*}
   * @memberof ShuyouAdminUtilsController
   */
  @Get('/getWeatherCD')
  async getWeatherCD() {
    const list = await this.ShuyouUtilsService.getWeatherCD();
    if (list.code == 200) {
      return this.ok(list);
    } else {
      return this.fail('无法获取天气信息', -1);
    }
  }

  //TODO
  /**
   *查询当前付费失败的账号
   *
   * @return {*}
   * @memberof ShuyouAdminUtilsController
   */
  @Post('/payFailed')
  async payFailed(@Body(ALL) queryObject) {
    const { task_id } = queryObject;
    let list;
    list = await this.ShuyouXJFUtilsService.payFailed(task_id);
    if (list.code == 1) {
      if (list.data == 'null') {
        return this.ok({ code: 1, message: 'null' });
      } else {
        return this.ok({ code: 1, message: JSON.parse(list.data) });
      }
    } else {
      return this.fail('无法获取信息', -1);
    }
  }
  /**
   *查询今日可付费账号
   *
   * @return {*}
   * @memberof ShuyouAdminUtilsController
   */
  @Post('/unpaid')
  async unpaid(@Body(ALL) queryObject) {
    const { task_id } = queryObject;
    let list;
    list = await this.ShuyouXJFUtilsService.unpaid(task_id);
    if (list.code == 1) {
      if (list.data == 'null') {
        return this.ok({ code: 1, message: 'null' });
      } else {
        return this.ok({ code: 1, message: JSON.parse(list.data) });
      }
    } else {
      return this.fail('无法获取信息', -1);
    }
  }
}
