diff --git a/app/controller/Donation.php b/app/controller/Donation.php index 7339985..c36a117 100644 --- a/app/controller/Donation.php +++ b/app/controller/Donation.php @@ -47,5 +47,57 @@ 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_']]['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($UserIds)) { + return []; + } + $StudentIds = array_unique($StudentIds); + $getAllStudentsMessage = []; + $UserLists = Db::name("students")->where("id", "IN",$StudentIds)->field("nickname")->select()->toArray(); + foreach ($UserLists as $vo) { + $getAllStudentsMessage[$vo['id']] = $vo; + } + return $getAllStudentsMessage; + } } \ No newline at end of file