/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2022-07-05 13:43:30
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\game_target.ts
 */
import { ALL, Body, Inject, Post, Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';
import { ShuyouGameTargetEntity } from '../../entity/game_target';
import { ShuyouGameTargetService } from '../../service/game_target';
import { ShuyouXJFUtilsService } from '../../service/utils_xjf';


/**
 * 游戏目标
 */
@Provide()
@CoolController({
  // 添加通用CRUD接口
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  // 设置表实体
  entity: ShuyouGameTargetEntity,
  service: ShuyouGameTargetService,
  // // 向表插入当前登录用户ID
  // insertParam: async (ctx: Context) => {
  //   return {
  //     userId: ctx.admin.userId,
  //   };
  // },
  // // info接口忽略价格字段
  // infoIgnoreProperty: ['price'],

  before: ctx => {
    //前段数据转JSON格式
    const data = ctx.request.body;
    if (typeof (data.new_date) == "undefined") {
      data.new_date = [new Date(), new Date()]
    }
    ctx.request.body.data = JSON.stringify(data);
  },
  // 分页查询配置
  pageQueryOp: {
    // 让字段支持模糊查询
    keyWordLikeFields: ['id'],
    // 让字段支持筛选
    fieldEq: ['id'],
    // 添加排序
    addOrderBy: {
      // 排序字段及排序方式
      directorName: 'asc',
    },
  },
})
export class ShuyouGameTargetController extends BaseController {

  @Inject()
  ShuyouGameTargetService: ShuyouGameTargetService;

  @Inject()
  ShuyouXJFUtilsService: ShuyouXJFUtilsService;


  //重新下发今日付费未成功的账号以及重置留存账号
  @Post('/resetPay')
  async resetPay(@Body(ALL) queryObject) {
    let { id } = queryObject
    // console.log(id)
    let reqmsg = await this.ShuyouGameTargetService.resetPay(id);
    // console.log(reqmsg)
    if (reqmsg.code == 1000) {
      return this.ok({ code: 1, message: '重置成功' });
    } else {
      return this.fail(reqmsg.data + '', -1);
    }
  }
  //手动充值-魅族
  @Post('/handAddPayMz')
  async handAddPayMz(@Body(ALL) queryObject) {
    let { xjf_id, pay_price, account } = queryObject
    // console.log(xjf_id)
    // console.log('pay_price' + pay_price)
    if (xjf_id == 0) {
      return this.fail('机房后台不存在此任务', -1);
    }
    let list
    list = await this.ShuyouXJFUtilsService.handAddPayMz(xjf_id, account, pay_price);
    console.log(list)
    if (list.code == 1) {
      if (list.data == 'Get http://127.0.0.1:6655/once_max_recharge: EOF') {
        return this.ok({ code: 1, message: '喵币不足,请联系商务添加' });
      } else if (list.data == '没有传加币金额') {
        return this.ok({ code: 1, message: '加币金额只能为正整数' });
      } else {
        return this.ok({ code: 1, message: list.data });
      }
    } else {
      return this.fail('无法获取信息', -1);
    }
  }

  //强制手动充值-魅族
  @Post('/forceAddPayMz')
  async forceAddPayMz(@Body(ALL) queryObject) {
    let { xjf_id, pay_price, account } = queryObject
    // console.log(xjf_id)
    // console.log('pay_price' + pay_price)
    if (xjf_id == 0) {
      return this.fail('机房后台不存在此任务', -1);
    }
    let list
    list = await this.ShuyouXJFUtilsService.forceAddPayMz(xjf_id, account, pay_price);
    console.log(list)
    if (list.code == 1) {
      if (list.data == 'Get http://127.0.0.1:6655/once_max_recharge: EOF') {
        return this.ok({ code: 1, message: '喵币不足,请联系商务添加' });
      } else if (list.data == '没有传加币金额') {
        return this.ok({ code: 1, message: '加币金额只能为正整数' });
      } else {
        return this.ok({ code: 1, message: list.data });
      }
    } else {
      return this.fail('无法获取信息', -1);
    }
  }

}
