ApprovalController.php 10.8 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2019/1/15
 * Time: 11:10
 */

namespace app\admin\controller;


use app\admin\model\InquiryModel;
use app\admin\model\TransferModel;
use app\user\model\UserModel;
use cmf\controller\AdminBaseController;
use EasyWeChat\Foundation\Application;


/**
 * Class GroupController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   => '审批管理',
 *     'action' => 'default',
 *     'parent' => '',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   => '',
 *     'remark' => ''
 * )
 */
class ApprovalController extends AdminBaseController
{

    /**
     * 进修审批列表
     * @adminMenu(
     *     'name'   => '进修审批列表',
     *     'parent' => 'default',
     *     'display'=> true,
     *	   'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '进修审批管理',
     *     'param'  => ''
     * )
     */
    public function engageList(){
        $map['delete_time']=0;
        $list=db('engage')->where($map)->order('id','desc')->paginate('20');
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
        return $this->fetch();
    }

    /**
     * 进修详情
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function engageDetail(){
        $id=input('id');
        $info=db('engage')->where('id',$id)->find();
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 删除信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function engageDelete(){
        $map['id']=input('id');
        $update['delete_time']=time();
        $result=db('engage')->where($map)->update($update);
        if ($result==1){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 编辑信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function engageEdit(){
        $map['id']=input('id');
        $update['state']=input('state');
        $update['answer']=input('answer');
        $result=db('engage')->where($map)->update($update);
        if ($result==1){
            /*发送模板消息*/
            $engage=db('engage')->where($map)->find();
            $User=new UserModel();
            $openid=$User->getUserOpenid($engage['user_id']);
            $userId = $openid;
            $templateId = 'M0PtJ9xxGWkMoCI6p1ZhQLyj83k3PAqkeG94yyMRxD4';
            $url = url('user/expert/engagedetail',['id'=>$map['id']],'',true);
            if($update['state']==1){
                $first='恭喜您,您提交的进修申请已通过';
            }else{
                $first='对不起,您提交的进修申请已被驳回';
            }

