where("id",$student_id)->field("id")->find(); if(empty($info)){ return show("找不到该学生信息!"); } $data = [ "userid"=>$userid, "student_id"=>$student_id, "createtime"=>date("Y-m-d",time()) ]; $data['sha'] = sha1(json_encode($data)); Db::startTrans(); try { $info = Db::name("app_help_log")->where("sha", $data['sha'])->find(); if (!empty($info)) { return show("你今天已经为他助力过,谢谢!"); } else { Db::name("app_help_log")->insert($data); } $appHelp = Db::name("app_help")->where(["userid" => $userid, "student_id" => $student_id])->find(); if (empty($appHelp)) { Db::name("app_help")->insert([ "userid" => $userid, "student_id" => $student_id, "count" => 1 ]); } else { Db::name("app_help")->where(["id" => $appHelp['id']])->inc("count", 1)->update(); } Db::commit(); return show("助力成功!", SUCCESS_CODE, []); }catch (\Exception $e) { Db::rollback(); return show("助力失败!"); } } public function lists(){ if(empty($GLOBALS['data']['data']['student_id'])){ return show("请输入要助力的用户id!"); } $student_id = $GLOBALS['data']['data']['student_id']; $lastIndex = 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; } } if($lastIndex == 0) { $lastIndex = 1; } $list = Db::name("appHelp")->where("student_id",$student_id)->limit(env("page_count"))->order('count desc')->paginate([ "list_rows"=>env("PAGE_COUNT"), "page"=>$lastIndex ]); if(empty($list)) return show("获取成功", SUCCESS_CODE,$result); if($list->currentPage() < $list->lastPage()){ $result['lastIndex'] = $lastIndex +1; }else{ $result['lastIndex'] = 0; } $users = getAllUsersMessage($list,'userid','id,nickname,avatar'); foreach($list as $vo){ $result['list'][] = [ "id"=>$vo['id'], "userid"=>$vo['userid'], "username"=>empty($users[$vo['userid']]['nickname'])?'':$users[$vo['userid']]['nickname'], "count"=>$vo['count'] ]; } return show("获取成功!", SUCCESS_CODE, $result); } }