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

namespace app\admin\controller;


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']=null;
        $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('审核失败!');
        }
    }

}