/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2022-03-17 13:30:09
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\service\game_director.ts
 */
import { Provide } from '@midwayjs/decorator';
import { BaseService } from 'midwayjs-cool-core';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';
import * as _ from 'lodash';
import { ShuyouGameDirectorEntity } from '../entity/game_director';

/**
 * 游戏负责人
 */
@Provide()
export class ShuyouGameDirectorService extends BaseService {

  @InjectEntityModel(ShuyouGameDirectorEntity)
  ShuyouGameDirectorEntity: Repository<ShuyouGameDirectorEntity>;

  /**
   * 重写list查询
   * @param {*} query
   * @return {*} 
   * @memberof ShuyouGameDirectorService
   */
  async list(query) {
    const sql = `
          SELECT
            *
          FROM
            shuyou_game_director
          WHERE status = 1
        `;
    return this.nativeQuery(sql, query);
  }

  /**
   *  
   * @param {*} names
   * @return {*} 
   * @memberof ShuyouGameDirectorService
   */
  async queryPhoneByNames(names: any) {
    const sql = `
          SELECT phone
          FROM shuyou_game_director
          WHERE 
        `+ names;
    return this.nativeQuery(sql);
  }

  /**
   *
   *减少游戏数量by id
   * @param {*} id
   * @return {*} 
   * @memberof ShuyouGameDirectorService
   */
  async reduceGameNumById(id: number) {
    if (id) {
      const gameGameDirectorEntity = await this.ShuyouGameDirectorEntity.findOne({
        id: id
      });
      gameGameDirectorEntity.game_count = gameGameDirectorEntity.game_count - 1;
      await this.ShuyouGameDirectorEntity.save(gameGameDirectorEntity);
      return 1000
    } else {
      return -1
    }
  }
  /**
   *
   *增加游戏数量by id
   * @param {*} id
   * @return {*} 
   * @memberof ShuyouGameDirectorService
   */
  async addGameNumById(id: number) {
    if (id) {
      const gameGameDirectorEntity = await this.ShuyouGameDirectorEntity.findOne({
        id: id
      });
      gameGameDirectorEntity.game_count = gameGameDirectorEntity.game_count + 1;
      await this.ShuyouGameDirectorEntity.save(gameGameDirectorEntity);
      return 1000
    } else {
      return -1
    }
  }


}
