<?php
// +-----------------------------------------------------------------------------------
// | Software: [ThinkPHP framework]
// | Version: V4.0
// | Site: http://www.czreg.com
// +-----------------------------------------------------------------------------------
// | Author: 飘叶 <cds425@163.com>
// | Copyright (c) 2012-2014, http://www.czreg.com All Rights Reserved.
// | time:2015.6.17
// | explain:维修管理类
// +-----------------------------------------------------------------------------------

namespace Admin\Controller;
use Think\Controller;
class WxController extends AdminController {
    public function _initialize () {
        parent::_initialize();
        $this->leftmain=10;
    }

    //维修管理
    public function index(){
        $admininfo = $this->admininfo; 
        $this->topmain=1;
    	$wx=M('wx');
    	$prefix=C('DB_PREFIX');
        if(I('get.action')=="del"){
            $id = I('get.id');
            $del = M('wx')->where(array('id'=>$id))->save(array('status'=>10));
            if($del!==false){
                M('wxlog')->add(array('wxid'=>$id,'status'=>10,'content'=>'工作人员'.$admininfo['nickname'].'取消维修','timeline'=>time()));
                $da['isType'] = "success";
                $da['isData'] = '更改成功！';
                exit(json_encode($da));
                //$this->success('取消成功',U('index'));
            }else{
                //$this->error('取消失败');
                $da['isType'] = "warning";
                $da['isData'] = '更改失败';
                exit(json_encode($da)); 
            }
            exit;
        }
        $p=empty($_GET['p'])?'1':$_GET['p'];
        $this->list = $wx->field('wxno,wxparts,createtime,realname,status,phone,address,'.$prefix.'wx.id')->join('__USER__ ON __USER__.id = __WX__.userid','LEFT')->order($prefix.'wx.id desc')->page($p.',10')->select();
        $count=$wx->field('id')->count();
        $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->rollPage=5;//页码每页显示数量
        $Page->lastSuffix = false;//尾页是否显示总页数
        $Page->setConfig('header','条记录');
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('first','首页');
        $Page->setConfig('last','尾页');
        $Page->setConfig('theme','<div class="digg">%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% </div>');
        $show       = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $this->p=$p;
        $this->wxtype=C('WXTYPE');//维修类型输出
        $this->display();
    }

    //维修件修改
    public function edit(){
        $id = I('get.id');
        if(IS_POST){
            $data['status'] = I('post.status');
            if(I('post.wxno')!=''){
                $data['wxno'] = I('post.wxno');
            }
            if(I('post.firstprice')!=''){
                $data['firstprice'] = I('post.firstprice');
            }
            if(I('post.price')!=''){
                $data['price'] = I('post.price');
                $data['endtime'] = time();
            }
            $saveparts = M('wx')->where(array('id'=>$id))->save($data);
            if($saveparts!==false){
                if(I('content')!=''){
                    M('wxlog')->add(array('wxid'=>$id,'status'=>I('status'),'content'=>I('content'),'timeline'=>time()));
                }
                echo "<script language=javascript>parent.showlog();var index = parent.layer.getFrameIndex(window.name);parent.layer.close(index);</script>"; 
                //$this->success('设置成功',U('index'));
            }else{
                $this->error('设置失败');
            }
            exit;
        }else{
            $parts      = M('wx')->where('id='.$id)->find();
            if($parts['wxno']==''){
                $wxno = M('Outh_config')->where(array('name' =>'wx_no'))->find();
                $this->wx_no = $wxno['value'];
            }
            $this->userinfo   = M('user')->where('id='.$parts['userid'])->find();
            $this->parts = $parts;
            $this->log  = M('wxlog')->where(array('wxid'=>$id))->order('id asc')->select();
            $this->wxtype=C('WXTYPE');//维修类型输出
            $this->display();
        }
    }
}