FuJiTong.php 6.0 KB
<?php
namespace app\products\controller;



use app\common\model\serviceapi\Product as ProductModel;
use app\common\model\serviceapi\ProductUser as ProductUserModel;
use app\common\model\serviceapi\ProductOrder as ProductOrderModel;


use app\web\controller\BaseController;
use think\Log;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
 * 功能描述  妇记通获客
 * Class Product
 * @package app\FuJiTong\controller
 * Date: 2021/5/6
 * Time: 10:00
 * @author nyq
 */
class FuJiTong extends BaseController
{

    private $api_domain ="www.aisigit.com/products/fu/customer_list"; //测试平台
    //private $api_domain = "http://hzy.sosyun.com/products/fu/customer_list";

    /**
     * 函数功能描述   获取客户列表
     * Date: 2021/5/6
     * Time: 10:00
     * @author nyq
     */
    public function customer_list(Request $request)
    {
        $data = $request->param();

        //return json($data);

        Cookie::set('fu_data', $data);
        $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
        $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
        $offset=($page-1)*$rows;
        $data['offset']=$offset;
        $data['rows']=$rows;
        $json=[
            "offset"=>$offset,
            "rows"=>$rows,
            "result"=>isset($data['result']) && !empty($data['result']) ? $data['result'] : '',
            "type"=>isset($data['new_type']) && !empty($data['new_type']) ? $data['new_type'] : '',
            "start"=>!empty($data['start']) ? $data['start'] : '',
            "end"=>!empty($data['end']) ? $data['end'] : '',
            "phone"=>!empty($data['phone']) ? $data['phone'] : '',
        ];
       // return json($json);
        $data_http = http_build_query($json);
        $row=MCurl::instance($this->api_domain)->post($data_http);
        $data_list=json_decode($row,true);
        $data_json=$data_list['rows'];
        foreach($data_json  as $key=>$val ){
            $data_json[$key]['sex']=$val['sex'] == 1? '女' : '男';
        }
        $result["total"] =$data_list['total'];
        $result['rows']=$data_json;
        echo json_encode($result);
        //return $json;
    }

    /**
     * 函数功能描述   导出数据到表格
     * Date: 2020/8/26
     * Time: 10:00
     * @author nyq
     */
    public function to_excel()
    {
        $data= Cookie::get('fu_data');
        $json=[
            "offset"=>1,
            "rows"=>1,
            "result"=>isset($data['result']) && !empty($data['result']) ? $data['result'] : '',
            "type"=>isset($data['new_type']) && !empty($data['new_type']) ? $data['new_type'] : '',
            "start"=>!empty($data['start']) ? $data['start'] : '',
            "end"=>!empty($data['end']) ? $data['end'] : '',
            "phone"=>!empty($data['phone']) ? $data['phone'] : '',
            'to_excel'=>1
        ];

        $data_http = http_build_query($json);
        $row=MCurl::instance($this->api_domain)->post($data_http);
        $data_list=json_decode($row,true);

        $data_json=$data_list['rows'];
        foreach($data_json  as $key=>$val ){
            $data_json[$key]['sex']=$val['sex'] == 1? '女' : '男';
        }


        ob_end_clean();//清除缓冲区,避免乱码
        Vendor('PHPExcel.PHPExcel');
        $objPHPExcel=new \PHPExcel();
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '用户名称')
            ->setCellValue('B1', '性别')
            ->setCellValue('C1', '电话')
            ->setCellValue('D1', '证件号码')
            ->setCellValue('E1', '推送结果')
            ->setCellValue('F1', '推送时间');
        $rowIndex = 2;

        foreach ($data_json as $k => $v) {
            $objPHPExcel->getActiveSheet()
                ->setCellValue('A' . $rowIndex, $v['username'])
                ->setCellValue('B' . $rowIndex, $v['sex'])
                ->setCellValue('C' . $rowIndex, $v['phone'])
                ->setCellValue('D' . $rowIndex, $v['certificateNo'].',')
                ->setCellValue('E' . $rowIndex, $v['result'].',')
                ->setCellValue('F' . $rowIndex, $v['create_time']);
            $rowIndex++;
        }

        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);


        $filename = '用户信息列表';
        header('Content-Type: application/vnd.ms-excel');

        $ua = $_SERVER["HTTP_USER_AGENT"];
        header('Content-type: text/html; charset=gbk');
        header("Content-type:application/vnd.ms-excel;charset=gbk");
        //兼容IE11
        if (preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)) {
            header('Content-Disposition: attachment;filename="' . urlencode($filename) . '.xls"');
        } else if (preg_match("/Firefox/", $ua)) {
            header('Content-Disposition: attachment;filename*="' . $filename . '.xls"');
        } else {
            header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
        }
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Cache-Control: cache, must-revalidate');
        header('Pragma: public');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');

    }



}