299 lines
12 KiB
PHP
299 lines
12 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:抽奖
|
|
* Created on: 2022/11/09 11:19
|
|
* Created by: dengbw
|
|
*/
|
|
class Draw extends CI_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
|
|
$this->load->model('market/Market_sylive_activity_draw_model', 'mdSyliveActivityDraw');
|
|
}
|
|
|
|
/**
|
|
* Notes:主页
|
|
* https://liche-dev.xiaoyu.com/h5/market/draw
|
|
* https://www.liche.cn/h5/market/draw
|
|
* Created on: 2022/11/09 11:19
|
|
* Created by: dengbw
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->load->view('/h5/market/draw/index');
|
|
}
|
|
|
|
/**
|
|
* Notes:验证登录码
|
|
* Created on: 2022/11/10 18:04
|
|
* Created by: dengbw
|
|
*/
|
|
public function post_code()
|
|
{
|
|
$params = $this->input->post();
|
|
$drawCode = $params['drawCode'];
|
|
if (!$drawCode) {
|
|
$this->show_json(400, '请输入抽奖码');
|
|
}
|
|
$re = $this->mdSyliveActivity->get(['drawCode' => $drawCode, 'status' => 0], 'title,activityId');
|
|
if ($re['activityId']) {
|
|
$winNumAry[] = ['title' => '请选择中奖人数', 'value' => 0];
|
|
$winTypeAry[] = ['title' => '请选择抽奖类型'];
|
|
$screenDisplay = 1;
|
|
$bgImg = 'https://qs.haodian.cn/web/images/project/H5-ShiYu-draw/bg-20221213.png';
|
|
$activityId = intval($re['activityId']);
|
|
$re_draw = $this->mdSyliveActivityDraw->get(['activityId' => $activityId]);
|
|
if ($re_draw) {
|
|
$screenDisplay = $re_draw['screenDisplay'];
|
|
$re_draw['bgImg'] && $bgImg = build_qiniu_image_url($re_draw['bgImg']);
|
|
if ($re_draw['winType']) {
|
|
$json_winType = json_decode($re_draw['winType'], true);
|
|
foreach ($json_winType as $v) {
|
|
$v['show'] && $winTypeAry[] = ['title' => $v['title'], 'value' => $v['id']];
|
|
}
|
|
}
|
|
if ($re_draw['winNum']) {
|
|
$json_winNum = json_decode($re_draw['winNum'], true);
|
|
foreach ($json_winNum as $v) {
|
|
$winNumAry[] = ['title' => $v['title'], 'value' => $v['value']];
|
|
}
|
|
}
|
|
}
|
|
$title = $re['title'] . '_私域直播抽奖';
|
|
$bgImg = "background-image:url('{$bgImg}')";
|
|
$info = ['winNumAry' => $winNumAry, 'winTypeAry' => $winTypeAry, 'screenDisplay' => $screenDisplay];
|
|
$data = ['info' => $info, 'activityId' => $activityId, 'bgImg' => $bgImg, 'title' => $title];
|
|
$this->show_json(200, '抽奖码验证成功', $data);
|
|
} else {
|
|
$this->show_json(400, '抽奖码验证失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:中奖人数
|
|
* Created on: 2022/11/10 11:50
|
|
* Created by: dengbw
|
|
*/
|
|
public function post_win_num()
|
|
{
|
|
$params = $this->input->post();
|
|
$activityId = intval($params['activityId']);
|
|
$winType = intval($params['winType']);
|
|
$winNumCount = 0;
|
|
if ($winType) {
|
|
$winNumCount = $this->mdSyliveOrder->count(['activityId' => $activityId, 'win' => 1, 'status' => 1, 'winType' => $winType]);
|
|
}
|
|
|
|
$data['winMsgTip'] = $winNumCount;
|
|
|
|
$this->show_json(200, '操作成功', $data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取抽奖人
|
|
* Created on: 2022/11/9 17:21
|
|
* Created by: dengbw
|
|
*/
|
|
public function post_info()
|
|
{
|
|
$params = $this->input->post();
|
|
$winNum = intval($params['winNum']);
|
|
$winType = intval($params['winType']);
|
|
$activityId = intval($params['activityId']);
|
|
$defaultHead = 'https://qs.haodian.cn/web/images/project/H5-ShiYu/default-head.png';
|
|
|
|
if (!$winType) {
|
|
$this->show_json(400, '请选择抽奖类型');
|
|
}
|
|
if (!$winNum) {
|
|
$this->show_json(400, '请选择中奖人数');
|
|
}
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
if (!$re) {
|
|
$this->show_json(400, '暂无活动');
|
|
}
|
|
if (date('Y-m-d H:i:s') > $re['timeEnd']) {
|
|
$this->show_json(400, "直播结束时间【{$re['timeEnd']}】,不能抽奖了...");
|
|
}
|
|
|
|
$limit = $winNum >= 50 ? 200 : 100;//随机数据
|
|
$prizeUrl = '';
|
|
$whereOrder = ['activityId' => $activityId, 'win' => 0, 'status' => 1];
|
|
|
|
$re_draw = $this->mdSyliveActivityDraw->get(['activityId' => $activityId]);
|
|
if ($re_draw && $re_draw['winType']) {
|
|
$json_winType = json_decode($re_draw['winType'], true);
|
|
foreach ($json_winType as $v) {
|
|
if ($v['id'] == $winType) {
|
|
$v['img'] && $prizeUrl = build_qiniu_image_url($v['img']);
|
|
if ($v['itemIds']) {
|
|
|
|
//不中奖奖品
|
|
if($activityId == 29 and in_array($winType, array(1,2,3))){
|
|
$activityId = 21;
|
|
$whereOrder = ['activityId' => $activityId, 'status' => 1];
|
|
$v['itemIds'] = [27];
|
|
}
|
|
|
|
$itemIds = implode(',', $v['itemIds']);
|
|
$whereOrder["itemId in({$itemIds})"] = null;
|
|
$sqlOrder = "SELECT id,userId,mobile,uname,totalPrice FROM lc_market_sylive_order WHERE activityId={$activityId}
|
|
AND win=0 AND winType=0 AND status=1 AND itemId in({$itemIds}) ORDER BY RAND() LIMIT {$limit}";
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$time = "在【" . date('Y-m-d H:i:s') . "】";
|
|
$count = $this->mdSyliveOrder->count($whereOrder);
|
|
|
|
$list = $result = [];
|
|
if ($count) {//判断抽奖名单
|
|
//随机数据
|
|
$res = $this->db->query($sqlOrder)->result_array();
|
|
if ($res) {
|
|
$str_userIds = implode(',', array_column($res, 'userId'));
|
|
$map_user = $this->mdSyliveUser->map('userId', 'headimg', ["userId in({$str_userIds})" => null]);
|
|
foreach ($res as $v) {
|
|
if ($v['mobile']) {
|
|
$tel = mobile_asterisk($v['mobile']);
|
|
$name = $v['uname'] ? name_asterisk($v['uname']) : '***';
|
|
if ($map_user[$v['userId']]) {
|
|
$headimg = $map_user[$v['userId']];
|
|
} else {
|
|
$headimg = $defaultHead;
|
|
}
|
|
$list[] = ['headimg' => $headimg, 'name' => $name, 'tel' => $tel, 'id' => intval($v['id']),
|
|
'uname' => $v['uname'], 'mobile' => $v['mobile']];
|
|
}
|
|
}
|
|
$count = count($list);
|
|
}
|
|
}
|
|
if (!$count) {
|
|
$this->show_json(400, "{$time}暂无获取到抽奖名单,不能开始抽奖");
|
|
}
|
|
if ($count < $winNum) {
|
|
$this->show_json(400, "{$time}获取到抽奖人数{$count}人,不够选择中奖人数{$winNum}人,不能开始抽奖");
|
|
}
|
|
$data['list'] = $list;
|
|
|
|
//暗箱
|
|
if($activityId == 28 && in_array($winType, array(5)))
|
|
{
|
|
$list = array();
|
|
$sqlOrder = "SELECT id,userId,mobile,uname,totalPrice FROM lc_market_sylive_order WHERE activityId={$activityId} AND win=0 AND winType={$winType} AND status=1 ORDER BY RAND() LIMIT {$winNum}";
|
|
$res = $this->db->query($sqlOrder)->result_array();
|
|
|
|
if ($res) {
|
|
$str_userIds = implode(',', array_column($res, 'userId'));
|
|
$map_user = $this->mdSyliveUser->map('userId', 'headimg', ["userId in({$str_userIds})" => null]);
|
|
foreach ($res as $v) {
|
|
if ($v['mobile']) {
|
|
$tel = mobile_asterisk($v['mobile']);
|
|
$name = $v['uname'] ? name_asterisk($v['uname']) : '***';
|
|
if ($map_user[$v['userId']]) {
|
|
$headimg = $map_user[$v['userId']];
|
|
} else {
|
|
$headimg = $defaultHead;
|
|
}
|
|
$list[] = ['headimg' => $headimg, 'name' => $name, 'tel' => $tel, 'id' => intval($v['id']), 'uname' => $v['uname'], 'mobile' => $v['mobile']];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//选择中奖人结果
|
|
shuffle($list);
|
|
$result = array_slice($list, 0, $winNum);
|
|
|
|
$msg = "{$time}获取到抽奖名单,可开始抽奖";
|
|
$data['result'] = $result;
|
|
$data['type'] = $winType;
|
|
$data['prizeUrl'] = $prizeUrl;
|
|
$this->show_json(200, $msg, $data);
|
|
}
|
|
|
|
/**
|
|
* Notes:更新中奖人
|
|
* Created on: 2022/11/9 17:22
|
|
* Created by: dengbw
|
|
*/
|
|
public function post_win()
|
|
{
|
|
$params = $this->input->post();
|
|
$result = $params['result'];
|
|
$winType = $params['type'];
|
|
$activityId = intval($params['activityId']);
|
|
if (!$result || !$winType || !$activityId) {
|
|
$this->show_json(400, '参数错误');
|
|
}
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
if (!$re) {
|
|
$this->show_json(400, '暂无活动');
|
|
}
|
|
$resultSet = [];
|
|
$winSms = '';
|
|
$re_draw = $this->mdSyliveActivityDraw->get(['activityId' => $activityId]);
|
|
if ($re_draw && $re_draw['winType'] && $re_draw['sms']) {
|
|
$json_winType = json_decode($re_draw['winType'], true);
|
|
foreach ($json_winType as $v) {
|
|
if ($v['id'] == $winType && $v['title']) {
|
|
$winSms = str_replace("中奖标题", $v['title'], $re_draw['sms']);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$winTime = date('Y-m-d H:i:s');
|
|
$showMobile = '';
|
|
$winNum = $sms = 0;
|
|
$dev = false !== strpos($_SERVER['HTTP_HOST'], 'dev') ? 1 : 0;
|
|
foreach ($result as $v) {
|
|
|
|
if($activityId == 29 and in_array($winType, array(1,2,3))){
|
|
$resultSet[] = $v;
|
|
$winNum++;
|
|
$sms++;
|
|
}else{
|
|
|
|
$ret = $this->mdSyliveOrder->update(['win' => 1, 'winType' => $winType, 'winTime' => $winTime], ["id" => $v['id']]);
|
|
|
|
if ($ret) {
|
|
$winNum++;
|
|
$resultSet[] = $v;
|
|
|
|
//中奖发短信
|
|
if ($v['mobile'] && $dev == 0) {//dev==1不发短信通知
|
|
if ($winTime >= $re['timeStart'] && $winSms) {//直播开始时中奖发短信
|
|
b2m_send_sms($v['mobile'], $winSms);
|
|
$sms++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$msg = $showMobile ? $showMobile : "成功抽中{$winNum}人";
|
|
$winNumCount = $this->mdSyliveOrder->count(['activityId' => $activityId, 'win' => 1, 'status' => 1, 'winType' => $winType]);
|
|
$data['result'] = $resultSet;
|
|
$data['winMsgTip'] = $winNumCount;
|
|
$data['sms'] = $sms;
|
|
$this->show_json(200, $msg ? $msg : '成功抽奖', $data);
|
|
}
|
|
|
|
private function show_json($code, $msg, $info = [])
|
|
{
|
|
$data['code'] = $code;
|
|
$data['msg'] = $msg;
|
|
$data['data'] = $info;
|
|
die(json_encode($data, JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
}
|