当前位置: 首页 > article >正文

微信支付开发-后台统计工厂实现

一、数据库设计图

二、后端统计工厂逻辑

        1、统计父抽象类

                a、StatisticsHandle.php

        2、统计工厂通道类

                a、StatisticsFactory.php

        3、查询实现类

                a、答题统计(Answer.php)

三、后端统计工厂代码实现

        1、统计父抽象类(StatisticsHandle.php)

<?php
/**
 * 统计父抽象类
 * User: 龙哥·三年风水
 * Date: 2024/9/11
 * Time: 10:07
 */
namespace Statistics;
abstract class StatisticsHandle
{
    /**
     * 获取统计列表
     * User: 龙哥·三年风水
     * Date: 2024/9/11
     * Time: 10:31
     * @ param $param 参数
     * @ return mixed
     */

    protected abstract function getList($param);

    /**
     * 获取统计详情
     * User: 龙哥·三年风水
     * Date: 2024/9/11
     * Time: 10:31
     * @ param $id 编号
     * @ return mixed
     */

    protected abstract function getInfo($id);

    /**
     * 导出统计信息
     * User: 龙哥·三年风水
     * Date: 2024/9/11
     * Time: 10:32
     * @ return mixed
     */
    protected abstract function exportInfo($param);
}

        2、统计工厂通道类(StatisticsFactory.php)

<?php
/**
 * 统计工厂选择类
 * User: 龙哥·三年风水
 * Date: 2024/9/11
 * Time: 10:12
 */
namespace Statistics;
use app\BaseError;
use Statistics\statistics\Answer;

class StatisticsFactory
{
    protected static $instance = null;//缓存实例
    protected $channelType = 0;//通道类型

    /**
     * 初始化参数
     * @ param $types 类型选择
     */

    public function __construct($channelType){
        $this->channelType = $channelType;
    }

    /**
     * 通道选择器
     * User: 龙哥·三年风水
     * Date: 2024/9/11
     * Time: 10:39
     * @ return null
     */
    public function statisticsHandle(){
        switch ((int)$this->channelType){
            case 1: //可疑网址查询

                break;
            case 2: //银行卡查询

                break;
            case 3: //人员被骗风险查询

                break;
            case 4: //答题记录查询
                self::$instance = new Answer();
                break;
            default:
                self::$instance = null;
                throw new BaseError("未设置任何通道",50000,200);
                break;
        }
        return self::$instance;
    }
}

        3、答题统计查询实现(Answer.php)

<?php
/**
 * 答题记录查询控制
 * User: 龙哥·三年风水
 * Date: 2024/9/11
 * Time: 10:29
 */
namespace Statistics\statistics;
use Statistics\StatisticsHandle;
use app\BaseError;
use app\model\anxun\shuziren\StatisticsAnswer as ASSAModel;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use Upload\UploadFactory;
class Answer extends StatisticsHandle
{
    //初始化使用的
    public function __construct(){
    }


    /**
     * 获取统计列表
     * User: 龙哥·三年风水
     * Date: 2024/9/11
     * Time: 10:31
     * @ return mixed
     */

    public function getList($param){
        // TODO: Implement getList() method.
        $where = [];
        if(!empty($param['digitized_human_name']))$where[] = ['digitized_human_name','like','%'.$param['digitized_human_name'].'%'];
        if(!empty($param['involved_date']))$where[] = ['involved_date','=',$param['involved_date']];
        if(!empty($param['id_card']))$where[] = ['id_card','=',$param['id_card']];
        $resList = ASSAModel::getList($where,'id,digitized_human_name,correct_rate,error_rate,id_card,create_time',[$param['currentPage'], $param['currentSize']]);
        $list  =  $resList['info'];
        $res['list'] = $list;
        $res['meat'] = $resList['page'];
        return $res;
    }


    /**
     * 获取统计详情
     * User: 龙哥·三年风水
     * Date: 2024/9/11
     * Time: 10:31
     * @ return mixed
     */

