<?php

namespace App\Modules\Trade\Pay;

use App\Modules\Product\Models\Product;
use App\Modules\Subscribe\Models\Order;
use App\Modules\User\Models\User;
use DB;

/**
 * 
 * @property \App\Modules\Product\Models\Product $product
 */
class RechargeOrderPaySuccess extends PaySuccessAbstract
{

    private $product;

    public function __construct(Order $order)
    {
        parent::__construct($order);
        $this->product = Product::find($order->product_id);
    }

    protected function handlePayProcess()
    {
        $charge = $this->product->price * 100;
        $given = $this->product->given;
        $uid = $this->order->uid;
        User::where('id', $uid)->update(
            [
                'balance' => DB::raw('balance+' . ($charge + $given)),
                'charge_balance' => DB::raw('charge_balance+' . $charge),
                'reward_balance' => DB::raw('reward_balance+' . $given),
            ]
        );
    }
}
