<?php

namespace loyalsoft;

require_once ROOTDIR . '/service_call/pay/Mo/OrderNotice.php';

require_once ROOTDIR . '/util/tapdb/TapDB_config.php';

class TapDBPayEventProperties {

    public $ip = "0.0.0.0";        // 可选。充值用户的IP
    public $order_id;              // 可选。长度大于0并小于等于256。订单ID。
    public $amount;                // 必需。大于0并小于等于100000000000。充值金额。单位分，即无论什么币种，都需要乘以100
    public $virtual_currency_amount = 0; //获赠虚拟币数量，必传，可为0
    public $currency_type = "CNY"; // 可选。货币类型。国际通行三字母表示法，为空时默认CNY。参考：人民币 CNY，美元 USD；欧元 EUR
    public $product = "0";         // 可选。长度大于0并小于等于256。商品名称
    public $payment = "alipay";    // 可选。长度大于0并小于等于256。充值渠道
    public $charge_amount;
    public $channel;

    /**
     * pay event 属性
     * @param  \loyalsoft\pay\OrderNotice  $order
     * @param string $payMent 支付渠道: "alipay/wxpay"
     */
    public function __construct($order, $payMent) {
        $this->amount = $order->amount;                                         # 分转分.
        $this->charge_amount = $order->amount;
        $this->order_id = $order->cpOrderId;

        $this->currency_type = $order->currency;
        $this->payment = $payMent;
        $this->product = $order->dbOrder()->product_id;                         # 附加一下道具id
        $this->channel = $order->channel;
    }

}

/**
 * 支付事件
 * @author gwang
 */
class TapDBPayEvent {

    /**
     * 充值事件的数据格式的构造函数
     * @param string $uid
     * @param  \loyalsoft\pay\OrderNotice  $order
     * @param string $payMent 支付渠道: alipay/wxpay
     */
    public function __construct($order, $payMent) {
        $this->client_id = TapDB_config::Ins()->gameClientId;
        $this->user_id = $order->uid;
//        $this->index = TapDB_config::Ins()->gameClientId;
//        $this->identify = $order->uid;
        $this->properties = new TapDBPayEventProperties($order, $payMent);
    }

//    public $module = "GameAnalysis"; // 固定参数
    public $name = "charge"; // 事件名，固定为 "charge"
    public $type = "track";  // 必须, 固定为 "track"
//    public $index = "APPID"; // 必需。注意APPID需要被替换成TapDB的appid
//    public $identify = "userId"; // 必需。用户ID。必须和SDK的setUser接口传递的userId一样，并且该用户已经通过SDK接口进行过推送
    public $client_id;       // 必需。注意 ClientID 需要被替换成游戏的 ClientID
    public $user_id;         // 必需。用户ID。必须和SDK的setUser接口传递的userId一样，并且该用户已经通过SDK接口进行过推送
    public $properties;      // 充值属性值

}