    public function getInfo($id){
        // TODO: Implement getInfo() method.
        $data = ASSAModel::dataFind(['id' => $id],'id,digitized_human_name,correct_rate,error_rate,id_card,create_time',true);
        return $data;
    }


    /**
     * 导出统计信息
     * User: 龙哥·三年风水
     * Date: 2024/9/11
     * Time: 10:32
     * @ return mixed
     */

    public function exportInfo($param){
        // TODO: Implement exportInfo() method.
        $where = [];
        if(!empty($param['digitized_human_name']))$where[] = ['digitized_human_name','like','%'.$param['digitized_human_name'].'%'];
        if(!empty($param['involved_date']))$where[] = ['involved_date','=',$param['involved_date']];
        if(!empty($param['id_card']))$where[] = ['id_card','=',$param['id_card']];
        $list = ASSAModel::getAll($where,'digitized_human_name,correct_rate,error_rate,id_card,create_time','create_time DESC');
        if(!$list)throw new BaseError('暂无可导出',50000,200);
        // 处理标题
        $title = ['机器人名称', '正确题数', '错误题数','身份证号','参与时间'];
        $filename = '答题参与记录';
        $spreadsheet = new Spreadsheet();
        $spreadsheet->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); //设置水平默认对齐方式
        $spreadsheet->getDefaultStyle()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); //设置垂直默认对齐方式
        $sheet = $spreadsheet->getActiveSheet();
        $everyDay = date('Y-m-d', time()). '_' .uniqid();
        foreach ($title as $key => $value) {
            $sheet->setCellValueByColumnAndRow($key+1, 1, $value);
        }
        $row = 2;
        foreach ($list as $item) {
            $column = 1;
            foreach ($item as $k => $value) {
                $sheet->setCellValueByColumnAndRow($column, $row, $value);
                $column++;
            }
            $row++;
        }
        $savename = '/storage/'.$filename . '_' . $everyDay . '.xlsx';
        $object = date('Y-m-d',time()).'/' . $filename . '_' . $everyDay . '.xlsx';
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('.' . $savename);
        $UploadFactory = new UploadFactory();
        $uploadHandle = $UploadFactory->getUploadHandle();
        $res = $uploadHandle->uploadFile($object,'.' . $savename);
        $data['url'] = $res;
        $filePath = app()->getRuntimePath() . $savename;
        @unlink($filePath);
        return $data;
    }
}

http://www.kler.cn/a/316592.html

相关文章:

  • [Docker#8] 容器配置 | Mysql | Redis | C++ | 资源控制 | 命令对比
  • 词嵌入方法(Word Embedding)
  • ODOO学习笔记(8):模块化架构的优势
  • 如何提高自动驾驶中惯性和卫星组合导航pbox的精度?
  • 单例模式详解:如何优雅地实现线程安全的单例
  • Flink CDC(SQL Client)连接 MySQL 数据库教程
  • 优化SQL查询的常见方法
  • FPGA随记——VIVADO中ASYNC_REG指令
  • 解决Echarts:宽度100%,渲染的宽度却是100px
  • Vue3快速入门+axios的异步请求(基础使用)
  • 基于SpringBoot的旅游网站系统
  • 硬盘数据能否自己在家恢复?探索数据恢复的可行性与方法
  • 信息技术引领的智能化未来
  • 滚雪球学SpringCloud[5.3讲]: 配置管理中的高可用与容错
  • How can I stream a response from LangChain‘s OpenAI using Flask API?
  • 认识知识产权——商标
  • postgresql gcc编译选项解释
  • JAVA执行引擎详细介绍
  • Qt Creator 集成开发环境 常见问题
  • 【代码随想录Day25】回溯算法Part04
  • CPU使用率较高排查和解决思路
  • vue + leaflet + 天地图实现搜索省份后高亮
  • Linux bash脚本本地开发环境(Git Bash)配置
  • 干货满满:嵌入式电阻的重要作用全知晓
  • 实验——完全使用Ansible部署多台服务器的服务
  • CTF 技能树 LOG -GIT泄露 笔记