Files
liche/home/controllers/h5/market/Draw.php
T
2022-11-10 16:59:43 +08:00

164 lines
6.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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
{
private $activityId = 4;
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()
{
$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($this->activityId);
foreach ($winTypeAryGet as $k => $v) {
$winTypeAry[] = ['title' => $v['tag'] . ' ' . $v['title'], 'value' => $k];
}
$title = '私域直播抽奖';
$re = $this->mdSyliveActivity->get(['activityId' => $this->activityId], 'title');
$re['title'] && $title = $re['title'] . '_' . $title;
$data['info'] = ['winNumAry' => $winNumAry, 'winTypeAry' => $winTypeAry];
$data['title'] = $title;
$this->load->view('/h5/market/draw/index', $data);
}
/**
* Notes:中奖人数
* Created on: 2022/11/10 11:50
* Created by: dengbw
*/
public function post_win_num()
{
$params = $this->input->post();
$winType = intval($params['winType']);
$winNumCount = 0;
if ($winType) {
$winNumCount = $this->mdSyliveOrder->count(['activityId' => $this->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']);
if (!$winType) {
$this->show_json(400, '请选择抽奖类型');
}
if (!$winNum) {
$this->show_json(400, '请选择中奖人数');
}
$winTypeAry = $this->mdSyliveOrder->winTypeAry($this->activityId);
$price = $winTypeAry[$winType]['price'];
$limit = $winNum >= 50 ? 100 : 30;
//随机数据
$sql = "SELECT id,userId,mobile,uname,totalPrice FROM lc_market_sylive_order WHERE activityId={$this->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']];
}
}
$data['list'] = $list;
//$winNumCount = $this->mdSyliveOrder->count(['activityId' => $this->activityId, 'win' => 1, 'status' => 1, 'winType' => $winType]);
//$num = $winTypeAry[$winType]['num'];
//$winNum = ($winNum + $winNumCount) > $num ? $num - $winNumCount : $winNum;
if ($winNum > 0) {
shuffle($list);
$result = array_slice($list, 0, $winNum);
}
$msg = "在【" . date('Y-m-d H:i:s') . "】获取到信息";
$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'];
if (!$result || !$winType) {
$this->show_json(400, '参数错误');
}
$resultSet = [];
$winTypeAry = $this->mdSyliveOrder->winTypeAry($this->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' => $this->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));
}
}