import { Injectable } from '@angular/core';
import {CommonsService} from './commons.service';
import {environment} from '../../environments/environment';
import {HttpClient} from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class TradeOrderService {

  constructor(
      private http: HttpClient,
      private commonsService: CommonsService
  ) { }

  getHomeCountData(callBack) {
    this.http.get(environment.baseUrl + 'tradeCount/home?dt='+new Date().getTime()).subscribe(data => {
      callBack(data);
    });
  }
  /**
   * 查询交易订单
   * @param paramObject 参数
   * @param callBack
   */
  getOrderList(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'tradeOrder/getOrderList?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }
 /**
   * 统计交易订单
   * @param paramObject 参数
   * @param callBack
   */
 countOrderData(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'tradeOrder/countOrderData?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 好像交易订单
   * @param paramObject 参数
   * @param callBack
   */
  exportTradeOrder(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'tradeOrder/exportTradeOrder?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询交易订单
   * @param paramObject 参数
   * @param callBack
   */
  getOrderByOutTradeOrder(outTradeOrder: string, callBack) {
    this.http.get(environment.baseUrl + 'tradeOrder/getOrderByOutTradeOrder?outTradeOrder=' + outTradeOrder).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 订单退款
   * @param paramObject 参数
   * @param callBack
   */
  refund(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tradeOrderRefund/refund', paramObject).subscribe(data => {
      callBack(data);
    });
  }
}
