125 lines
4.6 KiB
PHP
125 lines
4.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
|
|
{
|
|
private $activityId = 1;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
}
|
|
|
|
/**
|
|
* 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];
|
|
}
|
|
$data['info'] = ['winNumAry' => $winNumAry, 'winTypeAry' => $winTypeAry];
|
|
$data['title'] = '私域直播抽奖';
|
|
$this->load->view('/h5/market/draw/index', $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 : 50;
|
|
$where = ['activityId' => $this->activityId, 'win' => 0, 'status' => 1, 'totalPrice>=' => $price];
|
|
$res = $this->mdSyliveOrder->select($where, 'payTime desc,id asc', 1, $limit, 'id,userId,mobile,uname');
|
|
$list = $result = [];
|
|
foreach ($res as $v) {
|
|
if ($v['mobile']) {
|
|
$headimg = 'https://qs.haodian.cn/web/images/project/H5-ShiYu/default-head.png';
|
|
$name = $v['uname'] ? $v['uname'] : '***';
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $v['userId']], 'nickname,headimg');
|
|
if ($re_user) {
|
|
$re_user['headimg'] && $headimg = $re_user['headimg'];
|
|
}
|
|
$list[] = ['id' => intval($v['id']), 'name' => $name, 'tel' => $v['mobile'], 'headimg' => $headimg];
|
|
}
|
|
}
|
|
shuffle($list);//随机数组
|
|
$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);
|
|
}
|
|
$data['result'] = $result;
|
|
$data['type'] = $winType;
|
|
$this->show_json(200, '更新信息成功', $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 = [];
|
|
foreach ($result as $v) {
|
|
$ret = $this->mdSyliveOrder->update(['win' => 1, 'winType' => $winType], ["id" => $v['id']]);
|
|
if ($ret) {
|
|
$resultSet = $v;
|
|
}
|
|
}
|
|
$winNumCount = $this->mdSyliveOrder->count(['activityId' => $this->activityId, 'win' => 1, 'status' => 1, 'winType' => $winType]);
|
|
$winTypeAry = $this->mdSyliveOrder->winTypeAry($this->activityId, $winType);
|
|
$winMsgTip = "已中奖{$winNumCount}人({$winTypeAry['tag']} {$winTypeAry['title']})";
|
|
$data['result'] = $resultSet;
|
|
$data['winMsgTip'] = $winMsgTip;
|
|
$this->show_json(200, '中奖成功', $data);
|
|
}
|
|
|
|
private function show_json($code, $msg, $info = [])
|
|
{
|
|
$data['code'] = $code;
|
|
$data['msg'] = $msg;
|
|
$data['data'] = $info;
|
|
die(json_encode($data, JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
}
|