blindbox_721

This commit is contained in:
dengbw
2022-07-21 16:04:26 +08:00
committed by lccsw
parent 6865b6735a
commit b4b385bf65
9 changed files with 1046 additions and 21 deletions
+268
View File
@@ -0,0 +1,268 @@
<?php
/**
* Notes:盲盒抽奖
* Created on: 2022/07/14 13:38
* Created by: dengbw
*/
class Blindbox extends HD_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('app/liche/app_liche_blind_box_model', 'mdBlindBox');
}
public function index()
{
return $this->lists();
}
public function lists()
{
$params = $this->input->get();
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 20;
$lists = array();
$where = array('status>' => -1);
$count = $this->mdBlindBox->count($where);
if ($count) {
$this->load->library('MyEncryption');
$res = $this->mdBlindBox->select($where, 'id desc', $params['page'], $params['size']);
foreach ($res as $key => $value) {
$setValue = array();
$setValue['id'] = $value['id'];
$setValue['title'] = $value['title'];
$setValue['s_time'] = $value['s_time'];
$setValue['e_time'] = $value['e_time'];
$setValue['c_time'] = date('Y-m-d H:i', $value['c_time']);
$setValue['status_name'] = $this->mdBlindBox->statusAry($value['status']);
$url = http_host_com('home') . "/h5/syt/blindbox?skey=" . $this->myencryption->base64url_encode("id=" . $value['id']);
$setValue['url'] = urlencode($url);
$lists[] = $setValue;
}
}
$this->data['_title'] = '盲盒抽奖列表';
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
$this->data['lists'] = $lists;
$this->data['params'] = $params;
return $this->show_view('/app/liche/blindbox/lists', true);
}
public function get()
{
$params = $this->input->get();
$id = intval($params['id']);
$title = $time = $rule = $prizes_content = $prizes_note = $prizes_winning_ins = $share_desc = $bottom_word =
$bg_color = $lottery_num = '';
$bg_img = $share_img = ['value' => '', 'src' => ''];
$prizes_list = [];
if ($id > 0) {
$re = $this->mdBlindBox->get(array('id' => $id));
if (!$re || empty($re)) {
return $this->show_json(SYS_CODE_FAIL, '数据不存在!');
}
$_title = '编辑盲盒抽奖';
$dataInfo['editType'] = 0;
$dataInfo['edit_url'] = '/app/liche/blindbox/edit';
$dataInfo['status'] = $re['status'];
$title = $re['title'];
$re['s_time'] && $time = $re['s_time'] . " ~ " . $re['e_time'];
$lottery_num = $re['lottery_num'];
if ($re['jsondata']) {
$jsondata = json_decode($re['jsondata'], true);
if ($jsondata['bg_img']) {
$bg_img['value'] = $jsondata['bg_img'];
$bg_img['src'] = build_qiniu_image_url($jsondata['bg_img']);
}
$jsondata['bg_color'] && $bg_color = $jsondata['bg_color'];
$jsondata['share_desc'] && $share_desc = $jsondata['share_desc'];
if ($jsondata['share_img']) {
$share_img['value'] = $jsondata['share_img'];
$share_img['src'] = build_qiniu_image_url($jsondata['share_img']);
}
$jsondata['bottom_word'] && $bottom_word = $jsondata['bottom_word'];
$jsondata['rule'] && $rule = $jsondata['rule'];
}
if ($re['prizes']) {//奖品配置
$prizes = json_decode($re['prizes'], true);
$prizes_content = $prizes['content'];
$prizes_note = $prizes['note'];
$prizes_winning_ins = $prizes['winning_ins'];
foreach ($prizes['list'] as $key => $value) {
$value['img_src'] = $value['img_value'] ? build_qiniu_image_url($value['img_value']) : '';
$prizes_list[] = $value;
}
}
} else {
$_title = '新增盲盒抽奖';
$dataInfo['editType'] = 2;
$dataInfo['edit_url'] = '/app/liche/blindbox/add';
$dataInfo['status'] = 0;
}
$status_list = [];
foreach ($this->mdBlindBox->statusAry() as $key => $value) {
$status_list[] = array("id" => $key, "name" => $value);
}
$dataInfo['id'] = $id;
$dataInfo['title'] = $title;
$dataInfo['bg_img'] = $bg_img;
$dataInfo['bg_color'] = $bg_color;
$dataInfo['time'] = $time;
$dataInfo['lottery_num'] = $lottery_num;
$dataInfo['share_desc'] = $share_desc;
$dataInfo['share_img'] = $share_img;
$dataInfo['bottom_word'] = $bottom_word;
$dataInfo['rule'] = $rule;
$dataInfo['prizes_content'] = $prizes_content;
$dataInfo['prizes_note'] = $prizes_note;
$dataInfo['prizes_winning_ins'] = $prizes_winning_ins;
$this->data['info'] = $dataInfo;
$this->data['status_list'] = $status_list;
$this->data['prizes_list'] = $prizes_list;
$this->data['_title'] = $_title;
return $this->show_view('/app/liche/blindbox/edit', true);
}
public function add()
{
$info = $this->input->post('info');
$checkData = $this->checkData($info);
if (!$checkData['code']) {
return $this->show_json($checkData['code'], $checkData['msg']);
}
$re = $this->mdBlindBox->get(array("title" => $info['title'], "status<>" => -1));
if ($re) {
return $this->show_json(SYS_CODE_FAIL, '该标题已存在!');
}
$json_data['bg_img'] = $info['bg_img']['value'];
$json_data['bg_color'] = $info['bg_color'];
$json_data['share_desc'] = $info['share_desc'];
$json_data['share_img'] = $info['share_img']['value'];
$json_data['bottom_word'] = $info['bottom_word'];
$json_data['rule'] = $info['rule'];
$jsondata = json_encode($json_data, JSON_UNESCAPED_UNICODE);
$prizes['content'] = $info['prizes_content'];
$prizes['note'] = $info['prizes_note'];
$prizes['winning_ins'] = $info['prizes_winning_ins'];
$prizes_list = [];
foreach ($info['prizes_list'] as $key => $value) {
unset($value['img_src']);
$prizes_list[] = $value;
}
$prizes['list'] = $prizes_list;
$prizes = json_encode($prizes, JSON_UNESCAPED_UNICODE);
$addData = ["title" => $info['title'], "lottery_num" => $info['lottery_num'], "jsondata" => $jsondata, "prizes" => $prizes
, "status" => $info['status'], "c_time" => time()];
if ($info['time']) {
$time = explode(' ~ ', $info['time']);
$addData['s_time'] = $time[0];
$addData['e_time'] = $time[1];
}
$id = $this->mdBlindBox->add($addData);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '新增失败!');
}
$this->data['type'] = 'add';
$this->data['id'] = $id;
return $this->show_json(SYS_CODE_SUCCESS, '新增成功!');
}
public function edit()
{
$info = $this->input->post('info');
$checkData = $this->checkData($info);
if (!$checkData['code']) {
return $this->show_json($checkData['code'], $checkData['msg']);
}
if (!$info['id']) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$json_data['bg_img'] = $info['bg_img']['value'];
$json_data['bg_color'] = $info['bg_color'];
$json_data['share_desc'] = $info['share_desc'];
$json_data['share_img'] = $info['share_img']['value'];
$json_data['bottom_word'] = $info['bottom_word'];
$json_data['rule'] = $info['rule'];
$jsondata = json_encode($json_data, JSON_UNESCAPED_UNICODE);
$prizes['content'] = $info['prizes_content'];
$prizes['note'] = $info['prizes_note'];
$prizes['winning_ins'] = $info['prizes_winning_ins'];
$prizes_list = [];
foreach ($info['prizes_list'] as $key => $value) {
unset($value['img_src']);
$prizes_list[] = $value;
}
$prizes['list'] = $prizes_list;
$prizes = json_encode($prizes, JSON_UNESCAPED_UNICODE);
$updateData = ["title" => $info['title'], "lottery_num" => $info['lottery_num'], "jsondata" => $jsondata, "prizes" => $prizes];
if ($info['time']) {
$time = explode(' ~ ', $info['time']);
$updateData['s_time'] = $time[0];
$updateData['e_time'] = $time[1];
}
$this->mdBlindBox->update($updateData, ['id' => $info['id']]);
$this->data['type'] = 'edit';
return $this->show_json(SYS_CODE_SUCCESS, '修改成功!');
}
/**
* Notes:修改状态
* Created on: 2020/8/24 11:12
* Created by: dengbw
* @return bool|void
*/
public function edit_status()
{
$info = $this->input->post('info');
if (!$info['id']) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$this->mdBlindBox->update(array("status" => intval($info['status'])), array('id' => $info['id']));
return $this->show_json(SYS_CODE_SUCCESS, '操作成功!');
}
/**
* Notes:检查新增/修改数据
* Created on: 2020/8/20 11:59
* Created by: dengbw
* @param $info
* @return array
*/
private function checkData($info)
{
$msg = '';
$code = SYS_CODE_FAIL;
if (!$info) {
$msg = '非法参数';
} else if (!$info['title']) {
$msg = '请输入标题';
} else if (!$info['bg_img']) {
$msg = '请上传背景图片';
} else if (!$info['bg_color']) {
$msg = '请上传背景颜色';
} else if (!$info['time']) {
$msg = '请选择活动时间';
} else if (!$info['rule']) {
$msg = '请输入其它事项';
} else {
$code = SYS_CODE_SUCCESS;
}
return array('code' => $code, 'msg' => $msg);
}
public function del()
{
}
public function batch()
{
// TODO: Implement batch() method.
}
public function export()
{
}
}
+10
View File
@@ -21,6 +21,7 @@ class Main extends HD_Controller
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
$this->load->model('app/user_accountlog_model');
$this->load->model('app/liche/app_liche_luckybag_users_model', 'mdLuckyBagUsers');
$this->load->model('app/liche/app_liche_blind_box_model', 'mdBlindBox');
}
public function index()
@@ -57,6 +58,15 @@ class Main extends HD_Controller
),
);
$value = $this->mdBlindBox->count(['status>' => -1]);
$list[] = array(
'title' => '盲盒抽奖(个)',
'value' => $value,
'btns' => array(
array('name' => '查看详情', 'url' => '/app/liche/blindbox'),
),
);
$value = $this->mdTopics->count(array('app_id' => $this->app_id));
$list[] = array(
'title' => '专题(个)',
+64 -20
View File
@@ -58,7 +58,47 @@ class Userslog extends HD_Controller
private function dataBizSelect($params)
{
$lists = $where = [];
$lists = $where = $where_c = $where_dt = [];
$same_day = 0;
if ($params['time']) {
$time = explode(' ~ ', $params['time']);
$time[0] == $time[1] && $same_day = 1;
if ($time[0]) {
$where["log_date>="] = $time[0];
$where_c["c_time>="] = strtotime("{$time[0]} 00:00:00");
$where_dt["dt_time>="] = "{$time[0]} 00:00:00";
}
if ($time[1]) {
$where["log_date<="] = $time[1];
$where_c["c_time<="] = strtotime("{$time[1]} 23:59:59");
$where_dt["dt_time<="] = "{$time[1]} 23:59:59";
}
} else {
$where_c["c_time>="] = strtotime("2022-04-15 00:00:00");
$where_dt["dt_time>="] = "2022-04-15 00:00:00";
}
//门店搜索
if (!$same_day && ($params['type'] || $params['biz_id'] || $params['city_id'] || $params['county_id'])) {
$where_cdt['status'] = 1;
$params['type'] && $where_cdt['type'] = $params['type'];
$params['biz_id'] && $where_cdt['id'] = $params['biz_id'];
$params['city_id'] && $where_cdt['city_id'] = $params['city_id'];
$params['county_id'] && $where_cdt['county_id'] = $params['county_id'];
$res_biz = $this->mdBiz->select($where_cdt, 'id desc', 0, 0, 'id');
if ($res_biz) {
$str_ids = implode(',', array_column($res_biz, 'id'));
$where_c["biz_id in ({$str_ids})"] = null;
$where_dt["biz_id in ({$str_ids})"] = null;
} else {
$where_c['biz_id'] = -2;
$where_dt['biz_id'] = -2;
}
}
if ($params['type']) {
$where["type"] = $params['type'];
} else {
$params['type'] = '';
}
if ($params['biz_id']) {
$where['biz_id'] = $params['biz_id'];
} else if ($params['city_id']) {
@@ -77,16 +117,6 @@ class Userslog extends HD_Controller
$params['county_id'] = '';
$params['biz_id'] = '';
}
if ($params['type']) {
$where["type"] = $params['type'];
} else {
$params['type'] = '';
}
if ($params['time']) {
$time = explode(' ~ ', $params['time']);
$time[0] && $where["log_date>="] = $time[0];
$time[1] && $where["log_date<="] = $time[1];
}
$total = $this->mdBizsLog->count($where);
$offlineSources = $this->mdCustomers->offlineSources();
if ($total) {
@@ -163,15 +193,29 @@ class Userslog extends HD_Controller
$customers = $c_num = $orders = 0;
$customers_info = $c_num_info = $orders_info = '';
foreach ($offlineSources as $k => $v) {
$sum2 = $this->mdUsersLog->sum("customer_{$k}", $where);//客户数
if ($sum2['customer_' . $k]) {//客户数
$customers += $sum2['customer_' . $k];
$customers_info .= "<br>{$v['name']}{$sum2['customer_'.$k]}";
}
$sum2 = $this->mdUsersLog->sum("c_num_{$k}", $where);//进店人数
if ($sum2['c_num_' . $k]) {
$c_num += $sum2['c_num_' . $k];
$c_num_info .= "<br>{$v['name']}{$sum2['c_num_'.$k]}";
if ($same_day) {
$sum2 = $this->mdUsersLog->sum("customer_{$k}", $where);//客户数
if ($sum2['customer_' . $k]) {//客户数
$customers += $sum2['customer_' . $k];
$customers_info .= "<br>{$v['name']}{$sum2['customer_'.$k]}";
}
$sum2 = $this->mdUsersLog->sum("c_num_{$k}", $where);//进店人数
if ($sum2['c_num_' . $k]) {
$c_num += $sum2['c_num_' . $k];
$c_num_info .= "<br>{$v['name']}{$sum2['c_num_'.$k]}";
}
} else {
$count2 = $this->mdCustomers->count(array_merge($where_c, ['of_id' => $k]));//客户数
if ($count2) {
$customers += $count2;
$customers_info .= "<br>{$v['name']}{$count2}";
}
$count2 = $this->mdCustomers->count(array_merge($where_dt, ['of_id' => $k]));//进店人数
if ($count2) {
$c_num += $count2;
$c_num_info .= "<br>{$v['name']}{$count2}";
}
}
$sum2 = $this->mdUsersLog->sum("order_{$k}", $where);//订单数
if ($sum2['order_' . $k]) {
+461
View File
@@ -0,0 +1,461 @@
<div class="am-form am-form-horizontal" style="width: 98%;padding-top: 10px">
<div id="vue-edit">
<div class="am-g">
<div class="col-sm-12" style="margin-bottom: 20px;">
<div class="col-sm-2">
<div class="my-panel">
<div class="text-center">
状态
</div>
<div class="text-center" style="padding-top: 5px;">
<select v-if="info.id==0" id="status" v-model="info.status">
<template v-for="(v,i) in status_list">
<option :value="v.id">{{v.name}}</option>
</template>
</select>
<select v-else id="status" disabled="disabled" v-model="info.status">
<template v-for="(v,i) in status_list">
<option :value="v.id">{{v.name}}</option>
</template>
</select>
</div>
</div>
</div>
<div v-if="info.id>0" class="am-form-inline"
style="text-align:right;padding-right: 10px;padding-top: 35px;">
<div class="am-form-group ml10">
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-default"
@click="editType(1)" v-if="info.editType==1">取消编辑</a>
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-default"
@click="editType(1)" v-else>编辑状态</a>
</div>
<div class="am-form-group ml10" v-if="info.editType==1">
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-success"
@click="saveStatus()">保存状态</a>
</div>
</div>
</div>
</div>
<div class="am-u-lg-12">
<div class="am-panel am-panel-default">
<div class="am-panel-hd">
<span style="font-size: 20px">活动信息</span>
</div>
<div class="am-panel-bd am-g">
<div class="am-form-group">
<label class="am-para-label">标题:</label>
<div class="am-para-input" style="width: 80%">
<input type="text" v-model="info.title">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">背景图片:</label>
<div class="am-para-input">
<div class="am-form-group am-form-file">
<button type="button" class="am-btn am-btn-default am-btn-sm"
data-file="1" data-mark="" data-type="jpg,png,gif,png,jpeg"
data-uptype="qiniu" data-params-source="vue_obj.info.bg_img">
<i class="am-icon-cloud-upload"></i> 上传图片
</button>
<span class="f12 clr999 lh-default ml5">建议尺寸宽度690</span>
<img data-tips-image style="height:auto;max-height:32px;min-width:32px"
:src="vue_obj.info.bg_img.src"/>
</div>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">背景颜色:</label>
<div class="am-para-input" style="width: 30%">
<input type="text" v-model="info.bg_color">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">活动时间:</label>
<div class="am-para-input" style="width: 30%">
<input id="time_id" value="<?= $info['time'] ?>" type="text" placeholder="开始日期 ~ 结束日期"
autocomplete="off"/>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">抽奖次数:</label>
<div class="am-para-input" style="width: 30%">
<input type="text" v-model="info.lottery_num">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">其它事项:</label>
<div class="am-para-input" style="width: 80%">
<textarea rows="4" v-model="info.rule"></textarea>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">底部文字:</label>
<div class="am-para-input" style="width: 30%">
<input type="text" v-model="info.bottom_word">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">分享描述:</label>
<div class="am-para-input" style="width: 80%">
<input type="text" v-model="info.share_desc">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">分享图片:</label>
<div class="am-para-input">
<div class="am-form-group am-form-file">
<button type="button" class="am-btn am-btn-default am-btn-sm"
data-file="1" data-mark="" data-type="jpg,png,gif,png,jpeg"
data-uptype="qiniu" data-params-source="vue_obj.info.share_img">
<i class="am-icon-cloud-upload"></i> 上传图片
</button>
<img data-tips-image style="height:auto;max-height:32px;min-width:32px"
:src="vue_obj.info.share_img.src"/>
</div>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">礼品说明:</label>
<div class="am-para-input" style="width: 80%">
<textarea rows="4" v-model="info.prizes_content"></textarea>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">礼品备注:</label>
<div class="am-para-input" style="width: 30%">
<input type="text" v-model="info.prizes_note">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">中奖说明:</label>
<div class="am-para-input" style="width: 30%">
<input type="text" v-model="info.prizes_winning_ins">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">礼品配置:</label>
<div class="am-para-input">
<div class="col-sm-10">
<table class="table table-hover table-middle" style="table-layout:fixed">
<colgroup>
<col width="80px"/>
<col width="30%">
<col width="15%">
<col width="30%"/>
<col width="">
</colgroup>
<thead>
<tr>
<th class="text-center">图片</th>
<th class="text-center">标题</th>
<th class="text-center">积分</th>
<th class="text-center">排序</th>
<th class="text-right">
<a href="javascript:" style="margin-top: 2px;"
class="btn btn-primary btn-sm"
@click='adModal()'>添加</a>
</th>
</tr>
</thead>
<tbody>
<template v-for="(item,index) in prizes_list">
<tr>
<td><img data-tips-image :src="item.img_src"></td>
<td class="text-center">{{item.title}}</td>
<td class="text-center">{{item.credit}}</td>
<td class="text-center">
<div :id="'group_name_txt_'+index">{{item.order_view}} <a
href="javascript:"
@click="showGroupEditForm(index)"><i
class="fa fa-edit"></i></a></div>
<input :id="'group_name_'+index" @blur="editGroupName(index,item.id)"
style="display: none;" type="number" class="form-control"
v-model="item.order_view" placeholder="请输入排序值">
</td>
<td class="text-right">
<a href="javascript:void(0);" style="margin-top:2px;"
class="btn btn-default btn-sm" @click='adModal(item)'>编辑</a>
<a href="javascript:void(0);" style="margin-top:2px;"
class="btn btn-danger btn-sm" @click='removeAd(index)'>删除</a>
</td>
</tr>
</template>
</tbody>
</table>
<template v-if="prizes_list.length <=0">
<div style="text-align: center;">无数据</div>
</template>
</div>
<div id="ad-modal" style="display: none;">
<div class="form-horizontal" style="padding-top: 20px;">
<div class="form-group" style="margin-left: 0px;margin-right: 0px;">
<label class="col-sm-2 control-label">标题</label>
<div class="col-sm-8">
<input type="text" class="form-control" v-model="prizes_item.title"
placeholder="请输入标题">
</div>
</div>
<div class="form-group" style="margin-left: 0px;margin-right: 0px;">
<label class="col-sm-2 control-label">图片</label>
<div class="col-sm-8">
<div class="input-group" style="width: 100%">
<input :value="vue_obj.prizes_img.value" type="text"
style="width: 60%;margin-right: 5px;"
class="form-control">
<button type="button" class="am-btn am-btn-default am-btn-sm"
data-file="1" data-mark="" data-type="jpg,png,gif,png,jpeg"
data-uptype="qiniu" data-params-source="vue_obj.prizes_img">
<i class="am-icon-cloud-upload"></i> 上传图片
</button>
<img data-tips-image
style="height:auto;max-height:32px;min-width:32px;margin-left: 5px;"
:src="vue_obj.prizes_img.src"/>
</div>
</div>
</div>
<div class="form-group" style="margin-left: 0px;margin-right: 0px;">
<label class="col-sm-2 control-label">积分</label>
<div class="col-sm-8">
<input type="text" class="form-control" v-model="prizes_item.credit"
placeholder="请输入积分">
</div>
</div>
<div class="form-group" style="margin-left: 0px;margin-right: 0px;">
<label class="col-sm-2 control-label">排序值</label>
<div class="col-sm-4">
<input type="number" class="form-control" v-model="prizes_item.order_view"
placeholder="请输入排序">
</div>
<div style="padding-top:7px;">
<small class="text-muted">越大越靠前</small>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label"></label>
<div class="am-para-input" style="width: 60%">
<a href="javascript:void(0)" class="am-btn am-btn-sm am-btn-success"
@click="saveEdit()">保存活动信息</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
require(['laydate'], function (laydate) {
//日期范围
laydate.render({
elem: '#time_id', range: '~', type: 'datetime'
, done: function (value, date, endDate) {
if (endDate.hours == "0" && endDate.minutes == "0" && endDate.seconds == "0") {
// 改变结束时间默认值
$(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
$(".laydate-main-list-1 .layui-laydate-content li ol li:last-child").click();
$(".layui-laydate-footer [lay-type='date'].laydate-btns-time").click();
}
}
});
});
var layer_open;
var vue_obj;
$(document).ready(function () {
vue_obj = new Vue({
el: '#vue-edit',
data: {
info: {},
status_list: [],
prizes_list: [],
prizes_item: {},
prizes_img: {value: '', src: ''},
},
mounted() {
var that = this;
that.info = <?=json_encode($info)?>;
that.status_list = <?=json_encode($status_list)?>;
that.prizes_list = <?=json_encode($prizes_list)?>;
},
computed: {},
created: function () {
},
updated: function () {
},
methods: {
// 修改排序
showGroupEditForm: function (index) {
$("#group_name_" + index).show();
$("#group_name_txt_" + index).hide();
$('#group_name_' + index).focus();
},
// 排序
editGroupName: function (index, group_id) {
var order_view = $("#group_name_" + index).val();
if (order_view == '') {
layer.msg("排序值不能为空!", {icon: 2});
return false;
}
this.prizes_list.sort(function (a, b) {
return b.order_view - a.order_view;
});
$("#group_name_" + index).hide();
$("#group_name_txt_" + index).show();
},
adModal: function (item) {
var that = this;
var _title = '新增礼品';
that.prizes_item = {};
if (item) {
that.prizes_item = item;
_title = '编辑礼品';
that.prizes_img = {value: item.img_value, src: item.img_src};
} else {
that.prizes_item = {"order_view": 50};
that.prizes_img = {value: '', src: ''};
}
layer.open({
type: 1,
area: ['50%'], //宽高
content: $('#ad-modal'),
title: _title,
shade: false,
btn: ['确定', '取消'],
yes: function (index) {
if (!item) {
let timestamp = Date.parse(new Date());
let rand = parseInt(Math.random() * 1000);
let id = timestamp + rand;
that.prizes_list.push({
id: id,
title: that.prizes_item.title,
img_value: that.prizes_img.value,
img_src: that.prizes_img.src,
credit: that.prizes_item.credit,
order_view: that.prizes_item.order_view
});
}
that.prizes_list.sort(function (a, b) {
return b.order_view - a.order_view;
});
layer.close(index);
}
});
},
removeAd: function (index) {
var vm = this;
vm.prizes_list.splice(index, 1);
},
editType: function (index) {
var vm = this;
if (index == 1) {
if (vm.info.editType == 1) {
$("#status").attr("disabled", "disabled");
vm.info.editType = 0;
} else {
$("#status").removeAttr("disabled");
vm.info.editType = 1;
}
} else if (index == 2) {
if (vm.info.editType == 2) {
vm.info.editType = 0;
} else {
vm.info.editType = 2;
}
} else {
vm.info.editType = 0;
}
},
saveEdit: function () {
var vm = this;
vm.info.time = $('#time_id').val();
vm.info.prizes_list = vm.prizes_list;
$.ajax({
url: vm.info.edit_url,
type: 'post',
dataType: 'json',
data: {
info: vm.info,
},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
if (data['data']['type'] == 'add') {
window.location.href = "#/app/liche/blindbox/get?id=" + data['data']['id'] + "?spm=<?= $_GET['spm'] ?>";
} else {
$.form.reload();
}
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
layer.closeAll('loading');
},
});
},
saveStatus: function () {
var vm = this;
$.ajax({
url: '/app/liche/blindbox/edit_status',
type: 'post',
dataType: 'json',
data: {
info: vm.info
},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
$.form.reload();
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
layer.closeAll('loading');
},
});
},
}
});
});
</script>
<style type="text/css">
.my-ul ul li {
padding: 10px;
}
.my-panel {
padding: 10px;
border: 1px solid #ddd;
height: 90px;
}
.btn-group .disabled {
background-color: #eee;
opacity: 1;
}
</style>
<link rel="stylesheet" type="text/css" href="/static/css/appitem/font-awesome.min.css?v=1581252500">
<link rel="stylesheet" type="text/css" href="/static/css/appitem/AdminLTE.min.css?v=1581252500">
<link rel="stylesheet" type="text/css" href="/static/css/appitem/hd.css?v=1581252500">
+68
View File
@@ -0,0 +1,68 @@
<div class="coms-table-wrap mt10" id="vue-app">
<form class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/app/liche/blindbox">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">活动标题:</label>
<div class="am-para-inline w200">
<input type="text" name="title" value="<?= $params['title'] ?>"/>
</div>
</div>
<div class="am-form-group fl ml100">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
<div class="am-form-group fl ml10">
<button type="button" data-open="/app/liche/blindbox/get"
class="am-btn am-btn-success am-btn-sm w100">新增
</button>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="4%"><span>ID</span></th>
<th width="15%"><span>标题</span></th>
<th width="10%"><span>开始时间</span></th>
<th width="10%"><span>结束时间</span></th>
<th width="10%"><span>创建时间</span></th>
<th width="8%"><span>状态</span></th>
</tr>
</thead>
<tbody>
<?php if ($lists) {
foreach ($lists as $v) { ?>
<tr>
<td><?= $v['id'] ?></td>
<td><?= $v['title'] ?></td>
<td><?= $v['s_time'] ?></td>
<td><?= $v['e_time'] ?></td>
<td><?= $v['c_time'] ?></td>
<td><?= $v['status_name'] ?></td>
</tr>
<tr>
<td colspan="6" class="align-r">
<a class="am-btn am-btn-primary am-btn-xs"
data-modal="/common/share_link?id=<?= $v['id'] ?>&app_id=1&pages=lantushijia"
data-title="分享链接">分享链接</a>
<a class="am-btn am-btn-primary am-btn-xs"
data-open="/app/liche/blindbox/get?id=<?= $v['id'] ?>">编辑</a>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
+6 -1
View File
@@ -19,7 +19,7 @@
<div class="am-form-group fl">
<label class="am-para-label w80">门店:</label>
<div class="am-para-inline w120">
<select title="类型" name="type" v-model="params.type">
<select title="类型" name="type" v-model="params.type" @change="set_type">
<option value="">选择类型</option>
<option :value="i" v-for="(v,i) in typeAry">{{v}}</option>
</select>
@@ -193,6 +193,10 @@
}
});
},
set_type: function () {
var that = this;
that.params.city_id = '';
},
set_county: function () {
var that = this;
that.bizAry = [];
@@ -245,6 +249,7 @@
data: {
city_id: that.params.city_id,
county_id: that.params.county_id,
type: that.params.type,
status: 1
},
success: function (response) {
+133
View File
@@ -0,0 +1,133 @@
<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Notes:盲盒抽奖
* Created on: 2022/7/18 15:16
* Created by: dengbw
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class Blindbox extends Wxapp
{
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = [];//登录白名单
$this->check_status = [];//用户状态校验
$this->check_mobile = [];//需要手机号
$this->check_headimg = [];//授权微信信息
$this->load->model('app/liche/app_liche_blind_box_model', 'mdBlindBox');
$this->load->model('app/liche/app_liche_credits_log_model', 'mdCreditsLog');
}
protected function get()
{
$params = $this->input_param();
$id = intval($params['id']);//活动id
$re = $this->mdBlindBox->get(["id" => $id, "status" => 1]);
if (!$re) {
throw new Hd_exception('活动不存在!', API_CODE_FAIL);
}
$bgimg = $bgcolor = $share_img = $share_desc = $rule_content = $prizes_content = $prizes_note = $bottom_word = '';
$draw_value = 0;
if ($re['jsondata']) {
$jsondata = json_decode($re['jsondata'], true);
$jsondata['bg_img'] && $bgimg = build_qiniu_image_url($jsondata['bg_img']);
$jsondata['bg_color'] && $bgcolor = $jsondata['bg_color'];
$jsondata['rule'] && $rule_content = str_replace("\n", "<br>", $jsondata['rule']);
$jsondata['share_img'] && $share_img = build_qiniu_image_url($jsondata['share_img']);
$jsondata['share_desc'] && $share_desc = $jsondata['share_desc'];
$jsondata['bottom_word'] && $bottom_word = $jsondata['bottom_word'];
}
if ($re['prizes']) {
$prizes = json_decode($re['prizes'], true);
$prizes['content'] && $prizes_content = $prizes['content'];
$prizes['note'] && $prizes_note = $prizes['note'];
}
$info = ['title' => $re['title'], 'bgimg' => $bgimg, 'bgcolor' => $bgcolor];
//计算抽奖机会
if ($this->myuid) {
$lottery_log = $this->mdCreditsLog->count(["target_id" => $id, 'type' => 0, "credit_in>" => 0, "uid" => $this->myuid]);
$draw_value = $re['lottery_num'] - $lottery_log;
$draw_value < 0 && $draw_value = 0;
}
$info['draw'] = ['title' => '次抽奖机会', 'value' => $draw_value];
$time = date('Y年m月d日', strtotime($re['s_time'])) . ' - ' . date('Y年m月d日', strtotime($re['e_time']));
$info['rule'] = ['title' => '盲盒规则', 'time' => ['title' => '活动时间', 'value' => $time],
'Other' => ['title' => '其它事项', 'value' => $rule_content]];
$info['prizes'] = ['title' => '盲盒礼品说明', 'value' => $prizes_content, 'note' => $prizes_note];
$info['bottom_word'] = $bottom_word;
$info['share'] = ["img" => $share_img, "desc" => $share_desc];
return $info;
}
/**
* Notes:抽奖
* Created on: 2022/7/19 11:05
* Created by: dengbw
* @return mixed
* @throws Hd_exception
*/
protected function put()
{
$params = $this->input_param();
$id = intval($params['id']);//活动id
$re = $this->mdBlindBox->get(["id" => $id, "status" => 1]);
if (!$re) {
throw new Hd_exception('活动不存在!', API_CODE_FAIL);
}
$this->checkData($re);
$prizes = json_decode($re['prizes'], true);
$count = count($prizes['list']) - 1;
$num = rand(0, $count);
$prizes_item = $prizes['list'][$num];
$winning = [];
if ($prizes_item) {
$img = $prizes_item['img_value'] ? build_qiniu_image_url($prizes_item['img_value']) : '';
$credit = intval($prizes_item['credit']);
$winning = ['title' => $prizes_item['title'], 'img' => $img, 'value' => "抽到{$credit}积分!"];
$this->load->library('entity/credits_entity');//加积分
$jsondata = ['id' => $prizes_item['id'], 'title' => $prizes_item['title'], 'credit' => $prizes_item['credit']];
//积分变动
$result = $this->credits_entity->change($this->myuid, $credit, 0, $id, '盲盒抽奖', $jsondata);
if (!$result['code']) {
throw new Hd_exception($result['msg'], API_CODE_FAIL);
}
//冻结资金
$this->credits_entity->freeze($this->myuid, $credit, 0);
}
$info = ['title' => '恭喜您!', 'winning_ins' => $prizes['winning_ins'], 'winning' => $winning];
return $info;
}
protected function checkData($params)
{
if (!$this->myuid) {
throw new Hd_exception('需先登录,才能抽奖!', API_CODE_FAIL);
}
$date = date('Y-m-d H:i:s');
if ($params['s_time'] > $date) {
throw new Hd_exception('活动未开始!', API_CODE_FAIL);
}
if ($params['e_time'] < $date) {
throw new Hd_exception('活动已结束!', API_CODE_FAIL);
}
if (!$params['prizes']) {
throw new Hd_exception('未配置奖项!', API_CODE_FAIL);
}
if ($params['lottery_num']) {
//查找抽奖记录
$lottery_num = $this->mdCreditsLog->count(["target_id" => $params['id'], 'type' => 0, "credit_in>" => 0, "uid" => $this->myuid]);
if ($params['lottery_num'] <= $lottery_num) {
throw new Hd_exception('抽奖机会已用完!', API_CODE_FAIL);
}
}
}
protected function post()
{
}
}
+1
View File
@@ -36,6 +36,7 @@ class App_model extends HD_Model
'pages_groupcode_detail' => 'pages/groupCode/index',
'pages_special2' => 'pages/special2/index',
'pages_storeInfo' => array('id' => 'biz_id', 'pages' => 'pages/storeInfo/index'),
'pages_lantushijia' => 'pages/topicActivity/lantushijia/index',
),
),
2 => array(
@@ -0,0 +1,35 @@
<?php
/**
* Notes:盲盒抽奖
* Created on: 2022/07/14 13:38
* Created by: dengbw
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class App_liche_blind_box_model extends HD_Model
{
private $table_name = 'lc_app_liche_blind_box';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* Notes:状态
* Created on: 2022/7/14 11:23
* Created by: dengbw
* @param string $id
* @return array|mixed
*/
public function statusAry($id = '')
{
$arr = [-1 => '已删除', 0 => '待审核', 1 => '已通过', 2 => '未通过'];
if (strlen($id)) {
return $arr[$id];
} else {
return $arr;
}
}
}