519 lines
21 KiB
PHP
519 lines
21 KiB
PHP
<?php
|
||
defined('WXAPP_ITEMS') OR exit('No direct script access allowed');
|
||
ini_set('display_errors', 'On');
|
||
error_reporting(E_ERROR);
|
||
|
||
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
||
|
||
/**
|
||
* Notes:博饼首页
|
||
* Created on: 2021/8/10 15:16
|
||
* Created by: dengbw
|
||
*/
|
||
class Home extends Wxapp
|
||
{
|
||
private $appConfig, $car_id = 13;
|
||
|
||
function __construct($inputs, $app_key)
|
||
{
|
||
parent::__construct($inputs, $app_key);
|
||
$this->login_white = '';//
|
||
$this->check_status = array();//用户状态校验
|
||
$this->check_mobile = array();//需要手机号
|
||
$this->check_headimg = array();//授权微信信息
|
||
$this->majia_white = array('get');//超级管理员披上马甲可操作权限
|
||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||
$this->load->model('bobing/bobing_user_credit_model', 'mdBobingUserCredit');
|
||
$this->load->model('apporder/order_purchase_model', 'mdOrderPurchase');
|
||
$this->appConfig = $this->mdBobingUser->appConfig();
|
||
$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();
|
||
$this->set_user($params);
|
||
$this->data['banner'] = $this->mdBobingUser->appImg('banner', $this->car_id);
|
||
$bo_nums = 0;//$this->mdBobingUser->boNums($this->appConfig['act_key'])
|
||
$this->data['bodata'] = array('title' => "累计博饼次数", 'content' => $this->appConfig['content'], 'bo_nums' => $bo_nums);
|
||
$lucky_car[] = array('title' => '', 'img' => $this->mdBobingUser->appImg('index-tip'), 'url' => '/bobing/pages/game/signUp/index');
|
||
$share = array('title' => '送你100元现金,帮我博取iPhone13、汽车大奖', 'img' => $this->mdBobingUser->appImg('share_tip', $this->car_id));
|
||
$this->data['lucky_car'] = $lucky_car;
|
||
$this->data['group'] = $this->appConfig['group'];
|
||
$this->data['share'] = $share;
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:排名
|
||
* Created on: 2021/8/20 15:23
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
protected function get_ranking()
|
||
{
|
||
$this->set_user();
|
||
$this->data['banner2'] = $this->mdBobingUser->appImg('banner2', $this->car_id);
|
||
$this->data['dates'] = $this->pr_dates(false);
|
||
$this->data['rank'] = $this->pr_ranking_date(true);//今日幸运分
|
||
$this->data['title'] = $this->appConfig['title'];
|
||
$this->data['winners_day'] = $this->pr_winners(true);
|
||
$this->data['winners_weeks'] = $this->pr_winners_lottery(2);
|
||
$this->data['winners_all'] = $this->pr_winners_lottery(3);
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:今日幸运分排名
|
||
* Created on: 2021/8/20 15:23
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
public function get_ranking_date()
|
||
{
|
||
$params = $this->input->get();
|
||
$this->data['rank'] = $this->pr_ranking_date(false, $params);
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:周排名
|
||
* Created on: 2021/8/20 15:23
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
public function get_ranking_weeks()
|
||
{
|
||
$params = $this->input->get();
|
||
$page = $params['page'] ? intval($params['page']) : 1;
|
||
$size = $params['size'] ? intval($params['size']) : 50;
|
||
$list = array();
|
||
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'credit >' => 0);
|
||
$date = date('Y-m-d');
|
||
if ($date >= '2021-09-13' && $date <= '2021-09-19') {
|
||
$where["bo_date >="] = '2021-09-13';
|
||
$where["bo_date <="] = '2021-09-19';
|
||
} else if ($date >= '2021-09-20' && $date <= '2021-09-26') {
|
||
$where["bo_date >="] = '2021-09-20';
|
||
$where["bo_date <="] = '2021-09-26';
|
||
} else if ($date >= '2021-09-27' && $date <= '2021-10-03') {
|
||
$where["bo_date >="] = '2021-09-27';
|
||
$where["bo_date <="] = '2021-10-03';
|
||
} else {
|
||
$where["bo_date >="] = '2021-08-31';
|
||
$where["bo_date <="] = '2021-09-12';
|
||
}
|
||
$select = 'uid, sum(credit) as credit_sum';
|
||
$res_c = $this->mdBobingUserCredit->select_groupby('uid', $where, 'credit_sum desc', $page, $size, $select);
|
||
if ($res_c) {
|
||
$users = array();//微信昵称
|
||
$uids = array_column($res_c, 'uid');
|
||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||
foreach ($re_u as $key => $value) {
|
||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||
}
|
||
foreach ($res_c as $key => $value) {
|
||
$user = $users[$value['uid']];
|
||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||
, 'credit' => $value['credit_sum'] . '分');
|
||
}
|
||
}
|
||
$this->data['weeks'] = array('list' => $list);
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:总幸运分排名
|
||
* Created on: 2021/8/20 15:24
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
public function get_ranking_all()
|
||
{
|
||
$params = $this->input->get();
|
||
$this->data['rank'] = $this->pr_ranking_all(false, $params);
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:中奖用户
|
||
* Created on: 2021/8/20 15:38
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
public function get_winners()
|
||
{
|
||
$params = $this->input->get();
|
||
$this->data['winners'] = $this->pr_winners(false, $params);
|
||
return $this->data;
|
||
}
|
||
|
||
private function pr_ranking_date($return_array = false, $params = array())
|
||
{
|
||
$page = $params['page'] ? intval($params['page']) : 1;
|
||
$size = $params['size'] ? intval($params['size']) : 50;
|
||
$bo_date = date('Y-m-d');
|
||
$list = array();
|
||
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'bo_date' => $bo_date, 'credit >' => 0);
|
||
$total = $this->mdBobingUserCredit->count($where);
|
||
if ($total) {
|
||
$res_c = $this->mdBobingUserCredit->select($where, 'credit desc,u_time asc', $page, $size, 'uid,credit');
|
||
if ($res_c) {
|
||
$users = array();//微信昵称
|
||
$uids = array_column($res_c, 'uid');
|
||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||
foreach ($re_u as $key => $value) {
|
||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||
}
|
||
foreach ($res_c as $key => $value) {
|
||
$user = $users[$value['uid']];
|
||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||
, 'credit' => $value['credit'] . '分');
|
||
}
|
||
}
|
||
}
|
||
if ($return_array) {
|
||
return $list;
|
||
}
|
||
return array('list' => $list, 'total' => $total);
|
||
}
|
||
|
||
private function pr_ranking_all($return_array = false, $params = array())
|
||
{
|
||
$page = $params['page'] ? intval($params['page']) : 1;
|
||
$size = $params['size'] ? intval($params['size']) : 50;
|
||
$list = array();
|
||
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'credit >' => 0);
|
||
$total = $this->mdBobingUser->count($where);
|
||
if ($total) {
|
||
$res_c = $this->mdBobingUser->select($where, 'credit desc,u_time asc', $page, $size, 'uid,credit');
|
||
if ($res_c) {
|
||
$users = array();//微信昵称
|
||
$uids = array_column($res_c, 'uid');
|
||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||
foreach ($re_u as $key => $value) {
|
||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||
}
|
||
foreach ($res_c as $key => $value) {
|
||
$user = $users[$value['uid']];
|
||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||
, 'credit' => $value['credit'] . '分');
|
||
}
|
||
}
|
||
}
|
||
if ($return_array) {
|
||
return $list;
|
||
}
|
||
return array('list' => $list, 'total' => $total);
|
||
}
|
||
|
||
private function pr_winners($return_array = false, $params = array())
|
||
{
|
||
$dates = $this->pr_dates(false);
|
||
$date_default = $dates ? $dates[0] : date('Y-m-d');
|
||
$bo_date = $params['date'] ? $params['date'] : $date_default;
|
||
//$bo_date = '2021-08-19';
|
||
$list = array();
|
||
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'bo_date' => $bo_date, 'lottery' => 1);
|
||
$total = $this->mdBobingUserCredit->count($where);
|
||
if ($total) {
|
||
$res_c = $this->mdBobingUserCredit->select($where, 'credit desc,u_time asc', 0, 0, 'uid,credit');
|
||
if ($res_c) {
|
||
$users = array();//微信昵称
|
||
$uids = array_column($res_c, 'uid');
|
||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||
foreach ($re_u as $key => $value) {
|
||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||
}
|
||
foreach ($res_c as $key => $value) {
|
||
$user = $users[$value['uid']];
|
||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||
, 'credit' => $value['credit'] . '分');
|
||
}
|
||
}
|
||
}
|
||
if ($return_array) {
|
||
return $list;
|
||
}
|
||
return array('list' => $list, 'total' => $total);
|
||
}
|
||
|
||
private function pr_winners_lottery($lottery)
|
||
{
|
||
$list = array();
|
||
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'lottery' => $lottery);
|
||
$res_c = $this->mdBobingUserCredit->select($where, 'credit desc,u_time asc', 0, 0, 'uid,credit');
|
||
if ($res_c) {
|
||
$users = array();//微信昵称
|
||
$uids = array_column($res_c, 'uid');
|
||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||
foreach ($re_u as $key => $value) {
|
||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||
}
|
||
foreach ($res_c as $key => $value) {
|
||
$user = $users[$value['uid']];
|
||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||
, 'credit' => $value['credit'] . '分');
|
||
}
|
||
}
|
||
return $list;
|
||
}
|
||
|
||
/**
|
||
* Notes:规则
|
||
* Created on: 2021/8/19 17:08
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
protected function get_rule()
|
||
{
|
||
$this->set_user();
|
||
$this->data['banner2'] = $this->mdBobingUser->appImg('banner2', $this->car_id);
|
||
$this->data['rule'] = $this->appConfig['rule'];
|
||
$this->data['title'] = $this->appConfig['title'];
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:礼品
|
||
* Created on: 2021/8/19 17:45
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
protected function get_gift()
|
||
{
|
||
$this->set_user();
|
||
$this->data['banner2'] = $this->mdBobingUser->appImg('banner2', $this->car_id);
|
||
$this->data['gift'] = $this->mdBobingUser->appImg('gift', $this->car_id);
|
||
$this->data['title'] = $this->appConfig['title'];
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:我的
|
||
* Created on: 2021/8/27 10:29
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
protected function get_mine()
|
||
{
|
||
$credit = $car_gold = 0;
|
||
$re_u = $this->set_user();
|
||
$tips = '';
|
||
if ($re_u) {
|
||
$credit = $re_u['credit'];
|
||
$car_gold = $re_u['car_gold'] + $re_u['buy_car_gold'] + $re_u['lotter_gold'];
|
||
if ($re_u['buy_car_gold'] > 0) {
|
||
$tips = '<div><span style="color:#dd4223;">☛ 您已添加顾问领取到' . intval($re_u['buy_car_gold']) . '元购车金</span></div>';
|
||
}
|
||
if ($credit) {
|
||
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key']);
|
||
$re_uc = $this->mdBobingUserCredit->get(array_merge($where, array('uid' => $this->myuid, 'lottery>' => 0)));
|
||
if ($re_uc) {
|
||
$bo_date = date('n月d日', strtotime($re_uc['bo_date']));
|
||
$tips .= '<div><span style="color:#dd4223;">☛ 您在' . $bo_date . '获得单日排行榜前' . $this->appConfig['lottery_nums']
|
||
. '名,<br>获得购车金' . $this->appConfig['lotter_gold'] . '元,购车金可叠加使用</span></div>';
|
||
} else {
|
||
$sum = $this->mdBobingUser->count($where);
|
||
$row = $this->mdBobingUser->count(array_merge($where, array('credit<=' => $credit)));
|
||
$percentage = round($row / $sum * 100, 2);
|
||
$tips .= '<div>您已打败全闽南<span style="color:#dd4223;">' . $percentage . '%</span>的用户</div>';
|
||
}
|
||
$tips .= '<div>继续邀请好友助力博饼,冲刺大奖吧~</div>';
|
||
}
|
||
}
|
||
$menulist[] = array('title' => '预约试驾', 'url' => '/bobing/pages/game/signUp/index', 'img' => $this->mdBobingUser->appImg('icon-mine-4'));
|
||
$menulist[] = array('title' => '我的海报', 'url' => '/bobing/pages/game/invite/index', 'img' => $this->mdBobingUser->appImg('icon-mine-2'));
|
||
$menulist[] = array('title' => '联系客服', 'url' => '/pages/', 'img' => $this->mdBobingUser->appImg('icon-mine-3'));
|
||
$menulist[] = array('title' => '关于狸车', 'url' => 'lc://switchTab/pages/index/index', 'img' => $this->mdBobingUser->appImg('icon-mine-5'));
|
||
$data = array(
|
||
"title" => $this->appConfig['title'],
|
||
"credit" => array('title' => '幸运分', 'value' => $credit),
|
||
"car_gold" => array('title' => '购车金', 'value' => $car_gold),
|
||
"tips" => $tips,
|
||
"menulist" => $menulist
|
||
);
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* Notes:获取图片
|
||
* Created on: 2021/9/7 15:40
|
||
* Created by: dengbw
|
||
* @return array
|
||
* @throws Hd_Exception
|
||
*/
|
||
protected function get_img()
|
||
{
|
||
$params = $this->input->get();
|
||
$name = $params['name'];
|
||
if (!$name) {
|
||
throw new Hd_Exception('图片名称必填', API_CODE_INVILD_PARAM);
|
||
}
|
||
$urls = array();
|
||
if (strstr($name, ',')) {
|
||
$names = explode(',', $name);
|
||
foreach ($names as $key => $value) {
|
||
$urls[] = $this->mdBobingUser->appImg($value, $this->car_id);
|
||
}
|
||
} else {
|
||
$urls = $this->mdBobingUser->appImg($name, $this->car_id);
|
||
}
|
||
$this->data['img'] = $urls ? $urls : '';
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* Notes:购买购车金 暂不需要
|
||
* Created on: 2021/8/31 9:57
|
||
* Created by: dengbw
|
||
* @return array
|
||
*/
|
||
protected function get_buy_car_gold()
|
||
{
|
||
$where = array('app_id' => $this->appConfig['act_key'], 'app_uid' => $this->myuid, 'item_id' => 1);
|
||
$re_p = $this->mdOrderPurchase->get($where);
|
||
if (!$re_p) {
|
||
$sid = create_order_no(350200);
|
||
$add_data = [
|
||
'app_id' => $this->appConfig['act_key'],
|
||
'app_uid' => $this->myuid,
|
||
'sid' => $sid,
|
||
'item_id' => 1,
|
||
'item_title' => '9.9抢500购车金',
|
||
'item_num' => 1,
|
||
'type' => 3,
|
||
'item_price' => 9.9,
|
||
'total_price' => 9.9,//9.9
|
||
'uname' => $this->session['nickname'],
|
||
'mobile' => $this->session['mobile'],
|
||
'payway' => 1,
|
||
'status' => 1,
|
||
'status_detail' => 11,
|
||
'c_time' => time()
|
||
];
|
||
$order_id = $this->mdOrderPurchase->add($add_data);
|
||
$date = array('sid' => $sid, 'tips' => $order_id ? '' : '购买失败请重试');
|
||
} else {
|
||
$date = array('sid' => $re_p['sid'], 'tips' => $re_p['status'] == 2 ? '每人限购一次' : '');
|
||
}
|
||
return $date;
|
||
}
|
||
|
||
/**
|
||
* Notes:获取二维码
|
||
* Created on: 2021/8/27 16:34
|
||
* Created by: dengbw
|
||
* @return array
|
||
* @throws Hd_Exception
|
||
*/
|
||
protected function get_qrcode()
|
||
{
|
||
$scene = $this->input_param('scene');
|
||
$page = $this->input_param('page');
|
||
$width = $this->input_param('width');
|
||
$fig = $this->input_param('fig');
|
||
if (0 == strlen($scene)) {
|
||
throw new Hd_Exception('二维码参数必填', API_CODE_INVILD_PARAM);
|
||
}
|
||
return $this->qrcode($scene, $page, $width, $fig);
|
||
}
|
||
|
||
/**
|
||
* Notes:获取图片二维码
|
||
* Created on: 2021/8/27 16:33
|
||
* Created by: dengbw
|
||
* @param $scene
|
||
* @param string $page
|
||
* @param int $width
|
||
* @param string $fig
|
||
* @return array
|
||
* @throws Hd_Exception
|
||
*/
|
||
private function qrcode($scene, $page = '', $width = 0, $fig = 'liche')
|
||
{
|
||
$path = "{$page}?{$scene}";
|
||
$width && $path .= "{$width}";
|
||
if ($fig) {
|
||
$this->config->load('app', true, true);
|
||
$configs = $this->config->item('app');
|
||
$config = $configs[$fig];
|
||
if (!$config) {
|
||
debug_log("[error] " . __FUNCTION__ . ": config not exist;fig={$fig}", $this->log_file);
|
||
throw new Hd_Exception('请求的小程序不存在', API_CODE_INVILD_PARAM);
|
||
}
|
||
$wxconfig = $config['wx'];
|
||
} else {
|
||
$wxconfig = $this->wx_config;
|
||
$fig = $this->app_key;
|
||
}
|
||
$filename = "{$fig}/" . substr(md5($path), 8, 16);
|
||
$this->load->library('Hdwechat');
|
||
$hdwechat = new Hdwechat($wxconfig);
|
||
$ret = $hdwechat->qrcode($filename, $scene, $page, $width);
|
||
if (!$ret) {
|
||
throw new Hd_Exception('生成失败,稍后重试', API_CODE_FAIL);
|
||
}
|
||
$data = array('url' => $ret['url']);
|
||
return $data;
|
||
}
|
||
|
||
//日期列表
|
||
private function pr_dates($include_today = true)
|
||
{
|
||
$date_end = $include_today ? strtotime(date('Y-m-d')) : strtotime(date('Y-m-d', strtotime('-1 day')));
|
||
$game_start_date = strtotime(date('Y-m-d', strtotime($this->appConfig['game_start_date'])));
|
||
$game_start_end = strtotime(date('Y-m-d', strtotime($this->appConfig['game_end_date'])));
|
||
$dates = array();
|
||
$do = true;
|
||
while ($do) {
|
||
if ($game_start_date <= $date_end && $game_start_date <= $game_start_end) {
|
||
$dates[] = date('Y-m-d', $game_start_date);
|
||
$game_start_date = strtotime('+1 day', $game_start_date);
|
||
} else {
|
||
$do = false;
|
||
}
|
||
}
|
||
$dates = array_reverse($dates);
|
||
return $dates;
|
||
}
|
||
|
||
/**
|
||
* 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;
|
||
}
|
||
|
||
}
|