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']; $this->car_id = $inputs['car_id'] ? intval($inputs['car_id']) : 13; } /** * 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; $credit = $percentage = $if_kz = $car_gold = 0; if ($re_u) { $car_gold = $re_u['car_gold'] + $re_u['buy_car_gold'] + $re_u['lotter_gold']; $credit = $re_u['credit']; if ($cf_uid == 0 && $re_u['if_kz'] == 0) { $this->mdBobingUser->update(array('if_kz' => 1), array('id' => $re_u['id'])); } $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_content = array('我已经博取' . $car_gold . '元购车金和' . $credit . '幸运分', '运气超越了全闽南' . $percentage . '%的用户。', '快来帮我助力博饼冲击汽车大奖,', '助力博饼可以获得现金奖励,最高100元哦!'); $content = '
目前累计' . $car_gold . '元购车金和' . $credit . '幸运分,您的运气爆表,
超越了全闽南' . $percentage . '%的用户,
邀请好友助力博饼,获得更多购车金,冲击汽车大奖~
助力好友可获得现金红包,最高100元!
'; $share = array('title' => '送你100元现金,帮我博取购车金和汽车大奖', 'share_content' => $share_content, 'content' => $content , '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']; $this->bo->car_id = $this->car_id; $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 .= "和{$result['car_gold']}元购车金"; } if ($cf_uid) { $status = 4; $data['hong_bao_url'] = http_host_com('home') . "/h5/hongbao?id={$result['lid']}&uid={$this->myuid}"; } $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 put_kz() { //throw new Hd_exception('开桌要先进群', API_CODE_FAIL); $where = array('act_key' => $this->appConfig['act_key'], 'app_id' => $this->appConfig['app_id'], 'uid' => $this->myuid); $re_u = $this->mdBobingUser->get($where); if ($re_u['if_kz'] == 1) { throw new Hd_exception('您已经开过桌了', API_CODE_FAIL); } $ret = $this->mdBobingUser->update(array("if_kz" => 1), array('id' => $re_u['id'])); if (!$ret) { throw new Hd_exception('开桌失败', API_CODE_FAIL); } throw new Hd_exception('开桌成功', API_CODE_SUCCESS); } 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, 'bo_date' => date('Y-m-d'))); $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) { $top_titles = array(); if ($cf_uid) { $reU = $this->app_user_model->get(array('id' => $cf_uid)); $top_title = $reU['nickname'] ? $reU['nickname'] . '的博饼桌' : '未知用户的博饼桌'; $top_titles[] = array('title' => $top_title, 'url' => ''); } else { $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))); $credit = $re_c['credit'] ? $re_c['credit'] : 0; $ranking = $this->mdBobingUserCredit->count(array_merge($where, array('credit>=' => $credit, 'uid<>' => $this->myuid))) + 1;//排名 $ranking > 100 && $ranking = '100名外'; $top_titles[] = array('title' => "今日博饼分:{$credit} | 今日排名:{$ranking}", 'url' => ''); $where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'uid' => $this->myuid); $re_u = $this->mdBobingUser->get($where); $car_gold = $re_u['car_gold'] + $re_u['buy_car_gold'] + $re_u['lotter_gold']; $top_titles[] = array('title' => "累计购车金:{$car_gold}元 查看购车金适用车型>>", 'url' => '/bobing/pages/game/signUp/index'); } return $top_titles; } 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) { if ($value['credit'] > 0 && $value['car_gold'] > 0) { $content = "桌长博到{$value['credit']}幸运分和{$value['car_gold']}元购车金"; } else if ($value['credit'] > 0) { $content = "桌长博到{$value['credit']}幸运分"; } else if ($value['car_gold'] > 0) { $content = "桌长博到{$value['car_gold']}元购车金"; } } else if ($value['type'] == 1) { $nickname = $nicknames[$value['cf_uid']]; if ($value['credit'] > 0 && $value['car_gold'] > 0) { $content = $nickname . "为桌长博到{$value['credit']}幸运分和{$value['car_gold']}元购车金"; } else if ($value['credit'] > 0) { $content = $nickname . "为桌长博到{$value['credit']}幸运分"; } else if ($value['car_gold'] > 0) { $content = $nickname . "为桌长博到{$value['car_gold']}元购车金"; } } else if ($value['type'] == 2) { $content = "桌长加企业微信得到{$this->appConfig['wxqy_nums']}购车金"; } $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:设置用户 * Created on: 2021/9/2 15:32 * Created by: dengbw * @param array $params * @return mixed */ private function set_user($params = array()) { $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) { $addUser = array_merge($where, array('c_time' => time())); $this->mdBobingUser->add($addUser); //添加购物金 $re_au = $this->app_user_model->get(array('id' => $this->myuid)); if ($re_au['unionid']) { $this->load->model('app/app_wechatqy_model', 'mdWechatqy'); $re_wx = $this->mdWechatqy->get(array('unionid' => $re_au['unionid'], 'app_id' => $this->appConfig['app_id'])); if ($re_wx) {//有加企业微信 $this->app_user_model->update(array('wxqy' => 1), array('id' => $re_au['id'])); $this->load->library('bobing/bo'); $this->bo->uid = $this->myuid; $this->bo->wxqy_car_gold(); //加购物金 } } } return $re_u; } }