Files
heping-api/app/controller/Donation.php
2022-09-16 13:37:54 +08:00

109 lines
4.0 KiB
PHP

<?php
namespace app\controller;
use think\facade\Db;
class Donation
{
public function lists(){
if(empty($GLOBALS['data']['data']['student_id'])){
return show("请正确上传用户信息!", ERROR_CODE,[]);
}
$student_id = $GLOBALS['data']['data']['student_id'];
$lastIndex = lastIndex();
if($lastIndex == 0){
$where = "id > 0";
}else{
$where = "id < ".$lastIndex;
}
$result = [];
//查询用户信息
$result['userinfo'] = [];
if($lastIndex==0) {
$userinfo = Db::name("student")->where("id", $student_id)->field("id,nickname,identifier,avatar,age,type,disabled as is_disabled,city,school,hot,hot_count")->find();
if (!empty($userinfo)) {
$result['userinfo'] = $userinfo;
}
}
$result['donation_list'] = [];
$list = Db::name("order")->where(['student_id' => $student_id,"status"=>1])->where($where)->order("id desc")->select()->toArray();
$users = getAllUsersMessage($list,"user_id","id,nickname,avatar,shiyou_id");
foreach($list as $vo){
$result['lastIndex'] = $vo['id'];
$result['donation_list'][] = [
"nickname"=>$users[$vo["user_id"]]['nickname'],
"identity"=>empty($users[$vo["user_id"]]['shiyou_id'])?1:0,
"avatar"=>empty($users[$vo['user_id']]['avatar'])?'':$users[$vo['user_id']]['avatar'],
"amount"=>$vo['amount'],
];
}
if(count($list)<env("PAGE_COUNT")){
$result["lastIndex"] = 0;
}
return show("获取成功",SUCCESS_CODE,$result);
}
public function certificate()
{
$userid = $GLOBALS['data']['userid'];
if(empty($userid)){
return show("请登录后再查看!",NEED_LOGIN);
}
$lastIndex = lastindex();
$result = [];
if($lastIndex == 0){
$where = " id > 0";
}else{
$where = " id < ".$lastIndex;
}
$result['lastIndex'] = 0;
$result['total'] = 0;
$result['list'] = [];
$list = Db::name("order")->where(['user_id'=>$userid,'status'=>1])->where($where)->order("id desc")->limit(env("page_count"))->select()->toArray();
if(!empty($list)){
$result['total'] = Db::name("order")->where(['user_id'=>$userid,'status'=>1])->where($where)->count();
$appUser = getAllUsersMessage($list,"user_id","id,nickname");
$studentUser = $this->getStudents($list);
foreach ($list as $key => $vo) {
$result['lastIndex'] = $vo['id'];
$result["list"][] = [
"id"=>$vo['id'],
"date"=> explode(" ",$vo['create_time'])[0],
"student_nickname"=>$studentUser[$vo['student_id']]['nickname'],
"donation_nickname"=>$appUser[$vo['user_id']]['nickname'],
"avatar"=>$studentUser[$vo['student_id']]['avatar'],
"type"=>$studentUser[$vo['student_id']]['type'],
"is_disabled"=>$studentUser[$vo['student_id']]['is_disabled'],
];
}
if (count($list) < env("PAGE_COUNT")) {
$result["lastIndex"] = 0;
}
}
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
private function getStudents($list){
$StudentIds = [];
foreach ($list as $vo) {
$StudentIds[] = $vo["student_id"];
}
if (empty($StudentIds)) {
return [];
}
$StudentIds = array_unique($StudentIds);
$getAllStudentsMessage = [];
$UserLists = Db::name("student")->where("id", "IN",$StudentIds)->field("id,nickname,avatar,type,disabled as is_disabled")->select()->toArray();
foreach ($UserLists as $vo) {
$getAllStudentsMessage[$vo['id']] = $vo;
}
return $getAllStudentsMessage;
}
}