<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2017/12/2
 * Time: 15:36
 */

namespace App\Modules\Xcx\Services;

use App\Modules\Xcx\Models\XcxSendOrder;
use DB;
use Redis;
use App\Modules\Xcx\Models\XcxOrder;
use App\Modules\User\Models\Xcxuser;

class XcxSendOrderService
{
  
    /**
     * 创建推广派单
     */
    static function createOrder($data)
    {
        return XcxSendOrder::createOrder($data);
    }
    
    static function search($params, $isAll = false)
    {
    	return XcxSendOrder:: search($params, $isAll);
    }
    
    static function getSendOrderStat($distribution_channel_id)
    {
    	$sendOrderStat = array(); 
    	$sendOrderStat['todayChargeAmount'] =  XcxOrder::getDistributionTodayChargeAmount($distribution_channel_id);
    	$sendOrderStat['todayAddUserNum'] = Xcxuser::getDistributionTodayAddUserNum($distribution_channel_id);
    	$sendOrderStat['totalChargeAmount'] = XcxOrder::getDistributionTotalChargeAmount($distribution_channel_id);
    	$sendOrderStat['totalUserNum'] = Xcxuser::getDistributionTotalAddUserNum($distribution_channel_id);
    	
    	return $sendOrderStat;
    }


    /**
     * 删除派单
     * @param $id
     * @param $distribution_channel_id
     * @return mixed
     */
    static function removeSendOrder($id,$distribution_channel_id)
    {
        return XcxSendOrder::removeSendOrder($id,$distribution_channel_id);
    }

    /**
     * 根据派单id获取渠道号
     * @param int $id
     * @return mixed
     */
    static function getChannelIdBySendOrderId(int $id){
        return XcxSendOrder::where('id',$id)->select('distribution_channel_id')->first();
    }

}