FastMovieAI AI短剧创作平台 二开基线

- 源码: xhadmincn/FastMovieAI (Apache 2.0)
- 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION
- vendor/示例资源已gitignore
This commit is contained in:
李建琦
2026-08-26 18:37:36 +08:00
commit eae151fd57
888 changed files with 105571 additions and 0 deletions
@@ -0,0 +1,313 @@
<?php
namespace plugin\marketing\app\control\controller;
use app\Basic;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\State;
use plugin\marketing\app\model\PluginMarketingCoupon;
use plugin\marketing\app\model\PluginMarketingCouponCode;
use plugin\marketing\utils\enum\ReceiveType;
use plugin\marketing\utils\enum\UseState;
use plugin\marketing\utils\enum\UseType;
use support\Request;
class CouponCodeController extends Basic
{
public function __construct()
{
$this->model = new PluginMarketingCoupon();
}
public function indexGetTable(Request $request)
{
$coupon_id = $request->get('coupon_id');
if ($coupon_id) {
$coupon_id = (int)$coupon_id;
}
$builder = new TableBuilder();
$builder->addAction('操作', [
'width' => '100px',
'fixed' => 'right'
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => '/app/marketing/control/CouponCode/delete',
'props' => [
'message' => '确定删除该优惠券码吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('优惠券', [
'model' => Action::REDIRECT['value'],
'path' => '/app/marketing/control/Coupon/index',
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder(null, null, [
'inline' => true
]);
$formBuilder->add('coupon_code', '券码', 'input', '', [
'props' => [
'placeholder' => '券码搜索',
'clearable' => true
]
]);
$formBuilder->add('state', '状态', 'select', null, [
'options' => UseState::getOptions(),
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$formBuilder->add('receive_state', '领取状态', 'select', null, [
'options' => [
[
'label' => '已领取',
'value' => State::YES['value']
],
[
'label' => '未领取',
'value' => State::NO['value']
]
],
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$formBuilder->add('coupon_id', '优惠券', 'select', $coupon_id, [
'options' => PluginMarketingCoupon::options(['channels_uid' => $request->channels_uid]),
'props' => [
'placeholder' => '优惠券搜索',
'clearable' => true,
'filterable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$builder->add('title', '优惠券名', [
'component' => [
'name' => 'table-userinfo',
'props' => [
'nickname' => 'coupon.title',
'copy' => 'coupon_code',
]
],
'props' => [
'minWidth' => '340px'
]
]);
$builder->add('user', '领取人', [
'where' => [
['uid', 'not null', null]
],
'component' => [
'name' => 'table-userinfo',
'props' => [
'nickname' => 'user.nickname',
'avatar' => 'user.headimg',
'info' => 'user.id'
]
],
'props' => [
'minWidth' => '300px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'tag',
'options' => UseState::getOptions(),
],
'props' => [
'width' => '100px'
]
]);
$builder->add('receive_state', '领取状态', [
'component' => [
'name' => 'tag',
'options' => [
[
'label' => '已领取',
'value' => State::YES['value'],
'props' => [
'type' => 'success'
]
],
[
'label' => '未领取',
'value' => State::NO['value'],
'props' => [
'type' => 'info'
]
]
],
],
'props' => [
'width' => '100px'
]
]);
$builder->add('receive_timer', '领取/过期时间', [
'component' => [
'name' => 'tag',
'options' => [
[
'index' => 0,
'props' => [
'type' => 'primary'
]
],
[
'index' => 1,
'props' => [
'type' => 'success'
]
],
[
'index' => 2,
'props' => [
'type' => 'danger'
]
],
[
'index' => 3,
'props' => [
'type' => 'warning'
]
]
]
],
'props' => [
'width' => '180px'
]
]);
$builder->add('receive_use', '领取\使用规则', [
'component' => [
'name' => 'tag',
'options' => [
[
'index' => 0,
'props' => [
'type' => 'success'
]
],
[
'index' => 1,
'props' => [
'type' => 'primary'
]
]
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('timer', '使用时间', [
'component' => [
'name' => 'tag',
'options' => [
[
'index' => 0,
'props' => [
'type' => 'success'
]
],
[
'index' => 1,
'props' => [
'type' => 'danger'
]
]
]
],
'props' => [
'minWidth' => '180px'
]
]);
$builder->add('coupon.discount_text', '优惠', [
'component' => [
'name' => 'tag'
],
'props' => [
'minWidth' => '180px'
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$where[] = ['channels_uid', '=', $request->channels_uid];
$coupon_code = $request->get('coupon_code');
if ($coupon_code) {
$where[] = ['coupon_code', 'like', "%{$coupon_code}%"];
}
$state = $request->get('state');
if ($state !== null) {
$where[] = ['state', '=', $state];
}
$receive_state = $request->get('receive_state');
if ($receive_state !== null) {
if ($receive_state) {
$where[] = ['receive_time', 'NOT NULL', NULL];
} else {
$where[] = ['receive_time', 'NULL', NULL];
}
}
$coupon_id = $request->get('coupon_id');
if ($coupon_id !== null) {
$where[] = ['coupon_id', '=', $coupon_id];
}
$list = PluginMarketingCouponCode::where($where)->with(['user' => function ($query) {
$query->field('id,nickname,headimg,channels_uid');
}, 'coupon' => function ($query) {
$query->field('id,title,receive_type,use_type,discount,full_price,money,coupon_rule');
}])
->order('id desc')->paginate($limit)->each(function ($item) {
$item->receive_use = [ReceiveType::getText($item->receive_type), UseType::getText($item->use_type)];
$item->timer = [$item->start_time, $item->end_time];
$receive_state = 0;
if ($item->receive_time) {
$receive_state = 1;
}
$item->receive_state = $receive_state;
$item->receive_timer = ["有效期:{$item->day}", $item->receive_time, $item->expire_time, $item->use_time];
});
return $this->resData($list);
}
public function delete(Request $request)
{
$id = $request->post('id');
$PluginMarketingCouponCode = PluginMarketingCouponCode::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
if (!$PluginMarketingCouponCode) {
return $this->fail('券码不存在');
}
if ($PluginMarketingCouponCode->state === 1) {
return $this->fail('已使用的券码不能删除');
}
if (!$PluginMarketingCouponCode->delete()) {
return $this->fail('删除失败');
}
return $this->success('删除成功');
}
}
@@ -0,0 +1,657 @@
<?php
namespace plugin\marketing\app\control\controller;
use app\Basic;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\State;
use plugin\finance\utils\enum\OrdersType;
use plugin\marketing\app\model\PluginMarketingCoupon;
use plugin\marketing\app\model\PluginMarketingCouponApps;
use plugin\marketing\app\model\PluginMarketingCouponCode;
use plugin\marketing\app\model\PluginMarketingCouponExclusiveWith;
use plugin\marketing\app\model\PluginMarketingCouponPassword;
use plugin\marketing\app\model\PluginMarketingCouponServer;
use plugin\marketing\app\validate\PluginMarketingCoupon as ValidatePluginMarketingCoupon;
use plugin\marketing\utils\enum\CouponRule;
use plugin\marketing\utils\enum\ReceiveType;
use plugin\marketing\utils\enum\UseType;
use support\Request;
use think\facade\Db;
class CouponController extends Basic
{
public function __construct()
{
$this->model = new PluginMarketingCoupon();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder();
$builder->addAction('操作', [
'width' => '160px',
'fixed' => 'right'
]);
$builder->addTableAction('发行', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Coupon/release',
'props' => [
'title' => '发行《{title}》优惠券'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success',
'size' => 'small'
]
]
]);
$builder->addTableAction('券码', [
'model' => Action::REDIRECT['value'],
'path' => '/app/marketing/control/CouponCode/index',
'field' => [
'id' => 'coupon_id'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('创建优惠券', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Coupon/create',
'props' => [
'title' => '创建优惠券'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder(null, null, [
'inline' => true
]);
$formBuilder->add('title', '券名', 'input', '', [
'props' => [
'placeholder' => '券名搜索',
'clearable' => true
]
]);
$formBuilder->add('state', '状态', 'select', null, [
'options' => State::getOptions(),
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$formBuilder->add('show_list', '列表显示', 'select', null, [
'options' => State::getOptions(),
'props' => [
'placeholder' => '列表显示搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$expandBuilder = new TableBuilder([
'size' => 'default',
]);
$expandBuilder->add('password', '口令', [
'component' => [
'name' => 'copy'
]
]);
$builder->add('password', '', [
'components' => [
[
'name' => 'table',
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 6,
'lg' => 4,
],
'builder' => $expandBuilder->builder()
]
],
'props' => [
'type' => 'expand'
]
]);
$builder->add('title', '优惠券名', [
'component' => [
'name' => 'table-userinfo',
'props' => [
'nickname' => 'title',
'info' => 'code',
]
],
'props' => [
'width' => '180px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => '/app/marketing/control/Coupon/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '100px'
]
]);
$builder->add('show_list', '列表显示', [
'component' => [
'name' => 'switch',
'api' => '/app/marketing/control/Coupon/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '100px'
]
]);
$builder->add('receive_use', '领取\使用规则', [
'component' => [
'name' => 'tag',
'options' => [
[
'index' => 0,
'props' => [
'type' => 'success'
]
],
[
'index' => 1,
'props' => [
'type' => 'primary'
]
]
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('discount_text', '优惠', [
'component' => [
'name' => 'tag'
],
'props' => [
'minWidth' => '180px'
]
]);
$builder->add('statistic', '统计', [
'component' => [
'name' => 'statistic',
'options' => [
[
'label' => '总数',
'value' => 'sum'
],
[
'label' => '已使用',
'value' => 'use_num'
],
[
'label' => '未领取',
'value' => 'num'
],
[
'label' => '已领取',
'value' => 'receive_num'
],
[
'label' => '已过期',
'value' => 'expire_num'
]
]
],
'props' => [
'minWidth' => '380px'
]
]);
$builder->add('stackable', '是否叠加', [
'component' => [
'name' => 'switch',
'api' => '/app/marketing/control/Coupon/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '100px'
]
]);
$builder->add('server', '服务范围', [
'component' => [
'name' => 'tag',
],
'props' => [
'minWidth' => '300px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$where[] = ['channels_uid', '=', $request->channels_uid];
$title = $request->get('title');
if ($title) {
$where[] = ['title', 'like', "%{$title}%"];
}
$state = $request->get('state');
if ($state !== null) {
$where[] = ['state', '=', $state];
}
$show_list = $request->get('show_list');
if ($show_list !== null) {
$where[] = ['show_list', '=', $show_list];
}
$list = PluginMarketingCoupon::where($where)
->order('id desc')->paginate($limit)->each(function ($item) {
$item->receive_use = [ReceiveType::getText($item->receive_type), UseType::getText($item->use_type)];
$item->password = $item->password()->where(['coupon_id' => $item->id])->select();
$serverTemp = $item->server()->column('server');
$item->server = array_map(function ($value) {
return $value['label'];
}, OrdersType::getOptions(function ($value) use ($serverTemp) {
return in_array($value['value'], $serverTemp);
}));
});
return $this->resData($list);
}
/**
* 创建优惠券品类
*/
public function create(Request $request)
{
if ($request->method() === 'POST') {
$post = $request->post();
$validate = new ValidatePluginMarketingCoupon;
try {
$validate->check($post);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$model = new PluginMarketingCoupon;
$model->channels_uid = $request->channels_uid;
$model->title = $post['title'];
$model->coupon_rule = $post['coupon_rule'];
switch ($post['coupon_rule']) {
case 'discount':
$model->discount = $post['discount'];
break;
case 'full_price':
$model->full_price = $post['full_price'];
$model->money = $post['money'];
break;
}
$model->state = $post['state'];
$model->show_list = $post['show_list'];
$model->receive_type = $post['receive_type'];
$model->use_type = $post['use_type'];
$model->stackable = $post['stackable'] ? 1 : 0;
$model->save();
foreach ($post['server'] as $item) {
$PluginMarketingCouponServer = new PluginMarketingCouponServer();
$PluginMarketingCouponServer->coupon_id = $model->id;
$PluginMarketingCouponServer->server = $item;
$PluginMarketingCouponServer->save();
}
$passwords = $post['passwords'];
if (!empty($passwords)) {
$passwords = explode("\n", $passwords);
foreach ($passwords as $item) {
$item = trim($item);
if (empty($item)) {
continue;
}
if (PluginMarketingCouponPassword::where(['password' => $item])->count()) {
throw new \Exception("{$item}:优惠券口令重复");
}
$PluginMarketingCouponPassword = new PluginMarketingCouponPassword;
$PluginMarketingCouponPassword->coupon_id = $model->id;
$PluginMarketingCouponPassword->password = $item;
$PluginMarketingCouponPassword->save();
}
}
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->exception($th);
}
return $this->success('创建成功');
}
$Component = new ComponentBuilder;
$builder = new FormBuilder(null, null, [
'labelPosition' => 'right',
'label-width' => "200px",
'class' => 'w-80 mx-auto',
'size' => 'large'
]);
$builder->add('title', '优惠券名', 'input', '', [
'required' => true,
'props' => [
'placeholder' => '优惠券名'
]
]);
$builder->add('passwords', '口令', 'input', '', [
'prompt' => [
$Component->add('text', ['default' => '每行一个口令,每个口令长度在50个字符以内。每个口令需保持全局唯一'], ['type' => 'info', 'size' => 'small'])->builder(),
],
'props' => [
'type' => "textarea",
'placeholder' => '每行一个口令',
'autosize' => [
'minRows' => 4,
'maxRows' => 20
]
]
]);
$builder->add('coupon_rule', '优惠策略', 'radio', '', [
'required' => true,
'options' => CouponRule::getOptions(),
'subProps' => [
'border' => true
]
]);
$builder->add('discount', '折扣', 'input-number', null, [
'required' => true,
'where' => [
['coupon_rule', '=', CouponRule::DISCOUNT['value']]
],
'prompt' => [
$Component->add('text', ['default' => '折扣说明:'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '1. 满小于等于0则为无限制'], ['type' => 'info', 'size' => 'small'])->builder(),
],
'props' => [
'step' => 0.01,
'precision' => 2,
'min' => 0,
'max' => 1
]
]);
$builder->add('full_price', '满减', 'input-number', null, [
'required' => true,
'where' => [
['coupon_rule', '=', CouponRule::FULL_PRICE['value']]
],
'props' => [
'precision' => 2,
'min' => 0,
'controls' => false
],
'children' => [
'prefix' => [
'component' => 'el-text',
'props' => [
'size' => 'small'
],
'children' => [
'default' => '满'
]
]
]
]);
$builder->add('money', '满减', 'input-number', null, [
'required' => true,
'where' => [
['coupon_rule', '=', CouponRule::FULL_PRICE['value']]
],
'props' => [
'precision' => 2,
'min' => 0,
'controls' => false
],
'prompt' => [
$Component->add('text', ['default' => '折扣说明:'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '1. 0和1为不打折'], ['type' => 'info', 'size' => 'small'])->builder(),
],
'children' => [
'prefix' => [
'component' => 'el-text',
'props' => [
'size' => 'small'
],
'children' => [
'default' => '减'
]
]
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'required' => true,
'options' => State::getOptions(),
'subProps' => [
'border' => true
]
]);
$builder->add('show_list', '列表中显示', 'radio', State::NO['value'], [
'required' => true,
'options' => [
[
'label' => '显示',
'value' => State::YES['value']
],
[
'label' => '隐藏',
'value' => State::NO['value']
]
],
'prompt' => [
$Component->add('text', ['default' => '是否在优惠广场列表中显示:'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '不可用:在优惠广场中,优惠券列表将不显示该优惠券'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '正常:在优惠广场中,优惠券列表显示可被所有用户领取'], ['type' => 'info', 'size' => 'small'])->builder(),
],
'subProps' => [
'border' => true
]
]);
$builder->add('receive_type', '领取规则', 'radio', ReceiveType::REPEAT_DAY['value'], [
'required' => true,
'options' => ReceiveType::getOptions(),
'prompt' => [
$Component->add('text', ['default' => '领取规则:'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '账户唯一:该应用用户仅可领取一张,全平台生效'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '每日可领,每周可领,每月可领:用户可在规定时间内未领取则可领取一张'], ['type' => 'info', 'size' => 'small'])->builder(),
],
'subProps' => [
'border' => true
]
]);
$builder->add('use_type', '使用规则', 'radio', UseType::UNLIMITED['value'], [
'required' => true,
'options' => UseType::getOptions(),
'prompt' => [
$Component->add('text', ['default' => '使用规则:'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '首单可用:新用户首单可用'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '应用首单可用:用户未购买过应用可用'], ['type' => 'info', 'size' => 'small'])->builder(),
],
'subProps' => [
'border' => true
]
]);
$builder->add('server', '适用服务', 'checkbox', [], [
'options' => OrdersType::getOptions(),
'required' => true,
'subProps' => [
'border' => true
],
'props' => [
'min' => 1,
],
]);
return $this->resData($builder);
}
public function release(Request $request)
{
if ($request->method() === 'POST') {
$post = $request->post();
if (empty($post['coupon_id'])) {
return $this->fail('请选择优惠券');
}
$num = 1;
if (!empty($post['num'])) {
$num = (int)$post['num'];
if ($num > 1000) {
$num = 1000;
}
}
$start_time = null;
$end_time = null;
if (!empty($post['times'])) {
$start_time = $post['times'][0];
$end_time = $post['times'][1];
if ($start_time > $end_time || $end_time < date('Y-m-d H:i:s')) {
return $this->fail('开始时间不能大于结束时间或结束时间不能小于当前时间');
}
}
Db::startTrans();
try {
$prefix = 'A';
$PluginMarketingCoupon = PluginMarketingCoupon::where(['id' => $post['coupon_id'], 'channels_uid' => $request->channels_uid])->find();
if (!$PluginMarketingCoupon) {
throw new \Exception('优惠券不存在');
}
$couponData = [];
$createCode = [];
for ($i = 0; $i < $num; $i++) {
$code = PluginMarketingCoupon::getCouponCode($prefix, $post['coupon_id']);
if (in_array($code, $createCode)) {
$i--;
continue;
}
$createCode[] = $code;
$couponData[] = [
'channels_uid' => $request->channels_uid,
'coupon_id' => $post['coupon_id'],
'coupon_rule' => $PluginMarketingCoupon->coupon_rule,
'coupon_code' => $code,
'plugin_id' => $PluginMarketingCoupon->plugin_id,
'discount' => $PluginMarketingCoupon->discount,
'full_price' => $PluginMarketingCoupon->full_price,
'money' => $PluginMarketingCoupon->money,
'receive_type' => $PluginMarketingCoupon->receive_type,
'start_time' => $start_time,
'end_time' => $end_time
];
}
if (empty($couponData)) {
return $this->fail('创建失败');
}
$PluginMarketingCoupon->sum = Db::raw('sum+' . $num);
$PluginMarketingCoupon->num = Db::raw('num+' . $num);
$PluginMarketingCoupon->save();
$PluginMarketingCouponCode = new PluginMarketingCouponCode();
$PluginMarketingCouponCode->saveAll($couponData);
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail('发行失败:' . $th->getMessage());
}
return $this->success('发行成功');
}
$id = $request->get('id');
$builder = new FormBuilder(null, null, [
'labelPosition' => 'right',
'label-width' => "200px",
'class' => 'w-80 mx-auto',
'size' => 'large',
'submitButtonText' => '发行'
]);
$Component = new ComponentBuilder;
$builder->add('coupon_id', '优惠券', 'select', (int)$id, [
'required' => true,
'options' => PluginMarketingCoupon::options(),
'props' => [
'placeholder' => '请选择优惠券',
'disabled' => true
]
]);
$builder->add('times', '使用日期', 'date-picker', [], [
'prompt' => [
$Component->add('text', ['default' => '开始和结束日期说明:'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '1. 优惠券需在开始和结束日期之间才可使用'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '2. 未限制开始日期或未限制结束日期则优惠券随时可用'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '3. 如已过结束日期,系统将会清空未被领取的优惠券码'], ['type' => 'info', 'size' => 'small'])->builder()
],
'props' => [
'value-format' => "YYYY-MM-DD HH:mm:ss",
'type' => "datetimerange",
'start-placeholder' => "选择可使用开始日期",
'end-placeholder' => "选择可使用结束日期"
]
]);
$builder->add('day', '有效期', 'input-number', 30, [
'required' => true,
'props' => [
'step' => 1,
'precision' => 0,
'min' => 1,
'max' => 365
]
]);
$builder->add('num', '数量', 'input-number', 1, [
'required' => true,
'prompt' => [
$Component->add('text', ['default' => '数量说明:'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '1. 批量创建优惠券券码'], ['type' => 'info', 'size' => 'small'])->builder(),
$Component->add('text', ['default' => '2. 最低为1,最高单次为1000'], ['type' => 'info', 'size' => 'small'])->builder()
],
'props' => [
'step' => 1,
'precision' => 0,
'min' => 1,
'max' => 1000
]
]);
return $this->resData($builder);
}
}
@@ -0,0 +1,96 @@
<?php
namespace plugin\marketing\app\control\controller;
use app\Basic;
use app\expose\build\builder\DataboardBuilder;
use app\expose\build\builder\databoardBuilder\component\Statistic;
use plugin\marketing\app\model\PluginMarketingCoupon;
use plugin\marketing\app\model\PluginMarketingCouponCode;
use support\Request;
class IndexController extends Basic
{
public function index(Request $request)
{
$builder = new DataboardBuilder([
'gutter' => 6
]);
$today=PluginMarketingCoupon::where('channels_uid', $request->channels_uid)->whereDay('create_time')->count();
$yesterday=PluginMarketingCoupon::where('channels_uid', $request->channels_uid)->whereDay('create_time','yesterday')->count();
$statistic = new Statistic;
$statistic->setLabel('新增优惠券')
->setUnit('')
->setData([
'today' => $today,
'yesterday' => $yesterday,
'growth_rate' => $yesterday?round(($today-$yesterday)/$yesterday*100,2):0
])
->setClass('p-6');
$builder->add($statistic, [
'xs' => 24,
'sm' => 12,
'md' => 6,
'lg' => 4,
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
]);
$today=PluginMarketingCouponCode::where('channels_uid', $request->channels_uid)->whereDay('create_time')->count();
$yesterday=PluginMarketingCouponCode::where('channels_uid', $request->channels_uid)->whereDay('create_time','yesterday')->count();
$statistic = new Statistic;
$statistic->setLabel('发行券码')
->setUnit('')
->setData([
'today' => $today,
'yesterday' => $yesterday,
'growth_rate' => $yesterday?round(($today-$yesterday)/$yesterday*100,2):0
])
->setClass('p-6');
$builder->add($statistic, [
'xs' => 24,
'sm' => 12,
'md' => 6,
'lg' => 4,
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
]);
$today=PluginMarketingCouponCode::where('channels_uid', $request->channels_uid)->whereDay('receive_time')->count();
$yesterday=PluginMarketingCouponCode::where('channels_uid', $request->channels_uid)->whereDay('receive_time','yesterday')->count();
$statistic = new Statistic;
$statistic->setLabel('领取优惠券')
->setUnit('')
->setData([
'today' => $today,
'yesterday' => $yesterday,
'growth_rate' => $yesterday?round(($today-$yesterday)/$yesterday*100,2):0
])
->setClass('p-6');
$builder->add($statistic, [
'xs' => 24,
'sm' => 12,
'md' => 6,
'lg' => 4,
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
]);
$today=PluginMarketingCouponCode::where('channels_uid', $request->channels_uid)->whereDay('use_time')->count();
$yesterday=PluginMarketingCouponCode::where('channels_uid', $request->channels_uid)->whereDay('use_time','yesterday')->count();
$statistic = new Statistic;
$statistic->setLabel('使用优惠券')
->setUnit('')
->setData([
'today' => $today,
'yesterday' => $yesterday,
'growth_rate' => $yesterday?round(($today-$yesterday)/$yesterday*100,2):0
])
->setClass('p-6');
$builder->add($statistic, [
'xs' => 24,
'sm' => 12,
'md' => 6,
'lg' => 4,
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
]);
return $this->resData($builder);
}
}
@@ -0,0 +1,475 @@
<?php
namespace plugin\marketing\app\control\controller;
use app\Basic;
use app\expose\build\builder\ActionBuilder;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\State;
use plugin\marketing\app\model\PluginMarketingPlan;
use plugin\marketing\app\model\PluginMarketingPlanPrice;
use plugin\marketing\utils\enum\PlanKey;
use plugin\marketing\utils\enum\BillingCycle;
use plugin\shortplay\utils\enum\StyleClassify;
use support\Request;
class PlanController extends Basic
{
public function __construct()
{
$this->model = new PluginMarketingPlan();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder;
$builder->addHeader();
$builder->addHeaderAction('创建会员套餐', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Plan/create',
'props' => [
'title' => '创建会员套餐'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder(null, null, [
'inline' => true
]);
$formBuilder->add('name', '名称', 'input', '', [
'props' => [
'placeholder' => '名称搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->addAction('操作', [
'width' => '220px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Plan/update',
'props' => [
'title' => '编辑《ID{id}》会员套餐'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('价格', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Plan/priceList',
'props' => [
'title' => '会员套餐价格列表'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => '/app/marketing/control/Plan/delete',
'where' => [
['is_system', '!=', 1]
],
'props' => [
'type' => 'error',
'message' => '确定要删除吗?',
'confirmButtonClass' => 'el-button--danger'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->add('id', 'ID', [
'props' => [
'width' => '100px'
]
]);
$builder->add('name', '名称', [
'props' => [
'width' => '150px'
]
]);
$builder->add('description', '名称', [
'props' => [
'min-width' => '250px'
]
]);
$builder->add('key', '套餐类型', [
'component' => [
'name' => 'tag',
'options' => PlanKey::getOptions()
]
]);
$builder->add('sort', '排序');
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => '/app/marketing/control/Plan/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$where[] = ['channels_uid', '=', $request->channels_uid];
$name = $request->get('name');
if ($name) {
$where[] = ['name', 'like', "%{$name}%"];
}
$list = PluginMarketingPlan::where($where)
->order('id desc')->paginate($limit)->each(function ($item) {});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() === 'POST') {
$D = $request->post();
try {
$D['channels_uid'] = $request->channels_uid;
$PluginMarketingPlan = new PluginMarketingPlan;
$PluginMarketingPlan->save($D);
} catch (\Throwable $th) {
return $this->exception($th);
}
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() === 'POST') {
$D = $request->post();
try {
$PluginMarketingPlan = PluginMarketingPlan::where(['id' => $D['id'], 'channels_uid' => $request->channels_uid])->find();
$PluginMarketingPlan->save($D);
} catch (\Throwable $th) {
return $this->exception($th);
}
return $this->success('更新成功');
}
$id = $request->get('id');
$Style = PluginMarketingPlan::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
$builder = $this->getFormBuilder();
$builder->setData($Style->toArray());
return $this->resData($builder);
}
private function getFormBuilder()
{
$builder = new FormBuilder(null, null, [
'translations' => true,
'size' => 'large',
]);
$builder->add('name', '名称', 'input', '', [
'required' => true,
'maxlength' => 30,
'show-word-limit' => true,
]);
$builder->add('key', '套餐类型', 'radio', PlanKey::BASIC['value'], [
'options' => PlanKey::getOptions(),
'subProps' => [
'border' => true
]
]);
$component = new ComponentBuilder;
$builder->add('description', '描述', 'input', '', [
'required' => true,
'props' => [
'type' => 'textarea',
'autosize' => [
'minRows' => 4,
'maxRows' => 20
],
'placeholder' => '描述'
],
'prompt' => [
$component->add('text', ['default' => '描述使用 | 分割标签'], ['type' => 'info', 'size' => 'small'])->builder(),
]
]);
$builder->add('sort', '排序', 'input-number', 0, [
'required' => true,
'min' => 0,
'max' => 100,
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'options' => State::getOptions(),
'subProps' => [
'border' => true
],
'required' => true,
]);
return $builder;
}
public function delete(Request $request)
{
$id = $request->get('id');
$PluginMarketingPlan = PluginMarketingPlan::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
PluginMarketingPlanPrice::where(['plan_id' => $id])->delete();
if (!$PluginMarketingPlan->delete()) {
return $this->fail('删除失败');
}
return $this->success('删除成功');
}
public function priceListGetTable(Request $request)
{
$id = $request->get('id');
$builder = new TableBuilder;
$builder->addAction('操作', [
'width' => '180px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Plan/updatePrice',
'props' => [
'title' => '编辑《ID{id}》会员套餐价格'
],
'params' => [
'id' => $id
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('创建会员套餐价格', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Plan/createPrice',
'props' => [
'title' => '创建会员套餐价格'
],
'params' => [
'plan_id' => $id
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => '/app/marketing/control/Plan/priceDelete',
'where' => [
['is_system', '!=', 1]
],
'props' => [
'type' => 'error',
'message' => '确定要删除吗?',
'confirmButtonClass' => 'el-button--danger'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$formBuilder = new FormBuilder(null, null, [
'inline' => true
]);
$formBuilder->add('billing_cycle', '计费周期', 'select', '', [
'options' => BillingCycle::getOptions(),
'props' => [
'placeholder' => '计费周期搜索',
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '100px'
]
]);
$builder->add('price', '价格', [
'props' => [
'width' => '150px'
]
]);
$builder->add('original_price', '划线价', [
'props' => [
'width' => '150px'
]
]);
$builder->add('points', '积分', [
'props' => [
'width' => '150px'
]
]);
$builder->add('billing_cycle', '计费周期', [
'component' => [ 'name' => 'tag',
'options' => BillingCycle::getOptions()
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function priceList(Request $request)
{
$id = $request->get('id');
$limit = $request->get('limit', 10);
$where = [];
$where[] = ['plan_id', '=', $id];
$list = PluginMarketingPlanPrice::where($where)->order('id desc')->paginate($limit);
return $this->resData($list);
}
public function createPrice(Request $request)
{
if ($request->method() === 'POST') {
$D = $request->post();
$PluginMarketingPlanPrice = new PluginMarketingPlanPrice;
$PluginMarketingPlanPrice->save($D);
}
$builder = $this->getPriceFormBuilder();
return $this->resData($builder);
}
public function updatePrice(Request $request)
{
if ($request->method() === 'POST') {
$D = $request->post();
$PluginMarketingPlanPrice = PluginMarketingPlanPrice::where(['id' => $D['id']])->find();
$PluginMarketingPlanPrice->save($D);
return $this->success('更新成功');
}
$id = $request->get('id');
$PluginMarketingPlanPrice = PluginMarketingPlanPrice::where(['id' => $id])->find();
if (!$PluginMarketingPlanPrice) {
return $this->fail('会员套餐价格不存在');
}
$builder = $this->getPriceFormBuilder();
$builder->setData($PluginMarketingPlanPrice->toArray());
return $this->resData($builder);
}
private function getPriceFormBuilder()
{
$builder = new FormBuilder(null, null, [
'translations' => true,
'size' => 'large',
]);
$builder->add('price', '价格', 'input-number', 0, [
'required' => true,
'min' => 0,
'max' => 100,
'props' => [
'controls' => false
]
]);
$builder->add('original_price', '划线价', 'input-number', 0, [
'required' => true,
'min' => 0,
'max' => 100,
'props' => [
'controls' => false
]
]);
$builder->add('points', '积分', 'input-number', 0, [
'required' => true,
'min' => 0,
'max' => 100,
'props' => [
'controls' => false
]
]);
$builder->add('billing_cycle', '计费周期', 'radio', BillingCycle::MONTH['value'], [
'options' => BillingCycle::getOptions(),
'subProps' => [
'border' => true
]
]);
return $builder;
}
public function priceDelete(Request $request)
{
$id = $request->post('id');
$PluginMarketingPlanPrice = PluginMarketingPlanPrice::where(['id' => $id])->find();
if (!$PluginMarketingPlanPrice) {
return $this->fail('会员套餐价格不存在');
}
if ($PluginMarketingPlanPrice->delete()) {
return $this->success('删除成功');
}
return $this->fail('失败');
}
}
@@ -0,0 +1,243 @@
<?php
namespace plugin\marketing\app\control\controller;
use app\Basic;
use app\expose\build\builder\ActionBuilder;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\State;
use plugin\marketing\app\model\PluginMarketingPoints;
use plugin\shortplay\utils\enum\StyleClassify;
use support\Request;
class PointsController extends Basic
{
public function __construct()
{
$this->model = new PluginMarketingPoints();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder;
$builder->addAction('操作', [
'width' => '180px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Points/update',
'props' => [
'title' => '编辑《ID{id}》积分套餐'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('创建积分套餐', [
'model' => Action::DIALOG['value'],
'path' => '/app/marketing/control/Points/create',
'props' => [
'title' => '创建积分套餐'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder(null, null, [
'inline' => true
]);
$formBuilder->add('name', '名称', 'input', '', [
'props' => [
'placeholder' => '名称搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '100px'
]
]);
$builder->add('name', '名称', [
'props' => [
'width' => '150px'
]
]);
$builder->add('price', '价格', []);
$builder->add('original_price', '原价', []);
$builder->add('points', '积分', []);
$builder->add('give', '操作次数', []);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => '/app/marketing/control/Points/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$where[] = ['channels_uid', '=', $request->channels_uid];
$name = $request->get('name');
if ($name) {
$where[] = ['name', 'like', "%{$name}%"];
}
$classify = $request->get('classify');
if ($classify) {
$where[] = ['classify', '=', $classify];
}
$list = PluginMarketingPoints::where($where)
->order('id desc')->paginate($limit)->each(function ($item) {});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() === 'POST') {
$D = $request->post();
try {
$D['channels_uid'] = $request->channels_uid;
$PluginMarketingPoints = new PluginMarketingPoints;
$PluginMarketingPoints->save($D);
} catch (\Throwable $th) {
return $this->exception($th);
}
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() === 'POST') {
$D = $request->post();
try {
$PluginMarketingPoints = PluginMarketingPoints::where(['id' => $D['id'], 'channels_uid' => $request->channels_uid])->find();
$PluginMarketingPoints->save($D);
} catch (\Throwable $th) {
return $this->exception($th);
}
return $this->success('更新成功');
}
$id = $request->get('id');
$Style = PluginMarketingPoints::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
$Style->discount =(int)$Style->discount > 0 ? 1 : 0;
$builder = $this->getFormBuilder();
$builder->setData($Style->toArray());
return $this->resData($builder);
}
private function getFormBuilder()
{
$builder = new FormBuilder(null, null, [
'translations' => true,
'size' => 'large',
]);
$builder->add('name', '名称', 'input', '', [
'required' => true,
'maxlength' => 30,
'show-word-limit' => true,
]);
$builder->add('desc', '描述', 'input', '', [
'required' => true,
]);
$builder->add('price', '价格', 'input-number', '', [
'required' => true,
'props' => [
'controls' => false
]
]);
$builder->add('original_price', '原价', 'input-number', '', [
'required' => true,
'props' => [
'controls' => false
]
]);
$builder->add('points', '积分', 'input-number', '', [
'required' => true,
'props' => [
'controls' => false
]
]);
$builder->add('give', '赠送积分', 'input-number', '', [
'required' => true,
'props' => [
'controls' => false
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'options' => State::getOptions(),
'subProps' => [
'border' => true
],
'required' => true,
]);
$builder->add('discount', '是否优惠', 'radio', 1, [
'options' => [
[
'label' => '优惠',
'value' => '1'
],
[
'label' => '无',
'value' => '0'
]
],
'subProps' => [
'border' => true
],
'required' => true,
]);
return $builder;
}
public function delete(Request $request)
{
$id = $request->get('id');
$PluginMarketingPoints = PluginMarketingPoints::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
if (!$PluginMarketingPoints) {
return $this->fail('积分套餐不存在');
}
if ($PluginMarketingPoints->delete()) {
return $this->success('删除成功');
}
return $this->fail('删除失败');
}
}