            $data = array(
                "first"=>"$first",
                "keyword1"  => "$engage[user_name]",
                "keyword2"   => $engage['phone_num'],
                "keyword3"  => date('Y-m-d H:i',$engage['add_time']),
                "keyword4" => "进修申请",
                "remark" => "点击查看详情确认信息",
            );
            $config=config('wechat_config');
            $Wechat=new Application($config);
            $notice = $Wechat->notice;
            $result = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
            $this->success('审核成功!');
        }else{
            $this->error('审核失败!');
        }
    }

    /**
     * 问诊审批列表
     * @adminMenu(
     *     'name'   => '问诊审批列表',
     *     'parent' => 'default',
     *     'display'=> true,
     *	   'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '问诊审批列表',
     *     'param'  => ''
     * )
     */
    public function inquiryList(){
        $map['a.delete_time']=0;
        $model=new InquiryModel();
        $data=$model->alias('a')
            ->join('__USER__ b','a.user_id=b.id','LEFT')
            ->field('a.*,b.user_nickname')
            ->where($map)->order('id','desc')->paginate(20);

        $list=$data->items();
        $this->assign('list', $list);
        $this->assign('page', $data->render());
        return $this->fetch();
    }

    /**
     * 进修详情
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function inquiryDetail(){
        $id=input('id');
        $model=new InquiryModel();
        $info=$model->alias('a')->join('__USER__ b','a.user_id=b.id','LEFT')
            ->field('a.*,b.user_nickname')
            ->where('a.id',$id)->find();
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 删除信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function inquiryDelete(){
        $map['id']=input('id');
        $update['delete_time']=time();
        $result=db('inquiry')->where($map)->update($update);
        if ($result==1){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 编辑信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function inquiryEdit(){
        $id=input('id');
        $model=new InquiryModel();
        $model->startTrans();
        $engage=$model->alias('a')->join('__USER__ b','a.user_id=b.id','LEFT')
            ->field('a.*,b.user_nickname,mobile')
            ->where('a.id',$id)->find();
        $update['status']=input('status');
        $result=db('inquiry')->where(['id'=>$id])->update($update);
        if ($result==1){
//            /*发送模板消息*/
//            $User=new UserModel();
//            $openid=$User->getUserOpenid($engage['user_id']);
//            $userId = $openid;
//            $templateId = 'M0PtJ9xxGWkMoCI6p1ZhQLyj83k3PAqkeG94yyMRxD4';
//            $url = url('user/expert/inquirydetail',['id'=>$id],'',true);
//            if($update['status']==1){
//                $first='恭喜您,您提交的问诊审核已通过';
//            }else{
//                $first='对不起,您提交的问诊审核已被驳回';
//            }
//
//            $data = array(
//                "first"=>$first,
//                "keyword1"  => $engage['user_nickname'],
//                "keyword2"   => $engage['mobile'],
//                "keyword3"  => date('Y-m-d H:i',$engage['addtime']),
//                "keyword4" => "问诊审核",
//                "remark" => "点击查看详情确认信息",
//            );
//            $config=config('wechat_config');
//            $Wechat=new Application($config);
//            $notice = $Wechat->notice;
//            $result = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
            $model->commit();
            $this->success('审核成功!');
        }else{
            $model->rollback();
            $this->error('审核失败!');
        }
    }

    /**
     * 转诊审批列表
     * @adminMenu(
     *     'name'   => '转诊审批列表',
     *     'parent' => 'default',
     *     'display'=> true,
     *	   'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '转诊审批列表',
     *     'param'  => ''
     * )
     */
    public function transferList(){
        $map['a.delete_time']=0;
        $model=new TransferModel();
        $data=$model->alias('a')
            ->join('__USER__ b','a.user_id=b.id','LEFT')
            ->field('a.*,b.user_nickname')
            ->where($map)->order('id','desc')->paginate(20);

        $list=$data->items();
        $this->assign('list', $list);
        $this->assign('page', $data->render());
        return $this->fetch();
    }

    /**
     * 进修详情
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function transferDetail(){
        $id=input('id');
        $model=new TransferModel();
        $info=$model->alias('a')->join('__USER__ b','a.user_id=b.id','LEFT')
            ->field('a.*,b.user_nickname')
            ->where('a.id',$id)->find();
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 删除信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function transferDelete(){
        $map['id']=input('id');
        $update['delete_time']=time();
        $result=db('transfer')->where($map)->update($update);
        if ($result==1){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 编辑信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function transferEdit(){
        $id=input('id');
        $model=new TransferModel();
        $model->startTrans();
        $engage=$model->alias('a')->join('__USER__ b','a.user_id=b.id','LEFT')
            ->field('a.*,b.user_nickname,mobile')
            ->where('a.id',$id)->find();
        $update['status']=input('status');
        $result=db('transfer')->where(['id'=>$id])->update($update);
        if ($result==1){
//            /*发送模板消息*/
//            $User=new UserModel();
//            $openid=$User->getUserOpenid($engage['user_id']);
//            $userId = $openid;
//            $templateId = 'M0PtJ9xxGWkMoCI6p1ZhQLyj83k3PAqkeG94yyMRxD4';
//            $url = url('user/expert/transferdetail',['id'=>$id],'',true);
//            if($update['status']==1){
//                $first='恭喜您,您提交的问诊审核已通过';
//            }else{
//                $first='对不起,您提交的问诊审核已被驳回';
//            }
//
//            $data = array(
//                "first"=>$first,
//                "keyword1"  => $engage['user_nickname'],
//                "keyword2"   => $engage['mobile'],
//                "keyword3"  => date('Y-m-d H:i',$engage['addtime']),
//                "keyword4" => "问诊审核",
//                "remark" => "点击查看详情确认信息",
//            );
//            $config=config('wechat_config');
//            $Wechat=new Application($config);
//            $notice = $Wechat->notice;
//            $result = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
            $model->commit();
            $this->success('审核成功!');
        }else{
            $model->rollback();
            $this->error('审核失败!');
        }
    }
}