<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
*	召回相关
*/
class Recallback extends MY_Controller{


	public $postdata = array('frombg' => 1, 'mod' => '', 'act' => '', 'lid' => 1, 'sid' => 1);

	public $data = array('referer' =>'', 'refresh' => 'false', 'state' => 'error', 'message' => '');

	public function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->helper('cookie');
		$this->load->library('curl');

		//请求地址
		$this->env = get_cookie($this->_wenenv);
		$this->_url = ($this->env == 2) ? $this->config->item('localUrl') : $this->config->item('officialUrl');
	}

	/**
	*	召回首页
	*/
	public function index()
	{
		$this->postdata['mod'] = 'Push';
        $this->postdata['act'] = 'getList';
        $this->env == 2 && $this->postdata['demo'] = 1;
        $res = $this->curl->req($this->_url, $this->postdata);
        $retData = json_decode($res, TRUE);
        $list = array();
        if (is_array($retData)) {
	        $data['list'] = $retData['list'];
        }
		$this->load->view('recallback/index', $data);
	}

	/**
	*	添加推送
	*/
	public function addpush()
	{
		$devices = implode(',', $this->input->post('user_device[]'));
		$days = $this->input->post('days');
		$title = $this->input->post('title');
		$content = $this->input->post('content');
		$name = get_cookie('chinesename');

		if (empty($days) || empty($title) || empty($content)) {
			$this->data['message'] = '请务必填写所有字段';
			die(json_encode($this->data));
		}

		$this->postdata['devices'] = $devices;
		$this->postdata['days'] = $days;
		$this->postdata['title'] = $title;
		$this->postdata['content'] = $content;
		$this->postdata['name'] = $name;

		$this->postdata['mod'] = 'Push';
        $this->postdata['act'] = 'addpush';
        $this->env == 2 && $this->postdata['demo'] = 1;
        $res = $this->curl->req($this->_url, $this->postdata);
        $retData = json_decode($res, TRUE);
        if ($retData['code'] == 1) {
        	$this->data['state'] = 'success';
        	$this->data['message'] = '添加成功';
        	$this->data['refresh'] = true;
        }
        die(json_encode($this->data));
	}


}