<?php
/**
 * Created by PhpStorm.
 * User: z-yang
 * Date: 2018/8/13
 * Time: 15:02
 */

namespace App\Modules\Xcx\Services;

use  App\Modules\Xcx\Models\XcxOrder as Order;

class XcxOrderService
{

    static function save_order($data){
        $insert_data = array();
        $insert_data['uid'] = $data['uid'];
        $insert_data['price'] = $data['price'];
        $insert_data['status'] = $data['status'];
        $insert_data['pay_type'] = $data['pay_type'];
        $insert_data['product_id'] = $data['product_id'];
        $insert_data['distribution_channel_id'] = $data['distribution_channel_id'];
        $insert_data['trade_no'] = $data['trade_no'];
        $insert_data['pay_merchant_source'] = $data['pay_merchant_source'];
        $insert_data['pay_merchant_id'] = $data['pay_merchant_id'];
        $insert_data['order_type'] = $data['order_type'];
        $insert_data['transaction_id'] = $data['transaction_id'];
        $insert_data['from_bid'] = $data['from_bid'];
        $insert_data['pay_end_at'] = $data['pay_end_at'];
        $insert_data['create_ip'] = $data['create_ip'];
        $insert_data['send_order_id'] = $data['send_order_id'];
        $insert_data['send_order_name'] = isset($data['send_order_name'])?$data['send_order_name']:'';
        $insert_data['from_type'] = $data['from_type'];
        $insert_data['activity_id'] = $data['activity_id'];
        return $result = Order::save_order($insert_data);
    }


    public static  function  getOrderList($uid,$page_size){
        return Order::select('id','price','created_at','status','trade_no')->where('uid',$uid)->where('from_type','!=','order_add')->orderBy('created_at','desc')->paginate($page_size);
    }

    static function getByTradeNo($trade_no)
    {
        return Order::where('trade_no',$trade_no)->first();
    }
}