This commit is contained in:
2022-09-16 10:53:37 +08:00

View File

@@ -47,5 +47,58 @@ class Donation
} }
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['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)){
$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'],
];
}
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")->select()->toArray();
foreach ($UserLists as $vo) {
$getAllStudentsMessage[$vo['id']] = $vo;
}
return $getAllStudentsMessage;
}
} }