<?php
/**
 * 微信用户信息管理公共控制器
 * 提供统一的业务逻辑，供admin和adminghd模块继承使用
 */
namespace app\common\controller;

use app\common\common\BaseController;
use think\Request;
use think\Db;

class WechatinfroBase extends BaseController
{
    /**
     * 查看小程序注册用户信息
     * @author hjc
     * @date 2024-05-14
     */
    public function getWechatUserList(Request $request)
    {
        $post = $request->param();
        
        $page = isset($post['page']) && !empty($post['page']) ? $post['page'] : 1; // 页数
        $page_size = isset($post['page_size']) && !empty($post['page_size']) ? $post['page_size'] : 30; // 每页条数
        
        // 搜索
        $where = [];
        if (isset($post['title']) && !empty($post['title'])) {
            $where['nickname'] = ['like', '%' . $post['title'] . '%'];
        }
        
        // 获取用户表名
        $tableName = $this->getTableName('user');
        
        // 升序获取菜单列表
        $res = Db::name($tableName)
            ->field('uid,nickname,headimg,create_time')
            ->where($where)
            ->order('create_time desc')
            ->paginate($page_size, false, ['page' => $page]);
        
        $lists = $res->items();
        $start = ($page - 1) * $page_size;
        foreach ($lists as $k => $v) {
            $start += 1;
            $lists[$k]['no_id'] = $start;
        }
        
        $result['lists'] = $lists;
        $result['lastPage'] = $res->lastPage(); // 总页数
        $result['currentPage'] = $res->currentPage(); // 当前页
        $result['erro'] = 0;
        $result['msg'] = '查询成功';
        return json($result);
    }
    
    /**
     * 查看小程序记录
     * @author hjc
     * @date 2024-05-14
     */
    public function getWechatRecordList(Request $request)
    {
        $post = $request->param();
        
        $page = isset($post['page']) && !empty($post['page']) ? $post['page'] : 1; // 页数
        $page_size = isset($post['page_size']) && !empty($post['page_size']) ? $post['page_size'] : 30; // 每页条数
        
        // 搜索
        $where = [];
        if (isset($post['title']) && !empty($post['title'])) {
            $where['name'] = ['like', '%' . $post['title'] . '%'];
        }
        
        // 获取计算记录表名
        $tableName = $this->getTableName('calculate_record');
        
        // 查询列表
        $res = Db::name($tableName)
            ->field('id,name,age,height,bone_age,father_height,mother_height,IGF,LH,uterus_thickness,calculate_resutlt,create_time')
            ->where($where)
            ->order('create_time desc')
            ->paginate($page_size, false, ['page' => $page]);
        
        $lists = $res->items();
        $start = ($page - 1) * $page_size;
        foreach ($lists as $k => $v) {
            $start += 1;
            $lists[$k]['no_id'] = $start;
        }
        
        $result = array();
        $result['lists'] = $lists;
        $result['lastPage'] = $res->lastPage(); // 总页数
        $result['currentPage'] = $res->currentPage(); // 当前页
        $result['erro'] = 0;
        $result['msg'] = '查询成功';
        return json($result);
    }
}
