login_white = '';// $this->check_status = array();//用户状态校验 $this->check_mobile = array();//需要手机号 $this->check_headimg = array();//授权微信信息 $this->majia_white = array('get');//超级管理员披上马甲可操作权限 //$this->myuid = 4; $this->load->model('bobing/bobing_user_model', 'mdBobingUser'); $this->load->model('bobing/bobing_user_credit_model', 'mdBobingUserCredit'); $this->load->model('bobing/bobing_logs_model', 'mdBobingLogs'); $this->appConfig = $this->mdBobingUser->appConfig(); $this->appConfig['act_key'] = $this->appConfig['act_key']; } /** * Notes:首页 * Created on: 2020/8/10 11:47 * Created by: dengbw * @return array * @throws Exception */ protected function get() { $params = $this->input_param(); $re_u = $this->set_user($params); $cf_uid = intval($params['cf_uid']);//要助力id $this->myuid == $cf_uid && $cf_uid = 0; //$cf_uid = 2; $where = array('act_key' => $this->appConfig['act_key'], 'app_id' => $this->appConfig['app_id'], 'uid' => $this->myuid); $credit = $percentage = 0; if ($re_u) { $credit = $re_u['credit']; if (!$cf_uid && $re_u['if_kz'] == 0) {//更新开桌 $this->mdBobingUser->update(array("if_kz" => 1), $where); } $sum = $this->mdBobingUser->count(array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'])); $row = $this->mdBobingUser->count(array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'credit<=' => $credit)); $percentage = round($row / $sum * 100, 2); } $share = array('title' => '送你100元现金,帮我博取iPhone13、汽车大奖', 'content' => '
目前累计' . $credit . '幸运分,打败全闽南' . $percentage . '%的用户,
继续邀请好友助力博饼,
冲刺购物卡、苹果手机、汽车大奖~
添加小狸微信,还可立即获得288幸运分!
' , 'img' => $this->mdBobingUser->appImg('share_tip', $this->car_id), 'posters' => $this->mdBobingUser->appImg('posterbg', $this->car_id)); $result['valid_nums'] = $this->get_valid_nums($cf_uid); $result['top_title'] = $this->get_top_title($cf_uid); $result['users'] = $this->pr_users(true, array('cf_uid' => $cf_uid)); $result['logs'] = $this->pr_logs($cf_uid); $result['share'] = $share; $result['invite_theme'] = $this->mdBobingUser->appImg('invite_theme', $this->car_id); $result['banner2'] = $this->mdBobingUser->appImg('banner2', $this->car_id); return $result; } /** * Notes:博一把 * Created on: 2021/8/10 15:18 * Created by: dengbw */ protected function put_bo() { $this->check_game_date(); $cf_uid = intval($this->input_param('cf_uid'));//要助力id $this->myuid == $cf_uid && $cf_uid = 0; //$cf_uid = 2; if ($cf_uid) { $where = array('act_key' => $this->appConfig['act_key'], 'app_id' => $this->appConfig['app_id'], 'uid' => $cf_uid); $re_u = $this->mdBobingUser->get($where); if (!$re_u) { throw new Hd_exception('无此用户', API_CODE_FAIL); } } //$cf_uid = 14; $this->load->library('bobing/bo'); $this->bo->uid = $this->myuid; $valid_nums = $this->get_valid_nums($cf_uid);//获取博饼剩余数 $this->bo->valid_nums = $valid_nums['value']; $nickname = ''; if ($cf_uid) {//助力博 $this->bo->cf_uid = $cf_uid; $result = $this->bo->zl_bo(); $reU = $this->app_user_model->get(array('id' => $this->myuid)); $reU['nickname'] && $nickname = $reU['nickname']; } else {//开桌博 $result = $this->bo->kz_bo(); } //status 1开桌博饼次数用完2助力数用完 if ($result['status']) {//返回错误信息 if ($result['status'] == API_CODE_FAIL) { throw new Hd_exception($result['content'], $result['status']); } return $result; } $status = 0; $data['popup'] = $result['popup']; //status 3抽到购车金4抽到红包 $log = $cf_uid ? $nickname . "为桌长博到{$result['credit']}幸运分" : "桌长博到{$result['credit']}幸运分"; if ($result['car_gold'] > 0) { $status = 3; $data['car_gold'] = $result['car_gold']; $log .= $cf_uid ? "和{$result['car_gold']}元购车金" : ",额外幸运地博到{$result['car_gold']}元购车金"; } else if ($result['hong_bao'] > 0) { $status = 4; $data['hong_bao_url'] = http_host_com('home') . "/h5/hongbao?id={$result['lid']}&uid={$this->myuid}"; $log .= ",额外幸运地博到一个现金红包"; } $data['log'] = $log; $data['status'] = $status; $valid_nums['value'] = $this->bo->valid_nums <= 0 ? 0 : $this->bo->valid_nums - 1; $data['dices'] = $result['dices']; $data['level'] = $result['level']; $data['bo_title'] = $result['level_name'] . ' + ' . $result['credit']; $data['valid_nums'] = $valid_nums; $data['top_title'] = $this->get_top_title($cf_uid); return $data; } protected function get_users() { $params = $this->input->get(); $this->data['users'] = $this->pr_users(false, $params); return $this->data; } /** * Notes:获取博饼剩余数 * Created on: 2021/8/17 10:24 * Created by: dengbw * @param $cf_uid * @return array */ private function get_valid_nums($cf_uid) { if ($cf_uid) { $zl_nums = $this->mdBobingLogs->count(array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'] , 'uid' => $cf_uid, 'cf_uid' => $this->myuid, 'type' => 1)); $zl_nums = intval($this->appConfig['zl_nums'] - $zl_nums);//剩下助力博饼数 $valid_nums = array('title' => '剩余助力次数:', 'value' => $zl_nums <= 0 ? 0 : $zl_nums); } else { $kz_nums = $this->mdBobingLogs->count(array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'] , 'uid' => $this->myuid, 'type' => 0)); $kz_nums = intval($this->appConfig['kz_nums'] - $kz_nums);//剩下开桌博饼数 $valid_nums = array('title' => '剩余博饼次数:', 'value' => $kz_nums <= 0 ? 0 : $kz_nums); } return $valid_nums; } /** * Notes:博饼顶部标题 * Created on: 2021/9/1 17:21 * Created by: dengbw * @param $cf_uid * @param string $reU * @return string */ private function get_top_title($cf_uid) { if ($cf_uid) { $reU = $this->app_user_model->get(array('id' => $cf_uid)); $top_title = $reU['nickname'] ? $reU['nickname'] . '的桌子' : '未知用户的桌子'; } else { $credit = $ranking = 0; $where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'bo_date' => date('Y-m-d')); $re_c = $this->mdBobingUserCredit->get(array_merge($where, array('uid' => $this->myuid))); $re_c && $credit = $re_c['credit']; $ranking = $this->mdBobingUserCredit->count(array_merge($where, array('credit>=' => $credit, 'uid<>' => $this->myuid))) + 1;//排名 $ranking > 100 && $ranking = '100名外'; $top_title = "今日博饼分:{$credit} | 今日排名:{$ranking}"; } return $top_title; } private function pr_users($return_array = false, $params = array()) { $page = $params['page'] ? intval($params['page']) : 1; $size = $params['size'] ? intval($params['size']) : 7; $cf_uid = intval($params['cf_uid']); //$cf_uid = 14; $list = array(); if ($cf_uid) { $where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'uid' => $cf_uid, 'type' => 1); } else { $where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'uid' => $this->myuid, 'type' => 1); } $total = $this->mdBobingLogs->count($where, 'distinct(cf_uid)'); if ($total) { $res_u = $this->mdBobingLogs->select($where, 'id DESC', $page, $size, 'distinct(cf_uid)'); if ($res_u) { $uids = implode(',', array_column($res_u, 'cf_uid')); $list = $this->app_user_model->select(array('id in (' . $uids . ')' => null), 'id DESC', 0, 0, 'nickname,headimg'); } } if ($return_array) { return $list; } return array('list' => $list, 'total' => $total); } /** * Notes:获取博饼记录 * Created on: 2021/8/19 11:16 * Created by: dengbw * @param $cf_uid * @return array */ private function pr_logs($cf_uid) { //$cf_uid = 14; $logs = array(); if ($cf_uid) { $where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'uid' => $cf_uid); } else { $where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'uid' => $this->myuid); } $res_l = $this->mdBobingLogs->select($where, 'id DESC', 1, 7, 'credit,hong_bao,car_gold,type,uid,cf_uid'); if ($res_l) { $uids = array_column($res_l, 'cf_uid'); array_unique($uids); $users2 = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname'); $nicknames = array();//微信昵称 foreach ($users2 as $key => $value) { $nicknames[$value['id']] = $value['nickname'] ? $value['nickname'] : '****'; } foreach ($res_l as $key => $value) { $content = ''; if ($value['type'] == 0) { $content = "桌长博到{$value['credit']}幸运分"; $value['car_gold'] > 0 && $content .= "和{$value['car_gold']}元购车金"; } else if ($value['type'] == 1) { $content = $nicknames[$value['cf_uid']] . "为桌长博到{$value['credit']}幸运分"; $value['car_gold'] > 0 && $content .= "和{$value['car_gold']}元购车金"; $value['hong_bao'] > 0 && $content .= ",额外博到现金红包"; } else if ($value['type'] == 2) { $content = "桌长加企业微信得到{$value['credit']}幸运分"; } $logs[] = $content; } } return $logs; } /** * Notes:检查博饼时间 * Created on: 2021/8/27 14:25 * Created by: dengbw * @throws Hd_exception */ protected function check_game_date() { $date = date('Y-m-d H:i'); if ($this->appConfig['game_start_date'] > $date) { throw new Hd_exception('博饼未开始', API_CODE_FAIL); } if ($this->appConfig['game_end_date'] < $date) { throw new Hd_exception('博饼已结束', API_CODE_FAIL); } } /** * Notes:设置car_id * Created on: 2021/9/2 15:32 * Created by: dengbw * @param array $params * @return mixed */ private function set_user($params = array()) { $this->myuid == $params['cf_uid'] && $params['cf_uid'] = 0; $where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'uid' => $this->myuid); $re_u = $this->mdBobingUser->get($where); if ($re_u['car_id']) { $this->car_id = $re_u['car_id']; } else if ($params['car_id']) { $this->car_id = $params['car_id']; } else if ($params['cf_uid']) { $where['uid'] = $params['cf_uid']; $re_u_c = $this->mdBobingUser->get($where); $this->car_id = $re_u_c['car_id']; } !$this->car_id && $this->car_id = 13; if (!$re_u['car_id']) { $where['uid'] = $this->myuid; $this->mdBobingUser->update(array("car_id" => $this->car_id), $where); } if (!$re_u) { $where['uid'] = $this->myuid; $addUser = array_merge($where, array('car_id' => $this->car_id, 'c_time' => time())); $this->mdBobingUser->add($addUser); } return $re_u; } }