Files
liche/api/controllers/wxapp/liche/Luckybag.php
T
xiaoyu 6a9316dd64 0507
2025-05-07 12:39:07 +08:00

203 lines
8.7 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Notes:福袋活动
* Created on: 2021/11/25 15:16
* Created by: dengbw
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class Luckybag extends Wxapp
{
private $activityTime = ['s_time' => '2021-11-01', 'e_time' => '2021-12-12', 'title' => '时间·2021-12-11/12'];
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
$this->load->model('app/liche/app_liche_luckybag_users_model', 'mdLuckyBagUsers');
$this->load->model('app/liche/app_liche_luckybag_log_model', 'mdLuckyBagLog');
}
protected function get()
{
$params = $this->input_param();
$lucky_bag_btn = ['title' => '拆福袋', 'status' => 0];
if ($params['cf_uid'] && ($params['cf_uid'] != $this->myuid)) {//帮别人助力
$set_uid = $params['cf_uid'];
$user_btn = ['title' => '助力领领红包', 'status' => 1, 'type' => 1];
$re_l = $this->mdLuckyBagLog->get(['uid' => $params['cf_uid'], 'cf_uid' => $this->myuid]);
if ($re_l) {
$user_btn['title'] = '已为TA助力过';
$user_btn['status'] = 0;
}
$zhu_li_count = $this->mdLuckyBagLog->count(['uid' => $set_uid]);
} else {
$set_uid = $this->myuid;
$user_btn = ['title' => '邀请好友助力领福袋', 'status' => 1, 'type' => 0];
$zhu_li_count = $this->mdLuckyBagLog->count(['uid' => $this->myuid]);
if ($this->myuid) {
$re_u = $this->mdLuckyBagUsers->get(['uid' => $this->myuid]);
if (!$re_u) {
$this->mdLuckyBagUsers->add(['uid' => $this->myuid, 'c_time' => time()]);
$re_u['lottery'] = 0;
}
if ($re_u['lottery'] > 0 || $zhu_li_count >= 3) {
$title_lottery = $re_u['lottery'] > 0 ? '已拆福袋' : '拆福袋';
$lucky_bag_btn = ['title' => $title_lottery, 'status' => 1];
}
}
}
$list = $this->mdLuckyBagLog->db->select('b.nickname,b.headimg')
->from('lc_app_liche_luckybag_log as a')
->join('lc_app_liche_users as b', "b.id=a.cf_uid", 'left')
->where(['a.uid' => $set_uid])
->order_by('a.id Desc')
->limit(3)
->get()->result_array();
$share = array('title' => '帮我拆福袋,赢取家电礼包。电视冰箱洗衣机100%中奖!',
'img' => 'https://qs.liche.cn/wechat_app/liche/ningDeFD/sharetip.png');
$data = array(
'title' => '哪吒汽车内购会',
"bg" => array('color' => '#f8c33f', 'img' => 'https://qs.liche.cn/wechat_app/liche/ningDeFD/bag-theme.jpg'),
'lucky_bag' => ['img' => 'https://qs.liche.cn/wechat_app/liche/ningDeFD/luckybag.png', 'title' => '哪吒汽车宁德时代内购会'
, 'btn' => $lucky_bag_btn, 'time' => $this->activityTime['title']],
'user' => ['btn' => $user_btn, 'zhu_li' => ['title' => "当前已有{$zhu_li_count}位好友帮忙", 'value' => $zhu_li_count, 'list' => $list]],
'gift' => $this->mdLuckyBagUsers->get_gift(),
'preferential' => ['https://qs.liche.cn/wechat_app/liche/ningDeFD/policy.jpg'],
'share' => $share
);
return $data;
}
/**
* Notes:领取礼包
* Created on: 2021/11/26 11:05
* Created by: dengbw
* @return mixed
* @throws Hd_exception
*/
protected function put()
{
$this->check_game_date();
if (!$this->myuid) {
throw new Hd_exception('参数错误', API_CODE_FAIL);
}
$re_u = $this->mdLuckyBagUsers->get(['uid' => $this->myuid]);
if (!$re_u) {
throw new Hd_exception('无此用户,领取失败', API_CODE_FAIL);
}
$bag_title = '内购会入门礼包';
if ($re_u['lottery'] > 0) {
$lottery = $re_u['lottery'];
$re_u['gift_bag'] && $bag_title = '内购会入门礼包(已领取)';
} else {
$zhu_li_count = $this->mdLuckyBagLog->count(['uid' => $this->myuid]);
if ($zhu_li_count < 3) {
throw new Hd_exception('还未集齐3位好友拆福袋', API_CODE_FAIL);
}
$lottery = rand(1, 3);
$jsondata = $re_u['jsondata'] ? json_decode($re_u['jsondata'], true) : [];
$jsondata['lottery_time'] = date('Y-m-d H:i:s');
$this->mdLuckyBagUsers->update(['lottery' => $lottery, 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)]
, ['uid' => $this->myuid]);
}
$gift_list[] = ['title' => $this->mdLuckyBagUsers->get_gift($lottery, 1)['tag'], 'img' => $this->mdLuckyBagUsers->get_gift($lottery, 0)['img']];
$gift_list[] = ['title' => $bag_title, 'img' => 'https://qs.liche.cn/wechat_app/liche/ningDeFD/gift-4.jpg'];
$data['title'] = '恭喜您,领取成功!';
$data['gift'] = ['title' => '恭喜获得:', 'list' => $gift_list];
$data['content'] = '注:订车后时展示该活动页面,销售会将抽中的礼品,写入合同备注中,提车时兑现。';
$data['btn'] = ['title' => '给好友送福袋', 'url' => '/pages/ningDeFD/index'];
return $data;
}
/**
* Notes:助力
* Created on: 2021/11/26 11:05
* Created by: dengbw
* @return mixed
* @throws Hd_exception
*/
protected function put_zhu_li()
{
$this->check_game_date();
$params = $this->input_param();
//$params['cf_uid'] = 2;
if (!$params['cf_uid'] || !$this->myuid) {
throw new Hd_exception('参数错误', API_CODE_FAIL);
}
if ($params['cf_uid'] == $this->myuid) {
throw new Hd_exception('不能自己助力', API_CODE_FAIL);
}
$user = $this->app_user_model->get(['id' => $params['cf_uid']]);
if (!$user) {
throw new Hd_exception('无此用户,助力失败', API_CODE_FAIL);
}
$re_l = $this->mdLuckyBagLog->get(['uid' => $params['cf_uid'], 'cf_uid' => $this->myuid]);
if ($re_l) {
throw new Hd_exception('您已助力过了', API_CODE_FAIL);
}
$id = $this->mdLuckyBagLog->add(['uid' => $params['cf_uid'], 'cf_uid' => $this->myuid, 'c_time' => time()]);
if (!$id) {
throw new Hd_exception('助力失败', API_CODE_FAIL);
}
$data['title'] = '助力成功';
$data['content'] = '恭喜您获得一个宁德时代内部员工专属福袋,只要您或者身边有要买新能源汽车的成功下单即可获得豪华礼品。小手一点,免费获得';
$data['btn'] = ['title' => '去领取红包', 'url' => '/pages/ningDeFD/index'];
return $data;
}
/**
* Notes:助力用户
* Created on: 2021/11/30 10:16
* Created by: dengbw
* @return array
*/
protected function get_zhu_li()
{
$params = $this->input_param();
$set_uid = $params['cf_uid'] ? intval($params['cf_uid']) : $this->myuid;
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 10;
$list = [];
$where = ['a.uid' => $set_uid];
$total = $this->mdLuckyBagLog->db->select('a.uid')
->from('lc_app_liche_luckybag_log as a')
->join('lc_app_liche_users as b', "b.id=a.cf_uid", 'left')
->where($where)
->count_all_results();
if ($total) {
$offset = ($params['page'] - 1) * $params['size'];
$limit = $params['size'];
$list = $this->mdLuckyBagLog->db->select('b.nickname,b.headimg')
->from('lc_app_liche_luckybag_log as a')
->join('lc_app_liche_users as b', "b.id=a.cf_uid", 'left')
->where($where)
->order_by('a.id Desc')
->limit($limit, $offset)
->get()->result_array();
}
return ['list' => $list, 'total' => $total];
}
protected function check_game_date()
{
$date = date('Y-m-d H:i');
if ($this->activityTime['s_time'] . ' 00:00' > $date) {
throw new Hd_exception('活动未开始', API_CODE_FAIL);
}
if ($this->activityTime['e_time'] . ' 23:59' < $date) {
throw new Hd_exception('活动已结束', API_CODE_FAIL);
}
}
protected function post()
{
return $this->put();
}
}