<?php

/**
 * MainController
 * Feel free to delete the methods and replace them with your own code.
 *
 * @author JieRen
 */
class PayController extends DooController {

    public $data;

    function __construct() {
        $this->data['rootUrl'] = Doo::conf()->APP_URL;
    }

    /*
     * 支付删除
     */

    public function pay_del() {
        $id = intval($this->params['pid']);
        if (empty($id))
            return false;
        Doo::loadModel('pay');
        $pay = new Pay();
        $pay->delete(array(
            'where' => 'id=?',
            'param' => array($id),
            'asArray' => TRUE));
        return $this->data['rootUrl'] . 'm/pay/add';
    }

    /*
     * 支付取消
     */

    public function pay_cancel() {
        $id = intval($this->params['pid']);
        if (empty($id))
            return false;
        Doo::loadModel('pay');
        $pay = new Pay();
        $pay->status = 'cancel';
        $pay->update(array('where' => 'id=' . $id));
//        showmessage(L('state_change_succ'), HTTP_REFERER);
        return $this->data['rootUrl'] . 'm/pay/add';
    }

    /**
     *
     */
    public function pay() {
        if (isset($_GET['op']) && !empty($_POST['ids'])) {
            $ops = $_GET['op'];
//            $ids = implode(',', $_POST['ids']);
            $ids = $_POST['ids'];
            var_dump($ids);
            Doo::loadModel('pay');
            $p = new Pay();
            if (!empty($ids)) {
                if ($ops == 'del') {
                    foreach ($ids as $key => $val) {
                        $p->id = $val;
                        $p->delete();
                    }
                }

                if ($ops == 'act') {
                    foreach ($ids as $key => $val) {
                        $p->status = 'succ';
                        $p->update(array('where' => 'id=' . $val));
                    }
                }
            }
        }
        Doo::loadHelper('DooPager');
        Doo::loadModel('pay');
        $pay = new Pay();
        $totalArchive = $pay->count();
        $pager = new DooPager(Doo::conf()->APP_URL . "m/pay/add/page", $totalArchive, 5, 5);
        if (isset($this->params['pindex']))
            $pager->paginate(intval($this->params['pindex']));
        else
            $pager->paginate(1);
        $this->data['userArray'] = $pay->get_all_posts($pager->limit);
        $this->data['pager'] = $pager->output;
        $this->render('admin/pay', $this->data, TRUE);
    }

}

?>