<?php

namespace app\admin\controller;

use app\admin\common\Base;
use think\Request;
use think\Db;
use think\Log;
header("Content-type: text/html; charset=utf-8"); 

class Wechatinfro extends Base
{
	/**
	*初始化
	*/
	protected function _initialize(){
		parent::_initialize();
		/*if(session('admin_user_type') != 1){
	    		$result['erro']=-1;
	    		$result['msg']='权限不足';
	    		Response::create($result,'json')->send();
	    		exit;
	    	}*/
	}
	public function wechatUserList()
    {
        return $this->view->fetch('userList');
    }
     /**
     * 查看小程序注册用户信息
     * @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'].'%'];
    	}
        //升序获取菜单列表
        $res = Db::name('wechat_user')
        		->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['total'] = $res->total();//数据总条数
	$result['erro'] = 0;
	$result['msg'] = '查询成功';
	return json($result);
    }
    public function wechatRecordList()
    {
        return $this->view->fetch('wechatRecordList');
    }
   /**
     * 查看小程序记录
     * @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'].'%'];
    	}
		// 查询列表
    	$res = Db::name('wechat_calculate_record')
	       		->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['total'] = $res->total();//数据总条数
	$result['erro'] = 0;
	$result['msg'] = '查询成功';
	return json($result);
    }
}
