master
wangxinglong 2022-03-01 16:19:41 +08:00
parent 9482c9059d
commit 102aae8d08
8 changed files with 526 additions and 43 deletions

View File

@ -2,9 +2,10 @@
namespace app\controller\manager;
use app\model\Activity as ActivityModel;
use app\model\ActivityTemplate as ActivityTemplateModel;
use app\model\ArchivesModelField;
use app\model\ActivityTemplateType as ActivityTemplateTypeModel;
use app\validate\Activity as VActivity;
use app\model\System;
use Exception;
use think\db\exception\DataNotFoundException;
@ -71,12 +72,11 @@ class ActivityTemplate extends Base
if ($this->request->isPost()) {
$item = input('post.');
$validate = $this->validateByApi($item, [
'name' => 'require',
]);
if ($validate !== true) {
return $validate;
try {
validate(VActivity::class)->check($item);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return $this->json(4001,$e->getError());
}
try {
@ -88,7 +88,12 @@ class ActivityTemplate extends Base
}
$this->data['item'] = $info;
$this->data['class'] = ActivityTemplateTypeModel::findList([],[],1,0,null,["sort"=>"desc","id"=>"asc"])['list'];
$this->data['lotteryMethod'] = ActivityModel::AllLotteryMethod();
$this->data['type'] = ActivityModel::AllType();
$this->data['redackType'] = ActivityModel::AllRedackType();
$winnerKey = array_keys($info['winner']);
$this->data['maxKey'] = max($winnerKey)+1;
return $this->view();
}
@ -140,27 +145,26 @@ class ActivityTemplate extends Base
{
if ($this->request->isPost()) {
$item = input('post.');
$validate = $this->validateByApi($item, [
'name' => 'require',
]);
if ($validate !== true) {
return $validate;
}
$tag = ActivityTemplateModel::findOne(["name"=>$item["name"]]);
if(!empty($tag)){
return $this->json(0, "success", ["id" => $tag["id"]]);
try {
validate(VActivity::class)->check($item);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return $this->json(4001,$e->getError());
}
try {
$item['create_time'] = date('Y-m-d H:i:s');
$id = ActivityTemplateModel::insertGetId($item);
return $this->json(0, "success", ["id" => $id]);
ActivityTemplateModel::create($item);
return $this->json(0, "success");
} catch (ValidateException $e) {
return $this->json(4001, $e->getError());
}
}
$this->data['class'] = ActivityTemplateTypeModel::findList([],[],1,0,null,["sort"=>"desc","id"=>"asc"])['list'];
$this->data['lotteryMethod'] = ActivityModel::AllLotteryMethod();
$this->data['type'] = ActivityModel::AllType();
$this->data['redackType'] = ActivityModel::AllRedackType();
return $this->view();
}
@ -176,7 +180,15 @@ class ActivityTemplate extends Base
$page = input('page/d', 1);
$limit = input('size/d', 20);
$items = ActivityTemplateModel::findList([], [], $page, $limit, function ($q) {
return $q->order('id', 'desc');
return $q->with(["adminType"])
->withAttr("lottery_method", function ($value) {
return ActivityModel::AllLotteryMethod()[$value] ?? "";
})
->withAttr("lottery_method", function ($value) {
return ActivityModel::AllLotteryMethod()[$value] ?? "";
})
->order('id', 'desc');
});
return $this->json(0, '操作成功', $items);

View File

@ -5,5 +5,37 @@ namespace app\model;
//抽奖
class Activity extends Base
{
const lottery_method_time = "time";//按时间开奖
const lottery_method_people_number = "people_number";//按人数开奖
const lottery_method_immediate = "immediate";//即抽即开
const type_prize = "prize";//通用抽奖
const type_redpack = "redpack";//红包抽奖
const redpack_type_random = "random";//拼手气红包
const redpack_type_uniformity = "uniformity";//均匀分配红包
public static function AllLotteryMethod()
{
return [
self::lottery_method_time =>"按时间开奖",
self::lottery_method_people_number =>"按人数开奖",
self::lottery_method_immediate =>"即抽即开",
];
}
public static function AllType()
{
return [
self::type_prize =>"通用抽奖",
self::type_redpack =>"红包抽奖",
];
}
public static function AllRedackType()
{
return [
self::redpack_type_random =>"拼手气红包",
self::redpack_type_uniformity =>"均匀分配红包",
];
}
}

View File

@ -3,7 +3,42 @@
namespace app\model;
//抽奖模板
use think\Model;
class ActivityTemplate extends Base
{
public function adminType(){
return $this->hasOne(ActivityTemplateType::class,"id","type_id")->bind(["type_text"=>"name"]);
}
/**
* 设置内容
* */
public function setWinnerAttr($value,$data)
{
$content = array_column($value,null,"sort");
$contentKey = array_keys($content);
sort($contentKey);
$contentData =[];
foreach ($contentKey as $ck){
$contentData[]= $content[$ck];
}
return json_encode($contentData,JSON_UNESCAPED_UNICODE);
}
/**
* 设置内容
* */
public function getWinnerAttr($value,$data)
{
return json_decode($value,true);
}
public static function onAfterInsert( $template)
{
$template->sort = $template->id;
$template->save();
}
}

29
app/validate/Activity.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace app\validate;
use think\Validate;
class Activity extends Validate
{
protected $rule = [
'title|标题' => 'require',
'cover|封面' => 'require',
'type_id|所属分类' => 'require',
'type|抽奖类型' => 'require',
'wechat_waiter_avatar|客服头像' => 'require',
'wechat_waiter_number|客服微信号' => 'require',
'lottery_method|开奖方式' => 'require',
'lottery_time|开奖时间' => 'requireIf:lottery_method,time',
'lottery_people_number|开奖人数' => 'requireIf:lottery_method,people_number',
'redpack_type|红包类型' => 'requireIf:type,redpack',
'redpack_money|红包总金额' => 'requireIf:type,redpack|>:0',
'redpack_num|红包个数' => 'requireIf:type,redpack|>:0',
'participants|参与者头像' => 'require',
'winner|奖品和中奖人' => 'require',
];
protected $scene = [
'edit' => ['old_password'], //修改密码
];
}

View File

@ -35,9 +35,9 @@ layui.use(['jquery', 'laytpl', 'table', 'form', 'miniTab'], function () {
page: true,
cols: [[
{type: 'checkbox'},
{field: 'name', minWidth: 200, title: '名称'},
{field: 'title', minWidth: 200, title: '名称'},
{field: 'type_text', title: '类型'},
{field: 'lottery_method_text', title: '开奖方式'},
{field: 'lottery_method', title: '开奖方式'},
{field: 'sort', align: 'center', title: '排序', edit: 'text'},
{templet: '#row-operate', align: 'center', title: '操作'}
]],

View File

@ -1,8 +1,55 @@
layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'tree', 'xmSelect', 'laydate','upload'], function () {
layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'tree', 'xmSelect', 'laydate','upload',"layer"], function () {
let $ = layui.jquery,
layer = layui.layer,
upload = layui.upload;
let image_exts = $('#image_exts').data('exts') ? $('#image_exts').data('exts') : "jpg|png|gif|bmp|jpeg";//图片上传后缀
upload = layui.upload,
form = layui.form,
laydate = layui.laydate;
//日期时间选择器
laydate.render({
elem: '#lottery_time'
,type: 'datetime'
});
//监听开奖类型
form.on('select(lottery_method)', function(data){
switch (data.value) {
case "time":
$("#lottery_time_row").show();
$("#lottery_people_number_row").hide();
break;
case "people_number":
$("#lottery_time_row").hide();
$("#lottery_people_number_row").show();
break;
default:
$("#lottery_time_row").hide();
$("#lottery_people_number_row").hide();
;
}
return false;
});
//监听红包类型
form.on('select(type)', function(data){
switch (data.value) {
case "prize":
$("#type_redpack_row").hide();
$("#redpack_money_row").hide();
$("#redpack_num_row").hide();
break;
case "redpack":
$("#type_redpack_row").show();
$("#redpack_money_row").show();
$("#redpack_num_row").show();
break;
default:
$("#type_redpack_row").hide();
$("#redpack_money_row").hide();
$("#redpack_num_row").hide();
break;
}
return false;
});
let image_exts = $('#image_exts').data('exts') ? $('#image_exts').data('exts') : "jpg|png|gif|bmp|jpeg";//图片上传后缀
// 删除时间
$('body').on('click', '.upload-file-div-close', function () {
$(this).parent().remove()

View File

@ -11,7 +11,93 @@
<div class="layui-form-item">
<label class="layui-form-label required">名称</label>
<div class="layui-input-block">
<input type="text" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" class="layui-input">
<input type="text" name="title" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">分类</label>
<div class="layui-input-block">
<select name="type_id" >
<option value=""></option>
{foreach $class as $cItem}
<option value="{$cItem['id']}">{$cItem['name']}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">开奖方式</label>
<div class="layui-input-block">
<select name="lottery_method" lay-filter="lottery_method">
<option value=""></option>
{foreach $lotteryMethod as $lKey => $LItem}
<option value="{$lKey}">{$LItem}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item " style="display: none" id="lottery_time_row">
<label class="layui-form-label required">开奖时间</label>
<div class="layui-input-block">
<input type="text" name="lottery_time" id="lottery_time" value="{:date('Y-m-d H:i:s')}" class="layui-input">
</div>
</div>
<div class="layui-form-item " style="display:none;" id="lottery_people_number_row">
<label class="layui-form-label required">开奖人数</label>
<div class="layui-input-block">
<input type="number" name="lottery_people_number" value="10" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">抽奖类型</label>
<div class="layui-input-block">
<select name="type" lay-filter="type">
<option value=""></option>
{foreach $type as $tKey => $tItem}
<option value="{$tKey}">{$tItem}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item" style="display: none" id="type_redpack_row">
<label class="layui-form-label ">红包类型</label>
<div class="layui-input-block">
<select name="redpack_type" >
{foreach $redackType as $rKey => $rItem}
<option value="{$rKey}">{$rItem}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item" style="display: none" id="redpack_money_row">
<label class="layui-form-label ">红包金额</label>
<div class="layui-input-block">
<input type="number" name="redpack_money" value="0" class="layui-input">
</div>
</div>
<div class="layui-form-item" style="display: none" id="redpack_num_row">
<label class="layui-form-label ">红包个数</label>
<div class="layui-input-block">
<input type="number" name="redpack_num" value="0" class="layui-input">
</div>
</div>
<div class="layui-form-item " >
<label class="layui-form-label required">是否热门</label>
<div class="layui-input-block">
<input type="radio" name="hot" value="1" title="是" >
<input type="radio" name="hot" value="0" title="否" checked>
</div>
</div>
@ -83,7 +169,7 @@
<div class="layui-inline layui-col-xs12 layui-col-md8">
<div class="layui-row upload-file-div">
<div class=" layui-col-xs12 layui-col-md8">
<input class="layui-input upload-file-value" name="wechat_waiter_avatar" type="text"
<input class="layui-input upload-file-value" name="participants" type="text"
value="">
<div class="layui-form-mid layui-word-aux">图片尺寸:请上传合适尺寸</div>
</div>
@ -121,17 +207,8 @@
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn layui-btn-normal" data-url="/manager/activity-template/add" lay-submit lay-filter="saveBtn">确认保存</button>
@ -142,7 +219,7 @@
</div>
<script>
addImgListNode=true;
addImgListNode = true;
var ImgListNodeKey = {$maxKey??0};//初始值
</script>
<script src="__MANAGER__/js/add_activity.js?v={:mt_rand()}"></script>

View File

@ -1,19 +1,270 @@
{layout name="manager/layout" /}
<style>
.upload-file-div{position: relative}
.upload-file-div-close{position: absolute;right: 0;top: 0;}
</style>
<div id="image_exts" data-exts="{:str_replace(',','|',$uploadConfig['img_type'])}"></div>
<div class="layuimini-container location-operate-page">
<div class="layuimini-main">
<div class="layui-form layuimini-form">
<div class="layui-form-item">
<label class="layui-form-label required">名称</label>
<div class="layui-input-block">
<input type="text" name="name" lay-verify="required" value="{$item.name ?? ''}" lay-reqtext="名称不能为空" placeholder="请输入名称" class="layui-input">
<input type="text" name="title" value="{$item['title']}" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">分类</label>
<div class="layui-input-block">
<select name="type_id" >
<option value=""></option>
{foreach $class as $cItem}
<option value="{$cItem['id']}" {if $item['type_id'] == $cItem['id']} selected {/if}>{$cItem['name']}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">开奖方式</label>
<div class="layui-input-block">
<select name="lottery_method" lay-filter="lottery_method">
<option value=""></option>
{foreach $lotteryMethod as $lKey => $LItem}
<option value="{$lKey}" {if $item['lottery_method'] == $lKey} selected {/if} >{$LItem}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item " {if $item['lottery_method'] !='time' } style="display: none" {/if} id="lottery_time_row">
<label class="layui-form-label required">开奖时间</label>
<div class="layui-input-block">
<input type="text" name="lottery_time" id="lottery_time" value="{$item['lottery_time']}" class="layui-input">
</div>
</div>
<div class="layui-form-item " {if $item['lottery_method'] !='people_number' } style="display: none" {/if} id="lottery_people_number_row">
<label class="layui-form-label required">开奖人数</label>
<div class="layui-input-block">
<input type="number" name="lottery_people_number" value="{$item['lottery_people_number']}" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">抽奖类型</label>
<div class="layui-input-block">
<select name="type" lay-filter="type">
<option value=""></option>
{foreach $type as $tKey => $tItem}
<option value="{$tKey}" {if $item['type'] == $tKey} selected {/if} >{$tItem}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item" {if $item['type'] !='redpack' } style="display: none" {/if} id="type_redpack_row">
<label class="layui-form-label ">红包类型</label>
<div class="layui-input-block">
<select name="redpack_type" >
{foreach $redackType as $rKey => $rItem}
<option value="{$rKey}" {if $item['redpack_type'] == $rKey} selected {/if} >{$rItem}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item" {if $item['type'] !='redpack' } style="display: none" {/if} id="redpack_money_row">
<label class="layui-form-label ">红包金额</label>
<div class="layui-input-block">
<input type="number" name="redpack_money" value="{$item['redpack_money']}" class="layui-input">
</div>
</div>
<div class="layui-form-item" {if $item['type'] !='redpack' } style="display: none" {/if} id="redpack_num_row">
<label class="layui-form-label ">红包个数</label>
<div class="layui-input-block">
<input type="number" name="redpack_num" value="{$item['redpack_num']}" class="layui-input">
</div>
</div>
<div class="layui-form-item " >
<label class="layui-form-label required">是否热门</label>
<div class="layui-input-block">
<input type="radio" name="hot" value="1" title="是" {if $item['hot'] == 1} checked {/if}>
<input type="radio" name="hot" value="0" title="否" {if $item['hot'] == 0} checked {/if}>
</div>
</div>
<div class="layui-form-item layui-row ">
<label class="layui-form-label">封面:</label>
<div class="layui-inline layui-col-xs12 layui-col-md8">
<div class="layui-row upload-file-div">
<div class=" layui-col-xs12 layui-col-md8">
<input class="layui-input upload-file-value" name="cover" type="text" value="{$item['cover']}">
<div class="layui-form-mid layui-word-aux">图片尺寸:请上传合适尺寸</div>
</div>
<div class="layui-col-xs12 layui-col-md3">
<span>
<button type="button" class="layui-btn layui-btn-danger upload-btn">
<i class="fa fa-upload"></i> 上传
</button>
</span>
<span><button type="button" class="layui-btn layui-btn-primary upload-choose-btn"
data-url="/manager/attachment/image" data-type="image"
data-multiple="false"><i class="fa fa-list"></i> 选择</button></span>
</div>
<ul class="layui-row layui-col-xs12 layui-col-md9 preview-list layui-col-space5"></ul>
</div>
</div>
</div>
<!-- 抽奖说明 -->
<div class="layui-form-item layui-form-text field-div current-field-summary">
<label class="layui-form-label">抽奖说明</label>
<div class="layui-input-block editor-text">
<!-- <div class="editor"></div>-->
<textarea name="explain" class="layui-textarea">{$item['explain']}</textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">微信客服</label>
<div class="layui-input-block">
<input type="text" name="wechat_waiter_number" value="{$item['explain']}" placeholder="请输入名称" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-row ">
<label class="layui-form-label">微信客服头像:</label>
<div class="layui-inline layui-col-xs12 layui-col-md8">
<div class="layui-row upload-file-div">
<div class=" layui-col-xs12 layui-col-md8">
<input class="layui-input upload-file-value" name="wechat_waiter_avatar" type="text" value="{$item['wechat_waiter_avatar']}">
<div class="layui-form-mid layui-word-aux">图片尺寸:请上传合适尺寸</div>
</div>
<div class="layui-col-xs12 layui-col-md3">
<span>
<button type="button" class="layui-btn layui-btn-danger upload-btn">
<i class="fa fa-upload"></i> 上传
</button>
</span>
<span><button type="button" class="layui-btn layui-btn-primary upload-choose-btn"
data-url="/manager/attachment/image" data-type="image"
data-multiple="false"><i class="fa fa-list"></i> 选择</button></span>
</div>
<ul class="layui-row layui-col-xs12 layui-col-md9 preview-list layui-col-space5"></ul>
</div>
</div>
</div>
<div class="layui-form-item layui-row ">
<label class="layui-form-label">参与者头像列表:</label>
<div class="layui-inline layui-col-xs12 layui-col-md8">
<div class="layui-row upload-file-div">
<div class=" layui-col-xs12 layui-col-md8">
<input class="layui-input upload-file-value" name="participants" type="text"
value="{$item['participants']}">
<div class="layui-form-mid layui-word-aux">图片尺寸:请上传合适尺寸</div>
</div>
<div class="layui-col-xs12 layui-col-md3">
<span>
<button type="button" class="layui-btn layui-btn-danger upload-btn"
data-multiple="true">
<i class="fa fa-upload"></i> 上传
</button>
</span>
<span><button type="button" class="layui-btn layui-btn-primary upload-choose-btn"
data-url="/manager/attachment/image" data-type="image"
data-multiple="true"
><i class="fa fa-list"></i> 选择</button></span>
</div>
<ul class="layui-row layui-col-xs12 layui-col-md9 preview-list layui-col-space5"></ul>
</div>
</div>
</div>
<div class="layui-form-item " >
<label class="layui-form-label">中奖者:</label>
<div class="layui-inline layui-col-md8 " >
<div id="img_list">
{foreach $item['winner'] as $wKey => $wItem}
<div class="layui-row upload-file-div">
<div class=" layui-col-xs12 layui-col-md4">
<input class="layui-input upload-file-value" name="winner[{$wKey}][avatar]" type="text" value="{$wItem['avatar']}">
<div class="layui-form-mid layui-word-aux">中奖者头像:请上传合适尺寸</div>
</div>
<div class="layui-col-xs12 layui-col-md3">
<span>
<button type="button" class="layui-btn layui-btn-danger " id="ImgListNode-upload-btn-{$wKey}">
<i class="fa fa-upload"></i> 上传
</button>
</span>
<span><button type="button" class="layui-btn layui-btn-primary upload-choose-btn"
data-url="/manager/attachment/image"
data-type="image"
data-multiple="false">
<i class="fa fa-list"></i> 选择
</button></span>
</div>
<ul class="layui-row layui-col-xs12 layui-col-md9 preview-list layui-col-space5"></ul>
<div class="layui-row">
<div class="layui-inline">
<label class="layui-form-label">奖品标题</label>
<div class="layui-input-inline">
<input type="text" name="winner[{$wKey}][prize_title]" value="{$wItem['prize_title']}" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">中奖者昵称</label>
<div class="layui-input-inline">
<input type="text" name="winner[{$wKey}][winner_title]" value="{$wItem['winner_title']}" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">排序</label>
<div class="layui-input-inline">
<input type="number" name="winner[{$wKey}][sort]" value="{$wItem['sort']}" class="layui-input">
</div>
</div>
</div>
<button class="layui-btn upload-file-div-close">删除</button>
</div>
{/foreach}
</div>
<div class="layui-input-block">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend> <button class="layui-btn " id="addrImgListNode">增加一个节点</button></legend>
</fieldset>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn layui-btn-normal" data-url="/manager/activity-template/edit?id={$item.id}" lay-submit lay-filter="saveBtn">确认保存</button>
<button class="layui-btn layui-btn-normal" data-url="/manager/activity-template/edit?id={$item['id']}" lay-submit lay-filter="saveBtn">确认保存</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
addImgListNode = false;
var ImgListNodeKey = {$maxKey??0};//初始值
</script>
<script src="__MANAGER__/js/add_activity.js?v={:mt_rand()}"></script>