Index.php 17.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
<?php

namespace app\api\controller\v1;
//允许所有的跨域请求
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: *");
header('Access-Control-Allow-Methods: POST,GET,OPTIONS');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
date_default_timezone_set('PRC');

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Cache;
use think\Config;
use think\Db;
use think\Validate;
use function Qiniu\explodeUpToken;
use Qiniu\Auth as QAuth;
use Qiniu\Storage\UploadManager;
use think\Lang;

Lang::load(APP_PATH . '/api/lang/zh-cn/v1/Index.php');

/**
 * 首页公共
 */
class Index extends Api
{
    protected $noNeedLogin = ["*"];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();

    }

    /**
     * 各模块轮播图列表(启动页、首页顶部轮播)+填报须知
     *
     */
    public function getWctImg()
    {
        //启动图片
        $list = Db::name('xcx_img')->where(['type' => "1", 'status' => 1])->order('id', 'desc')->find();
        $imgs = $list['images'] ? explode(',', $list['images']) : [];
        $data['start_img'] = $imgs ? full_image($imgs) : [];

        //首页图片
        $list2 = Db::name('xcx_img')
            ->where(['type' => "2", 'status' => 1])
            ->order('id', 'desc')
            ->find();
        $imgs2 = $list2['images'] ? explode(',', $list2['images']) : [];
        $data['index_banner_img'] = $imgs2 ? full_image($imgs2) : [];

        //管理端图片
        $list2 = Db::name('xcx_img')
            ->where(['type' => "3", 'status' => 1])
            ->order('id', 'desc')
            ->find();
        $imgs2 = $list2['images'] ? explode(',', $list2['images']) : [];
        $data['admin_banner_img'] = $imgs2 ? full_image($imgs2) : [];

        $this->success('获取成功', $data);
    }

    /**
     * 获得药品分类列表
     */
    public function getDrugsCatList()
    {
        $list = Db::name('job_category')
            ->where(['status' => '0', 'pid' => 0])
            ->field('id as value,name as label,pid')
            ->order('sort desc,id asc')
            ->select();
        foreach ($list as $k => $v) {
            $list[$k]['active'] = false;
            $children = Db::name('job_category')
                ->where(['status' => '0', 'pid' => $v['value']])
                ->field('id as value,name as label,pid')
                ->order('sort desc,id asc')
                ->select();
            foreach ($children as $k2 => $v2) {
                $children[$k2]['active'] = false;
            }
            $list[$k]['children'] = $children;
        }

        $this->success('获取成功', $list);
    }

    /**
     * 2. 图片\文件上传
     */
    public function fileUpload()
    {
        if ($this->request->isPost()) {
            $file = request()->file('file');

//            file_put_contents("test_upload.log","一:".date("Ymd H:i:s").json_encode($file).PHP_EOL,FILE_APPEND);
//            file_put_contents("test_upload.log","二:".date("Ymd H:i:s").json_encode($data).PHP_EOL,FILE_APPEND);

            if (empty($file)) {
                $this->error('请上传图片或文件');
            }

            //移动到框架应用根目录/public/uploads/目录下
            $info = $file->validate(['ext' => 'jpeg,jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
//            file_put_contents("test_upload.log","三:".date("Ymd H:i:s").json_encode($data).PHP_EOL,FILE_APPEND);

            $domain = 'https://share.xp.yn.cn/';
            $bucket = 'mzwlwz';
            $auth = new QAuth('Eb_QX9JpdaILVbUx0ChfMfo0AFK-12J-eD0uVy25', 'VeqduMD6UzUvxkAiXc6e2N6w51N_KwppZXT3Kaix');
            // 生成上传Token
            $token = $auth->uploadToken($bucket);

            // 构建 UploadManager 对象
            $uploadMgr = new UploadManager();

            if ($info) {
                $filepath = ROOT_PATH . 'public/uploads/' . date('Ymd', time()) . '/' . $info->getFilename();
                $fname = 'uploads/' . date('Ymd', time()) . '/' . $info->getFilename();
                list($ret, $err) = $uploadMgr->putFile($token, $fname, $filepath);
                $data['filepath'] = $domain . $ret['key'];
                $data['fileurl'] = '/' . $ret['key'];
                $path = '../public' . $data['fileurl'];
                //excel不删除
                $ext = pathinfo($path, PATHINFO_EXTENSION);
                if (!in_array($ext, ['xls', 'xlsx'])) {
                    is_file($path) && unlink($path);//删除服务器上文件
                }

                $files = $file->getInfo();
                $data['oldname'] = explode('.', $files['name']);
                $data['oldname'] = $data['oldname'][0];
                $this->success('文件上传成功', $data);
            } else {
                //上传失败获取错误信息
//                file_put_contents("test_upload.log","四:".$file->getError().PHP_EOL,FILE_APPEND);

                $this->error($file->getError());
            }
        }
    }


    /***
     * 首页-获得滚动信息
     */
    public function getdrugsList()
    {
        $list = Db::name('myneed_drugs')
            ->alias('ui')
            ->join('user u', 'ui.uid=u.id')
            ->where(['ui.status' => '3'])
            ->order('ui.id', 'desc')
            ->field('u.username,u.nickname')
            ->limit(20)
            ->select();
        $data = [];
        if ($list) {
            foreach ($list as $k => $v) {
                if (mb_strlen($v['username']) > 2) {
                    $name = mb_substr_replace($v['username'], '*', 1, -1);
                } else {
                    $name = mb_substr_replace($v['username'], '*', 0, -1);
                }
                $data[$k] = $name . ' 已获得所需药品';
            }
        }

        $this->success('获取成功', $data);
    }

    /***
     * 获得我的症状分类列表
     */
    public function myStatusList()
    {
        $list = Db::name('mystatus_cat')
            ->order('id', 'asc')
            ->field('id,name')
            ->select();

        $this->success('获取成功', $list);
    }

    /***
     * 药品来源
     */
    public function drug_source_list()
    {
        $list = Db::name('drug_source')
            ->field('id,source_name as name')
            ->order('id asc')
            ->select();
        $this->success('药品来源获取成功', $list);
    }

    /**
     * 来源地(省、市、区)
     */
    public function from_place()
    {
        $list = Cache::get('orgin_area');//取缓存
        if (empty($list)) {
            $where = [];
            $where["level"] = ["in", "1,2,3"];
            $list = Db::name("area_code")->where($where)->field("id,pid as parent,name,level")->select();
            //追加直筒子市(441900000000:广东省东莞市;442000000000:广东省中山市;460400000000:海南省儋州市;)
            $w = [];
            $w["level"] = ["=", 4];
            $w["pid"] = ["in", [441900000000, 442000000000, 460400000000]];
            $zhitongshi = Db::name("area_code")->where($w)->field("id,pid as parent,name,level")->select();
            $list = array_merge($list, $zhitongshi);

            if (!empty($list)) {
                $list = get_tree_list($list);
            }
            Cache::set('orgin_area', $list, 24 * 3600);
        }
        $this->success("来源地数据获取成功", $list);
    }

    /**
     * 14. 目的地(省、市、区)
     */
    public function dest_area()
    {
        $list = Cache::get('dest_area');//取缓存
        if (empty($list)) {
            $where = [];
            $where["level"] = ["in", "1,2,3"];
            $list = Db::name("hc_area_code")->where($where)->field("code as id,pcode as parent,name,level")->order("is_search desc")->select();
            if (!empty($list)) {
                $list = get_tree_list($list);
            }
            Cache::set('dest_area', $list, 24 * 3600);
        }
        $this->success("目的地数据获取成功", $list);
    }

    /**
     *   (省、市、区)(不包含学校)
     */
    public function dest_area_no_school()
    {
        $list = Cache::get('dest_area_no_school');//取缓存
        if (empty($list)) {
            $where = [];
            $where["level"] = ["in", "1,2,3"];
            $where["is_search"] = ["=", 0];
            $where["is_school"] = ["=", 0];
            $list = Db::name("hc_area_code")->where($where)->field("code as id,pcode as parent,name,level")->select();
            if (!empty($list)) {
                $list = get_tree_list($list);
            }
            Cache::set('dest_area_no_school', $list, 24 * 3600);
        }
        $this->success("目的地数据获取成功2", $list);
    }

    /**
     * 街道、小区(不包含学校)
     */
    public function street_community_no_school()
    {
        $code = $this->request->param("code", 532503000000);
        $list = [];
        if (!empty($code)) {
            $where = [];
            $where["pcode"] = ["=", $code];
            $where["is_search"] = ["=", 0];
            $where["is_school"] = ["=", 0];
            $list = Db::name("hc_area_code")->where($where)->field("code as id,pcode as parent,name,level")->order("is_school desc")->select();
            if (!empty($list)) {
                foreach ($list as $k => $v) {
                    $w = [];
                    $w["pcode"] = ["=", $v['id']];
                    $w["is_search"] = ["=", 0];
                    $w["is_school"] = ["=", 0];
                    $list[$k]['children'] = Db::name("hc_area_code")->where($w)->field("code as id,pcode as parent,name,level")->order("is_search desc")->select();
                }
            }
        }
        $this->success("街道、小区数据获取成功2", $list);
    }

    /**
     * 15. 街道、小区
     */
    public function street_community()
    {
        $code = $this->request->param("code");
        $list = [];
        if (!empty($code)) {
            $list = Db::name("hc_area_code")->where("pcode", $code)->field("code as id,pcode as parent,name,level")->order("is_school desc")->select();
            if (!empty($list)) {
                foreach ($list as $k => $v) {
                    $list[$k]['children'] = Db::name("hc_area_code")->where("pcode", $v['id'])->field("code as id,pcode as parent,name,level")->order("is_search desc")->select();
                }
            }
        }
        $this->success("街道、小区数据获取成功", $list);
    }


    /**
     * 48. 区、街道、社区
     */
    public function area_street_community()
    {
        $list = Cache::get('area_street_cun');//取缓存
        if (empty($list)) {
            $where = [];
            $where["level"] = ["=", 3];
            $where['pcode'] = ["=", 532500000000];//这里只拿红河哈尼族彝族自治州的
            $list = Db::name("hc_area_code")->where($where)->field("code as id,pcode as parent,name,level")->select();
            if (!empty($list)) {
                foreach ($list as $k => $v) {
                    $level4 = Db::name("hc_area_code")->where("pcode", $v['id'])->field("code as id,pcode as parent,name,level")->order("is_school desc")->select();
                    if (!empty($level4)) {
                        foreach ($level4 as $k4 => $v4) {
                            $level4[$k4]['children'] = Db::name("hc_area_code")->where("pcode", $v4['id'])->field("code as id,pcode as parent,name,level")->order("is_search desc")->select();
                        }
                        $list[$k]['children'] = $level4;
                    }

                }
            }
            Cache::set('area_street_cun', $list, 24 * 3600);
        }
        $this->success("区、街道、社区数据获取成功", $list);
    }

    /**
     * 测试
     */
    public function getxieyi()
    {
        $xieyi = Db::name('config')
            ->where(['name' => 'getxieyi'])
            ->find();
        $data['xieyi'] = $xieyi['value'];

        $this->success('获取成功', $data);
    }

    /**
     * 43. 常见问题列表
     */
    public function question_and_answer()
    {
        $data = Db::name("question_answer")->where("status", "1")->order("weigh desc")->field("id,title,content")->select();
        $this->success("常见问题列表获取成功", $data);
    }

    /***
     * 部门列表
     *
     */
    public function departlist()
    {
        if ($this->request->isPost()) {
            $search = $this->request->param('search', '');
            $page = $this->request->post('page', '1');
            $total = $this->request->post('total', '12');

            if ($search > '0') {
                $where['depart_name'] = ['like', '%' . $search . '%'];
            }
            $list = Db::name('workorder_depart')
                ->where(['status' => '0'])
                ->where($where)
                ->field('id,depart_name,contact_phone,contact_address')
                ->order('weigh desc,id asc')
                ->paginate($total, false, ['page' => $page])
                ->toArray();
            foreach ($list['data'] as $k => $v) {
                //统计部门办结的工单
                $orderCt = Db::name('workorder_orders')
                    ->where(['depart_id' => $v['id'], 'status' => 5])
                    ->count();
                $list['data'][$k]['orderCt'] = $orderCt;
            }

            $this->success("获取成功", $list);
        }
    }

    /***
     * 部门详情页面
     * 办理的工单统计和工单列表
     */
    public function departInfo()
    {
        if ($this->request->isPost()) {
            $id = $this->request->param('id', 0);
            $page = $this->request->post('page', '1');
            $total = $this->request->post('total', '12');

            $depart = Db::name('workorder_depart')
                ->where(['id' => $id, 'status' => '0'])
                ->field('id,depart_name,contact_phone,contact_address')
                ->find();
            $data['depart'] = $depart;
            //已办结 办结率 满意度
            $orderAll = Db::name('workorder_orders')
                ->whereNull('deletetime')
                ->where(['depart_id' => $depart['id']])
                ->count();
            $orderOk = Db::name('workorder_orders')
                ->whereNull('deletetime')
                ->where(['depart_id' => $depart['id'], 'status' => 5])
                ->count();
            $data['orderOk'] = $orderOk;
            if ($orderAll > 0 && $orderOk > 0) {
                $data['orderOk_pct'] = round(($orderOk / $orderAll) * 100, 2);
            } else {
                $data['orderOk_pct'] = 0;
            }
            //获得部门的近3个月工单ids
            $orderIds = Db::name('workorder_orders')
                ->where(['depart_id' => $depart['id']])
                ->whereTime('createtime', '-3 month')
                ->whereNull('deletetime')
                ->order('id', 'desc')
                ->column('id');
            $orderIds = implode(',', $orderIds);
            //部门所有工单评价
            $whcm['order_id'] = ['in', $orderIds];
            $orderCommAll = Db::name('workorder_evaluate')
                ->where($whcm)
                ->count();
            $orderCommAll4 = Db::name('workorder_evaluate')
                ->where($whcm)
                ->where('stars>=4')
                ->count();
            if ($orderCommAll > 0 && $orderCommAll4 > 0) {
                $data['orderComm_pct'] = round(($orderCommAll4 / $orderCommAll) * 100, 2);
            } else {
                $data['orderComm_pct'] = 0;
            }

            $list = Db::name('workorder_orders')
                ->alias('o')
                ->join('workorder_category c', 'o.category_id=c.id')
                ->where(['o.depart_id' => $depart['id']])
                ->whereNull('o.deletetime')
                ->field('o.id,o.category_id,o.status,o.createtime,o.title,c.name')
                ->order('o.id', 'desc')
                ->paginate($total, false, ['page' => $page])
                ->toArray();
            if ($list) {
                foreach ($list['data'] as $k => $v) {
                    $list['data'][$k]['createtime'] = date('Y-m-d H:i', $v['createtime']);
                }
            }

            $data['list'] = $list;

            $this->success('获取成功', $data);
        }
    }

    /***
     * 排行榜
     * 部门统计
     * $type  1=办理问政   2=已办结   3=满意度
     */
    public function ranklist()
    {
        $type = $this->request->param('type', 1);

        if ($type == 1) {
            $order = "ct.orderAll desc";
        }
        if ($type == 2) {
            $order = "ct.orderOk_pct desc and ct.orderAll desc";
        }
        if ($type == 3) {
            $order = "ct.orderComm_pct desc and ct.orderAll desc";
        }
        $list = Db::name('workorder_depart_order_ctall')
            ->alias('ct')
            ->join('workorder_depart d', 'ct.depart_id=d.id')
            ->order($order)
            ->limit(10)
            ->field('ct.id,ct.orderAll,ct.orderOk_pct,ct.orderComm_pct,d.depart_name')
            ->select();

        $this->success('获取成功', $list);
    }


}