195 lines
7.6 KiB
PHP
195 lines
7.6 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');
|
||
}
|
||
|
||
/**
|
||
* 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']) {
|
||
$activityId = intval($re['activityId']);
|
||
$winNumAry = [['title' => '请选择...', 'value' => 0], ['title' => '1人', 'value' => 1], ['title' => '2人', 'value' => 2],
|
||
['title' => '5人', 'value' => 5], ['title' => '50人', 'value' => 50]];
|
||
$winTypeAry = [];
|
||
$winTypeAryGet = $this->mdSyliveOrder->winTypeAry($activityId);
|
||
foreach ($winTypeAryGet as $k => $v) {
|
||
if ($k == 1 || $k == 2) {//监时加上
|
||
} else {
|
||
$winTypeAry[] = ['title' => $v['tag'] . ' ' . $v['title'], 'value' => $k];
|
||
}
|
||
}
|
||
$title = $re['title'] . '_私域直播抽奖';
|
||
$data = ['winNumAry' => $winNumAry, 'winTypeAry' => $winTypeAry, 'activityId' => $activityId, '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']);
|
||
if (!$winType) {
|
||
$this->show_json(400, '请选择抽奖类型');
|
||
}
|
||
if (!$winNum) {
|
||
$this->show_json(400, '请选择中奖人数');
|
||
}
|
||
$winTypeAry = $this->mdSyliveOrder->winTypeAry($activityId);
|
||
$price = $winTypeAry[$winType]['price'];
|
||
$limit = $winNum >= 50 ? 100 : 30;
|
||
//随机数据
|
||
$sql = "SELECT id,userId,mobile,uname,totalPrice FROM lc_market_sylive_order WHERE activityId={$activityId}
|
||
AND win=0 AND status=1 AND totalPrice>={$price} ORDER BY RAND() LIMIT {$limit}";
|
||
$res = $this->db->query($sql)->result_array();
|
||
$list = $result = [];
|
||
foreach ($res as $v) {
|
||
if ($v['mobile']) {
|
||
$headimg = 'https://qs.haodian.cn/web/images/project/H5-ShiYu/default-head.png';
|
||
$tel = mobile_asterisk($v['mobile']);
|
||
$name = $v['uname'] ? name_asterisk($v['uname']) : '***';
|
||
$re_user = $this->mdSyliveUser->get(['userId' => $v['userId']], 'nickname,headimg');
|
||
if ($re_user) {
|
||
$re_user['headimg'] && $headimg = $re_user['headimg'];
|
||
}
|
||
$list[] = ['headimg' => $headimg, 'name' => $name, 'tel' => $tel, 'id' => intval($v['id']),
|
||
'uname' => $v['uname'], 'mobile' => $v['mobile']];
|
||
}
|
||
}
|
||
$count = count($list);
|
||
$time = "在【" . date('Y-m-d H:i:s') . "】";
|
||
if (!$count) {
|
||
$this->show_json(400, "{$time}暂无获取到抽奖人,不能开始抽奖");
|
||
}
|
||
if ($count < $winNum) {
|
||
$this->show_json(400, "{$time}获取到抽奖人数{$count}人,不够选择中奖人数{$winNum}人,不能开始抽奖");
|
||
}
|
||
$data['list'] = $list;
|
||
//$winNumCount = $this->mdSyliveOrder->count(['activityId' => $activityId, 'win' => 1, 'status' => 1, 'winType' => $winType]);
|
||
//$num = $winTypeAry[$winType]['num'];
|
||
//$winNum = ($winNum + $winNumCount) > $num ? $num - $winNumCount : $winNum;
|
||
//选择中奖人结果
|
||
shuffle($list);
|
||
$result = array_slice($list, 0, $winNum);
|
||
|
||
$msg = "{$time}获取到的信息,可开始抽奖";
|
||
$data['result'] = $result;
|
||
$data['type'] = $winType;
|
||
$data['prizeUrl'] = $winTypeAry[$winType]['img'];
|
||
$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) {
|
||
$this->show_json(400, '参数错误');
|
||
}
|
||
$resultSet = [];
|
||
$winTypeAry = $this->mdSyliveOrder->winTypeAry($activityId, $winType);
|
||
$winTime = date('Y-m-d H:i:s');
|
||
$smsTime = date('Y-m-d H:i');
|
||
$showMobile = '';
|
||
$winNum = 0;
|
||
foreach ($result as $v) {
|
||
$ret = $this->mdSyliveOrder->update(['win' => 1, 'winType' => $winType, 'winTime' => $winTime], ["id" => $v['id']]);
|
||
if ($ret) {
|
||
$winNum++;
|
||
$resultSet[] = $v;
|
||
//中奖发短信
|
||
if ($winType == 1 || $winType == 2) {//一等奖、二等奖不发短信
|
||
$showMobile = $showMobile ? $showMobile . ",{$v['uname']}({$v['mobile']})" : "{$v['uname']}({$v['mobile']})";
|
||
} else if ($v['mobile']) {
|
||
if ($smsTime >= "2022-11-11 19:00") {//发短信
|
||
$content = "【好店云】礼品锁定提醒:感谢您参与东风ev新能源双11嗨购日专场活动,恭喜您成功锁定({$winTypeAry['title']})礼品一份,只需您在11月30日晚20点前在当地门店选购东风ev新车型纳米box,即可领取礼品哦!";
|
||
b2m_send_sms($v['mobile'], $content);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$msg = $showMobile ? $showMobile : "成功抽中{$winNum}人";
|
||
$winNumCount = $this->mdSyliveOrder->count(['activityId' => $activityId, 'win' => 1, 'status' => 1, 'winType' => $winType]);
|
||
$data['result'] = $resultSet;
|
||
$data['winMsgTip'] = $winNumCount;
|
||
$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));
|
||
}
|
||
|
||
} |