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,59 @@
{
"title": "营销",
"icon": "Discount",
"path": "/app/marketing/admin",
"sort":4999,
"children": [
{
"title": "控制台",
"icon": "ElementPlus",
"path": "/app/marketing/admin/Index/index",
"component": "databoard"
},
{
"title": "优惠券",
"icon": "Coupon",
"path": "/app/marketing/admin/Coupon/index",
"component": "table",
"show":false,
"children": [
{
"title": "创建优惠券",
"path": "/app/marketing/admin/Coupon/create",
"component": "form",
"show": false
},
{
"title": "发行优惠券码",
"path": "/app/marketing/admin/Coupon/release",
"component": "form",
"show": false
},
{
"title": "设置优惠券状态",
"path": "/app/marketing/admin/Coupon/indexUpdateState",
"show": false
}
]
},
{
"title": "优惠券码",
"icon": "BarCode",
"path": "/app/marketing/admin/CouponCode/index",
"component": "table",
"show":false,
"children": [
{
"title": "删除券码",
"path": "/app/marketing/admin/CouponCode/delete",
"show": false
},
{
"title": "作废券码",
"path": "/app/marketing/admin/CouponCode/zuofe",
"show": false
}
]
}
]
}
@@ -0,0 +1,15 @@
<?php
namespace plugin\marketing\api;
use plugin\control\expose\api\Control as ApiControl;
class Control
{
use ApiControl;
public function __construct()
{
$this->path = __DIR__;
$this->plugin = 'marketing';
}
}
@@ -0,0 +1,15 @@
<?php
namespace plugin\marketing\api;
use app\expose\api\Install as ApiInstall;
class Install
{
use ApiInstall;
public function __construct()
{
$this->path = __DIR__;
$this->plugin = 'marketing';
}
}
@@ -0,0 +1,312 @@
<?php
namespace plugin\marketing\app\admin\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/admin/CouponCode/delete',
'props' => [
'message' => '确定删除该优惠券码吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('优惠券', [
'model' => Action::REDIRECT['value'],
'path' => '/app/marketing/admin/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(),
'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 = [];
$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])->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,651 @@
<?php
namespace plugin\marketing\app\admin\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/admin/Coupon/release',
'props' => [
'title' => '发行《{title}》优惠券'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success',
'size' => 'small'
]
]
]);
$builder->addTableAction('券码', [
'model' => Action::REDIRECT['value'],
'path' => '/app/marketing/admin/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/admin/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/admin/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/admin/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/admin/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 = [];
$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->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']])->find();
$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[] = [
'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\admin\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::whereDay('create_time')->count();
$yesterday=PluginMarketingCoupon::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::whereDay('create_time')->count();
$yesterday=PluginMarketingCouponCode::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::whereDay('receive_time')->count();
$yesterday=PluginMarketingCouponCode::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::whereDay('use_time')->count();
$yesterday=PluginMarketingCouponCode::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,216 @@
<?php
namespace plugin\marketing\app\api\controller;
use app\Basic;
use app\expose\enum\State;
use plugin\apps\app\model\PluginApps;
use plugin\finance\app\model\PluginFinanceOrders;
use plugin\finance\utils\enum\OrdersState;
use plugin\finance\utils\enum\OrdersType;
use plugin\marketing\app\model\PluginMarketingCoupon;
use plugin\marketing\app\model\PluginMarketingCouponCode;
use plugin\marketing\utils\enum\ReceiveType;
use plugin\marketing\utils\enum\UseType;
use plugin\user\app\model\PluginUserSiteApps;
use support\Request;
use think\facade\Db;
class CouponController extends Basic
{
protected $notNeedLogin = ['index'];
public function index(Request $request)
{
$where = [];
$where[] = ['state', '=', State::YES['value']];
$where[] = ['show_list', '=', State::YES['value']];
$model = PluginMarketingCoupon::where($where);
$server = $request->get('server');
if ($server) {
$ids = PluginMarketingCoupon::alias('a')
->join('plugin_marketing_coupon_server', 'a.id = plugin_marketing_coupon_server.coupon_id', 'left')
->where(function ($query) use ($server) {
$query->where('plugin_marketing_coupon_server.server', '=', $server);
})
->distinct(true)
->field('a.id')
->column('a.id');
$model->whereIn('id', $ids);
}
$uid = $request->uid;
if ($uid) {
$hasPaidOrder = PluginFinanceOrders::where(['uid' => $uid])
->whereIn('state', PluginMarketingCouponCode::$validOrderStates)
->count();
if ($hasPaidOrder > 0) {
$model->where('use_type', 'in', [UseType::FIRST_PLUGIN['value'], UseType::UNLIMITED['value']]);
}
}
$data = $model->order('id desc')->select()->scene('external')->each(function ($item) use ($uid) {
$item->percentage = 0;
if ($item->sum > 0 && $item->num > 0) {
$item->percentage = round($item->num / $item->sum * 100, 2);
}
$item->receive_type_text = ReceiveType::get($item->receive_type);
$item->use_type_text = UseType::get($item->use_type);
$item->receive = 0;
if ($uid) {
switch ($item->receive_type) {
case ReceiveType::USER_ONLY['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'receive_type' => ReceiveType::USER_ONLY['value'], 'coupon_id' => $item->id])->count()) {
$item->receive = 1;
}
break;
case ReceiveType::REPEAT_DAY['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'coupon_id' => $item->id])->whereDay('receive_time')->count()) {
$item->receive = 1;
}
break;
case ReceiveType::REPEAT_WEEK['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'coupon_id' => $item->id])->whereWeek('receive_time')->count()) {
$item->receive = 1;
}
break;
case ReceiveType::REPEAT_MONTH['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'coupon_id' => $item->id])->whereMonth('receive_time')->count()) {
$item->receive = 1;
}
break;
}
switch ($item->use_type) {
case UseType::FIRST_ORDER['value']:
if (PluginFinanceOrders::where(['uid' => $uid, 'state' => OrdersState::FINISH['value']])->count()) {
$item->receive = 1;
}
break;
}
}
if ($item->stackable) {
$item->exclusive = PluginMarketingCoupon::whereIn('id', $item->exclusiveWith()->column('exclusive_with_id'))->select()->scene('external');
} else {
$item->exclusive = [];
}
$server = $item->server()->column('server');
$item->server = OrdersType::getOptions(function ($value) use ($server) {
return in_array($value['value'], $server);
});
});
return $this->resData($data);
}
public function receive(Request $request)
{
$uid = $request->uid;
$code = $request->post('code');
# 根据code获取coupon_id
$coupon_id = PluginMarketingCoupon::codeToId($code);
Db::startTrans();
try {
$coupon = PluginMarketingCoupon::where(['id' => $coupon_id, 'state' => State::YES['value']])->find();
if (!$coupon) {
throw new \Exception('优惠券不存在');
}
if ($coupon->num <= 0) {
throw new \Exception('优惠券已领完');
}
switch ($coupon->receive_type) {
case ReceiveType::USER_ONLY['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'receive_type' => ReceiveType::USER_ONLY['value']])->count()) {
throw new \Exception('已领取过相同类型的优惠券');
}
break;
case ReceiveType::REPEAT_DAY['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'coupon_id' => $coupon->id])->whereDay('receive_time')->count()) {
throw new \Exception('今日已领取过该优惠券');
}
break;
case ReceiveType::REPEAT_WEEK['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'coupon_id' => $coupon->id])->whereWeek('receive_time')->count()) {
throw new \Exception('本周已领取过该优惠券');
}
break;
case ReceiveType::REPEAT_MONTH['value']:
if (PluginMarketingCouponCode::where(['uid' => $uid, 'coupon_id' => $coupon->id])->whereMonth('receive_time')->count()) {
throw new \Exception('本月已领取过该优惠券');
}
break;
}
$couponCode = PluginMarketingCouponCode::where(['coupon_id' => $coupon_id])->whereNull('uid')->find();
if (!$couponCode) {
throw new \Exception('优惠券已领完');
}
$coupon->num = Db::raw('num-1');
$coupon->receive_num = Db::raw('receive_num+1');
$coupon->save();
$couponCode->uid = $uid;
$couponCode->expire_time = date('Y-m-d H:i:s', strtotime("+{$couponCode->day} day"));
if ($couponCode->end_time && $couponCode->end_time < $couponCode->expire_time) {
$couponCode->expire_time = $couponCode->end_time;
}
$couponCode->receive_time = date('Y-m-d H:i:s');
$couponCode->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->exception($th);
}
return $this->success('领取成功');
}
public function getAvailable(Request $request)
{
$uid = $request->uid;
$now = date('Y-m-d H:i:s');
$where = [];
$where[] = ['uid', '=', $uid];
$where[] = ['plugin_marketing_coupon_code.state', '=', State::NO['value']];
$model = PluginMarketingCouponCode::where($where);
$server = $request->get('server');
if ($server) {
$codeIds = PluginMarketingCouponCode::alias('plugin_marketing_coupon_code')->where($where)->column('coupon_id');
$codeIds = array_unique($codeIds);
$ids = PluginMarketingCoupon::alias('a')->whereIn('a.id', $codeIds)
->join('plugin_marketing_coupon_server', 'a.id = plugin_marketing_coupon_server.coupon_id', 'left')
->where(function ($query) use ($server) {
$query->where('plugin_marketing_coupon_server.server', '=', $server);
})
->distinct(true)
->field('a.id')
->column('a.id');
$model->whereIn('coupon_id', $ids);
}
$hasPaidOrder = PluginFinanceOrders::where(['uid' => $request->uid])
->whereIn('state', PluginMarketingCouponCode::$validOrderStates)
->count();
if ($hasPaidOrder > 0) {
$model->where('use_type', 'in', [UseType::FIRST_PLUGIN['value'], UseType::UNLIMITED['value']]);
}
$coupon = $model->where(function ($query) use ($now) {
$startTime = [
['start_time', '=', NULL],
['start_time', '<=', $now]
];
$query->whereOr($startTime);
})
->where(function ($query) use ($now) {
$endTime = [
['end_time', '=', NULL],
['end_time', '>=', $now]
];
$query->whereOr($endTime);
})
->whereTime('expire_time', '>=', $now)
->with(['coupon' => function ($query) {
$query->field('id,title,coupon_rule,discount,full_price,money,stackable')->hidden(['id']);
}])
->hasWhere('coupon', ['plugin_marketing_coupon.state' => State::YES['value']])
->order('receive_time desc')
->select()->scene('external')->each(function ($item) {
$item->exclusive = PluginMarketingCoupon::whereIn('id', $item->coupon->exclusiveWith()->column('exclusive_with_id'))->field('id,title')->select()->scene('external');
$server = $item->coupon->server()->column('server');
$item->server = OrdersType::getOptions(function ($value) use ($server) {
return in_array($value['value'], $server);
});
});
return $this->resData($coupon);
}
}
@@ -0,0 +1,16 @@
<?php
namespace plugin\marketing\app\api\controller;
use app\Basic;
use app\expose\helper\Payment;
use support\Request;
class PaymentController extends Basic
{
public function index(Request $request)
{
$list = Payment::platform($request->channels_uid);
return $this->resData($list);
}
}
@@ -0,0 +1,21 @@
<?php
namespace plugin\marketing\app\api\controller;
use app\Basic;
use app\expose\enum\State;
use plugin\marketing\app\model\PluginMarketingPoints;
use support\Request;
class PointsController extends Basic
{
public function index(Request $request)
{
$channels_uid = $request->channels_uid;
$where = [];
$where[] = ['channels_uid', '=', $channels_uid];
$where[] = ['state', '=', State::YES['value']];
$list = PluginMarketingPoints::where($where)->order('id desc')->select();
return $this->resData($list);
}
}
@@ -0,0 +1,79 @@
<?php
namespace plugin\marketing\app\api\controller;
use app\Basic;
use app\expose\enum\State;
use plugin\finance\utils\enum\OrdersType;
use plugin\marketing\app\model\PluginMarketingCoupon;
use plugin\marketing\app\model\PluginMarketingCouponCode;
use plugin\marketing\utils\enum\UseState;
use plugin\marketing\utils\enum\UseType;
use support\Request;
class UserCouponController extends Basic
{
public function index(Request $request)
{
$uid = $request->uid;
$now = date('Y-m-d H:i:s');
$where = [];
$where[] = ['uid', '=', $uid];
$action = $request->get('action');
if ($action) {
switch ($action) {
case 'unused':
$where[] = ['plugin_marketing_coupon_code.state', '=', UseState::ON['value']];
break;
case 'used':
$where[] = ['plugin_marketing_coupon_code.state', 'in', [UseState::USED['value'], UseState::EXPIRE['value']]];
break;
}
}
$model = PluginMarketingCouponCode::where($where);
$server = $request->get('server');
if ($server) {
$codeIds = PluginMarketingCouponCode::alias('plugin_marketing_coupon_code')->where($where)->column('coupon_id');
$codeIds = array_unique($codeIds);
$ids = PluginMarketingCoupon::alias('a')->whereIn('a.id', $codeIds)
->join('plugin_marketing_coupon_server', 'a.id = plugin_marketing_coupon_server.coupon_id', 'left')
->where(function ($query) use ($server) {
$query->where('plugin_marketing_coupon_server.server', '=', $server);
})
->distinct(true)
->field('a.id')
->column('a.id');
$model->whereIn('coupon_id', $ids);
}
$coupon = $model->where(function ($query) use ($now) {
$startTime = [
['start_time', '=', NULL],
['start_time', '<=', $now]
];
$query->whereOr($startTime);
})
->where(function ($query) use ($now) {
$endTime = [
['end_time', '=', NULL],
['end_time', '>=', $now]
];
$query->whereOr($endTime);
})
->with(['coupon' => function ($query) {
$query->field('id,title,coupon_rule,discount,full_price,money,stackable,use_type')->hidden(['id']);
}])
->hasWhere('coupon', ['plugin_marketing_coupon.state' => State::YES['value']])
->order('receive_time desc')
->select()->scene('external')->each(function ($item) {
$item->exclusive = PluginMarketingCoupon::whereIn('id', $item->coupon->exclusiveWith()->column('exclusive_with_id'))->field('id,title')->select()->scene('external');
$server = $item->coupon->server()->column('server');
$item->server = OrdersType::getOptions(function ($value) use ($server) {
return in_array($value['value'], $server);
});
$item->use_type_text = UseType::get($item->coupon->use_type);
$item->state_text = UseState::get($item->state);
});
return $this->resData($coupon);
}
}
@@ -0,0 +1,21 @@
<?php
namespace plugin\marketing\app\api\controller;
use app\Basic;
use app\expose\enum\State;
use plugin\marketing\app\model\PluginMarketingPlan;
use support\Request;
class VipController extends Basic
{
public function index(Request $request)
{
$channels_uid = $request->channels_uid;
$where = [];
$where[] = ['channels_uid', '=', $channels_uid];
$where[] = ['state', '=', State::YES['value']];
$list = PluginMarketingPlan::with('price')->where($where)->order('id desc')->select();
return $this->resData($list);
}
}
@@ -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('删除失败');
}
}
@@ -0,0 +1,6 @@
<?php
/**
* Here is your custom functions.
*/
@@ -0,0 +1,95 @@
<?php
namespace plugin\marketing\app\model;
use app\expose\utils\Str;
use app\model\Basic;
use plugin\developer\app\model\PluginDeveloperTeam;
use plugin\marketing\utils\enum\CouponRule;
use plugin\user\app\model\PluginUser;
class PluginMarketingCoupon extends Basic
{
protected function getOptions(): array
{
return [
'type' => [
// 设置JSON字段的类型
'discount' => 'float',
'full_price' => 'float',
'money' => 'float',
]
];
}
public function password()
{
return $this->hasMany(PluginMarketingCouponPassword::class, 'id', 'coupon_id');
}
public function server()
{
return $this->hasMany(PluginMarketingCouponServer::class, 'coupon_id', 'id');
}
/* public function user()
{
return $this->hasOne();
} */
public static function options($where = [])
{
$models = self::where($where)->order('id desc')->select();
$data = [];
foreach ($models as $item) {
$data[] = [
'label' => $item->title,
'value' => $item->id,
'tips' => "折扣:{$item->discount_text}"
];
}
return $data;
}
protected function sceneExternal()
{
return $this->visible(['title', 'coupon_rule', 'discount', 'full_price', 'money', 'receive_type', 'use_type', 'stackable', 'num', 'receive_num', 'sum', 'discount_text', 'code', 'percentage', 'receive', 'exclusive', 'scope', 'server', 'receive_type_text', 'use_type_text']);
}
public static function onAfterRead($model)
{
if ($model->coupon_rule) {
if ($model->coupon_rule === CouponRule::DISCOUNT['value']) {
$model->discount_text = ($model->discount * 10) . '折';
} else {
if ($model->full_price > 0) {
$model->discount_text = "{$model->full_price}元减{$model->money}";
} else {
$model->discount_text = "直减{$model->money}";
}
}
}
// coupon_id转16进制
$coupon_id = dechex((int)$model->id);
// coupon_id长度为6位,不足6位前面补0
$model->code = 'A' . str_pad($coupon_id, 6, '0', STR_PAD_LEFT);
}
public static function codeToId($code)
{
return hexdec(substr($code, 1));
}
/**
* 获取优惠券码
*/
public static function getCouponCode($prefix, $coupon_id)
{
// coupon_id转16进制
$coupon_id = dechex((int)$coupon_id);
// coupon_id长度为6位,不足6位前面补0
$coupon_id = str_pad($coupon_id, 6, '0', STR_PAD_LEFT);
$createDate = date('yWz');
$round = Str::random(6);
// 生成优惠券码
$code = "{$prefix}{$coupon_id}-{$createDate}-{$round}";
$couponCode = PluginMarketingCouponCode::where(['coupon_code' => $code])->find();
if ($couponCode) {
self::getCouponCode($prefix, $coupon_id);
}
return $code;
}
}
@@ -0,0 +1,111 @@
<?php
namespace plugin\marketing\app\model;
use app\model\Basic;
use plugin\finance\app\model\PluginFinanceOrders;
use plugin\finance\utils\enum\OrdersState;
use plugin\marketing\utils\enum\CouponRule;
use plugin\marketing\utils\enum\UseType;
use plugin\user\app\model\PluginUser;
class PluginMarketingCouponCode extends Basic
{
// 所有可识别订单状态
public static $validOrderStates = [
OrdersState::WAIT_PAY['value'],
OrdersState::PAID['value'],
OrdersState::FINISH['value'],
OrdersState::REFUND_ING['value'],
OrdersState::REFUND_SUCCESS['value'],
OrdersState::REFUND_FAIL['value'],
OrdersState::INVALID['value'],
OrdersState::NOTIFY_FAIL['value'],
];
protected function getOptions(): array
{
return [
'type' => [
// 设置JSON字段的类型
'discount' => 'float',
'full_price' => 'float',
'money' => 'float',
]
];
}
public function user()
{
return $this->hasOne(PluginUser::class, 'id', 'uid');
}
public function coupon()
{
return $this->hasOne(PluginMarketingCoupon::class, 'id', 'coupon_id');
}
protected function sceneExternal()
{
return $this->visible(['coupon_code', 'coupon_rule', 'state', 'state_text', 'discount', 'full_price', 'money', 'start_time', 'end_time', 'expire_time', 'receive_time', 'coupon', 'exclusive', 'scope', 'update_scope', 'support_scope', 'role', 'receive_type_text', 'use_type_text', 'server']);
}
/**
* 使用优惠券
* @param PluginFinanceOrders 订单
* @param PluginMarketingCouponCode 所选优惠券列表
* @param null $extra 额外参数
* @return array 返回可使用优惠券码id
* @throws \Exception
*/
public static function useCoupon($Order, $Coupons, $extra = null)
{
$Order->system_money = 0;
$result = [];
foreach ($Coupons as $item) {
$coupon = $item->coupon;
$server = $coupon->server()->column('server');
if (!empty($server) && !in_array($Order->type, $server)) {
throw new \Exception("优惠券「{$coupon->title}」不适用于当前服务");
}
// 3. 校验使用类型
switch ($coupon->use_type) {
case UseType::FIRST_ORDER['value']:
$hasPaidOrder = PluginFinanceOrders::where(['uid' => $Order->uid])
->whereIn('state', self::$validOrderStates)
->count();
if ($hasPaidOrder > 0) {
throw new \Exception("优惠券「{$coupon->title}」仅限首单使用");
}
break;
}
// 5. 优惠金额计算(先复制当前金额)
$newMoney = $Order->money;
switch ($coupon->coupon_rule) {
case CouponRule::DISCOUNT['value']:
if ($coupon->discount > 0 && $coupon->discount < 1) {
$newMoney = $newMoney * $coupon->discount;
}
break;
case CouponRule::FULL_PRICE['value']:
if ($coupon->full_price > 0 && $Order->origin_money < $coupon->full_price) {
throw new \Exception("优惠券「{$coupon->title}」不满足满减条件");
}
$newMoney -= $coupon->money;
break;
}
$newMoney = max(0, $newMoney);
$discountAmount = $Order->money - $newMoney;
// 6. 更新订单金额及归属
$Order->money = $newMoney;
$Order->system_money += $discountAmount;
// 7. 记录已使用的券码ID
$result[] = $item->id;
}
return $result;
}
}
@@ -0,0 +1,10 @@
<?php
namespace plugin\marketing\app\model;
use app\model\Basic;
class PluginMarketingCouponPassword extends Basic
{
protected $pk='coupon_id';
}
@@ -0,0 +1,10 @@
<?php
namespace plugin\marketing\app\model;
use app\model\Basic;
class PluginMarketingCouponServer extends Basic
{
protected $pk='coupon_id';
}
@@ -0,0 +1,13 @@
<?php
namespace plugin\marketing\app\model;
use app\model\Basic;
class PluginMarketingPlan extends Basic
{
public function price()
{
return $this->hasMany(PluginMarketingPlanPrice::class, 'plan_id', 'id');
}
}
@@ -0,0 +1,10 @@
<?php
namespace plugin\marketing\app\model;
use app\model\Basic;
class PluginMarketingPlanPrice extends Basic
{
}
@@ -0,0 +1,10 @@
<?php
namespace plugin\marketing\app\model;
use app\model\Basic;
class PluginMarketingPoints extends Basic
{
}
@@ -0,0 +1,28 @@
<?php
namespace plugin\marketing\app\validate;
use app\expose\validate\Validate;
class PluginMarketingCoupon extends Validate
{
protected $rule = [
'title' => 'require',
'coupon_rule' => 'require',
'discount' => 'requireIf:coupon_rule,discount',
'full_price' => 'requireIf:coupon_rule,full_price',
'money' => 'requireIf:coupon_rule,full_price',
'receive_type' => 'require',
'use_type' => 'require',
];
protected $message = [
'title.require' => '请输入优惠券名',
'coupon_rule.require'=>'请选择优惠策略',
'discount.requireIf'=>'请输入折扣',
'full_price.requireIf'=>'请输入满减策略',
'money.requireIf'=>'请输入满减策略',
'receive_type.require'=>'请选择领取规则',
'use_type.require'=>'请选择使用规则',
];
}
@@ -0,0 +1,9 @@
<?php
use support\Request;
return [
'debug' => true,
'controller_suffix' => 'Controller',
'controller_reuse' => false
];
@@ -0,0 +1,6 @@
<?php
return [
'files' => [
base_path() . '/plugin/marketing/app/functions.php',
]
];
@@ -0,0 +1,2 @@
<?php
return new Webman\Container;
@@ -0,0 +1,5 @@
<?php
return [
'' => app\exception\Handler::class,
];
@@ -0,0 +1,20 @@
<?php
return [
'default' => [
'handlers' => [
[
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
runtime_path() . '/logs/api.log',
7,
\Monolog\Level::Debug,
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [null, 'Y-m-d H:i:s', true],
],
]
],
],
];
@@ -0,0 +1,18 @@
<?php
return [
'' => [
app\expose\middleware\Platform::class
],
'admin' => [
app\expose\middleware\AdminAuth::class
],
'control' => [
plugin\control\expose\middleware\ControlAuth::class
],
'api' => [
plugin\control\expose\middleware\DomainMapping::class,
plugin\user\expose\middleware\UserAuth::class,
plugin\user\expose\middleware\Twofa::class,
]
];
@@ -0,0 +1,10 @@
<?php
use plugin\marketing\process\Expire;
use Workerman\Events\Select;
return [
'CouponExpire' => [
'eventLoop' => Select::class,
'handler' => Expire::class
],
];
@@ -0,0 +1,25 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Multilingual configuration
*/
return [
// Default language
'locale' => 'zh_CN',
// Fallback language
'fallback_locale' => ['zh_CN', 'en'],
// Folder where language files are stored
'path' => base_path() . '/plugin/marketing/resource/translations',
];
@@ -0,0 +1,138 @@
{
"title": "营销",
"icon": "Discount",
"path": "/app/marketing/control",
"sort": 5,
"children": [
{
"title": "优惠券",
"icon": "Coupon",
"path": "/app/marketing/control/Coupon/index",
"component": "table",
"show":false,
"children": [
{
"title": "创建优惠券",
"path": "/app/marketing/control/Coupon/create",
"component": "form",
"show": false
},
{
"title": "发行优惠券码",
"path": "/app/marketing/control/Coupon/release",
"component": "form",
"show": false
},
{
"title": "设置优惠券状态",
"path": "/app/marketing/control/Coupon/indexUpdateState",
"show": false
}
]
},
{
"title": "优惠券码",
"icon": "BarCode",
"path": "/app/marketing/control/CouponCode/index",
"component": "table",
"show":false,
"children": [
{
"title": "删除券码",
"path": "/app/marketing/control/CouponCode/delete",
"show": false
},
{
"title": "作废券码",
"path": "/app/marketing/control/CouponCode/zuofe",
"show": false
}
]
},
{
"title": "积分套餐",
"icon": "CreditCard",
"path": "/app/marketing/control/Points/index",
"component": "table",
"children": [
{
"title": "创建积分套餐",
"path": "/app/marketing/control/Points/create",
"component": "form",
"show": false
},
{
"title": "编辑积分套餐",
"path": "/app/marketing/control/Points/update",
"component": "form",
"show": false
},
{
"title": "删除积分套餐",
"path": "/app/marketing/control/Points/delete",
"show": false
},
{
"title": "设置积分套餐状态",
"path": "/app/marketing/control/Points/indexUpdateState",
"show": false
}
]
},
{
"title": "会员套餐",
"icon": "CreditCard",
"path": "/app/marketing/control/Plan/index",
"component": "table",
"children": [
{
"title": "创建会员套餐",
"path": "/app/marketing/control/Plan/create",
"component": "form",
"show": false
},
{
"title": "编辑会员套餐",
"path": "/app/marketing/control/Plan/update",
"component": "form",
"show": false
},
{
"title": "会员套餐价格列表",
"path": "/app/marketing/control/Plan/priceList",
"component": "table",
"show": false,
"children": [
{
"title": "创建会员套餐价格",
"path": "/app/marketing/control/Plan/createPrice",
"component": "form",
"show": false
},
{
"title": "编辑会员套餐价格",
"path": "/app/marketing/control/Plan/updatePrice",
"component": "form",
"show": false
},
{
"title": "删除会员套餐价格",
"path": "/app/marketing/control/Plan/deletePrice",
"show": false
}
]
},
{
"title": "删除会员套餐",
"path": "/app/marketing/control/Plan/delete",
"show": false
},
{
"title": "设置会员套餐状态",
"path": "/app/marketing/control/Plan/indexUpdateState",
"show": false
}
]
}
]
}
@@ -0,0 +1,10 @@
{
"name": "marketing",
"title": "营销",
"version": "0.0.1",
"description": "各种营销工具",
"author": {
"name": "余心",
"email": "unknown.renloong@gmail.com"
}
}
@@ -0,0 +1,53 @@
<?php
namespace plugin\marketing\process;
use plugin\marketing\app\model\PluginMarketingCoupon;
use plugin\marketing\app\model\PluginMarketingCouponCode;
use plugin\marketing\utils\enum\UseState;
use support\Log;
use Workerman\Crontab\Crontab;
use think\facade\Db;
class Expire
{
public function onWorkerStart()
{
// 每秒钟执行一次
new Crontab('*/10 * * * * *', function () {
try {
$data = PluginMarketingCouponCode::where(['state' => UseState::ON['value']])->whereNull('uid')->whereTime('end_time', '<=', date('Y-m-d H:i:s'))->limit(20)->select();
foreach ($data as $item) {
Db::startTrans();
try {
$PluginMarketingCoupon = PluginMarketingCoupon::where(['id' => $item->coupon_id])->find();
$PluginMarketingCoupon->num = Db::raw('num-1');
$PluginMarketingCoupon->expire_num = Db::raw('expire_num+1');
$PluginMarketingCoupon->save();
$item->delete();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
Log::error('Process Coupon Expire Error:'.$th->getMessage(),$th);
}
}
$data = PluginMarketingCouponCode::where(['state' => UseState::ON['value']])->whereNotNull('uid')->whereTime('expire_time', '<=', date('Y-m-d H:i:s'))->limit(20)->select();
foreach ($data as $item) {
Db::startTrans();
try {
$PluginMarketingCoupon = PluginMarketingCoupon::where(['id' => $item->coupon_id])->find();
$PluginMarketingCoupon->expire_num = Db::raw('expire_num+1');
$PluginMarketingCoupon->save();
$item->state=UseState::EXPIRE['value'];
$item->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
Log::error('Process UserCoupon Expire Error:'.$th->getMessage(),$th);
}
}
} catch (\Throwable $th) {
}
});
}
}
@@ -0,0 +1,5 @@
<?php
return [
'form_basic_title'=>'Basic',
];
@@ -0,0 +1,6 @@
<?php
return [
'success' => 'Success',
'fail' => 'Fail',
];
@@ -0,0 +1,68 @@
<?php
return [
'Dashboard' => 'Dashboard',
'Console' => 'Console',
'User' => 'User',
'User List' => 'User List',
'Create User' => 'Create User',
'Edit User' => 'Edit User',
'Update Status' => 'Update Status',
'Functional' => 'Functional',
'Administrator' => 'Administrator',
'Staff List' => 'Staff List',
'Create Administrator' => 'Create Administrator',
'Edit Administrator' => 'Edit Administrator',
'Delete Administrator' => 'Delete Administrator',
'Move Role' => 'Move Role',
'Role Management' => 'Role Management',
'Role List' => 'Role List',
'Create Role' => 'Create Role',
'Edit Role' => 'Edit Role',
'Delete Role' => 'Delete Role',
'Systems' => 'Systems',
'Basic Settings' => 'Basic Settings',
'Control Settings' => 'Control Settings',
'Upload Settings' => 'Upload Settings',
'SMS Settings' => 'SMS Settings',
'Payment Management' => 'Payment Management',
'Payment Settings' => 'Payment Settings',
'Payment Template' => 'Payment Template',
'Create Payment Template' => 'Create Payment Template',
'Edit Payment Template' => 'Edit Payment Template',
'Delete Payment Template' => 'Delete Payment Template',
'Platform Management' => 'Platform Management',
'WeChat Mini Program' => 'WeChat Mini Program',
'WeChat Official Account' => 'WeChat Official Account',
'Alipay Mini Program' => 'Alipay Mini Program',
'WeChat Open Platform' => 'WeChat Open Platform',
'App Platform' => 'App Platform',
'H5 Platform' => 'H5 Platform',
'PC Platform' => 'PC Platform',
'Public Permissions' => 'Public Permissions',
'Edit Profile' => 'Edit Profile',
'Get Profile' => 'Get Profile',
'Logout' => 'Logout',
'Get Upload Categories' => 'Get Upload Categories',
'Edit Upload Category' => 'Edit Upload Category',
'Delete Upload Category' => 'Delete Upload Category',
'Upload File' => 'Upload File',
'Delete Upload File' => 'Delete Upload File',
'Edit Upload File' => 'Edit Upload File',
'Get Upload File List' => 'Get Upload File List',
'Login Title'=>'Admin Login',
'toolbar Lock'=>'Lock',
'toolbar Search'=>'Search',
'toolbar Notification'=>'Notification',
'toolbar FullScreen'=>'FullScreen',
'toolbar House'=>'Home',
'toolbar Control'=>'Control',
'userDropdownMenu updateSelf'=>'Admin Info',
'Logout Success'=>'Logout Success',
'PIN Code Cannot Be Empty'=>'PIN Code Cannot Be Empty',
'Please Enter 6 Digits PIN Code'=>'Please Enter 6 Digits PIN Code',
'Lock Success'=>'Lock Success',
'Unlock Success'=>'Unlock Success',
'form_basic_title'=>'Basic',
'Settings_basic_web_name'=>'Apps Name'
];
@@ -0,0 +1,5 @@
<?php
return [
'success' => 'Success',
];
@@ -0,0 +1,5 @@
<?php
return [
'form_basic_title'=>'基础信息',
];
@@ -0,0 +1,6 @@
<?php
return [
'success' => '成功',
'fail' => '失败',
];
@@ -0,0 +1,68 @@
<?php
return [
'Dashboard' => '首页',
'Console' => '控制台',
'User' => '用户',
'User List' => '用户列表',
'Create User' => '创建用户',
'Edit User' => '编辑用户',
'Update Status' => '更新状态',
'Functional' => '职能',
'Administrator' => '管理员',
'Staff List' => '人员列表',
'Create Administrator' => '创建管理员',
'Edit Administrator' => '编辑管理员',
'Delete Administrator' => '删除管理员',
'Move Role' => '移动角色',
'Role Management' => '角色',
'Role List' => '角色管理',
'Create Role' => '创建角色',
'Edit Role' => '编辑角色',
'Delete Role' => '删除角色',
'Systems' => '系统',
'Basic Settings' => '基本配置',
'Control Settings' => '控制台配置',
'Upload Settings' => '上传配置',
'SMS Settings' => '短信配置',
'Payment Management' => '支付管理',
'Payment Settings' => '支付配置',
'Payment Template' => '支付模板',
'Create Payment Template' => '新增支付模板',
'Edit Payment Template' => '编辑支付模板',
'Delete Payment Template' => '删除支付模板',
'Platform Management' => '平台管理',
'WeChat Mini Program' => '微信小程序',
'WeChat Official Account' => '微信公众号',
'Alipay Mini Program' => '支付宝小程序',
'WeChat Open Platform' => '微信开放平台',
'App Platform' => 'APP',
'H5 Platform' => 'H5',
'PC Platform' => 'PC',
'Public Permissions' => '公共权限',
'Edit Profile' => '修改自己的信息',
'Get Profile' => '获取自己的信息',
'Logout' => '退出登录',
'Get Upload Categories' => '获取上传分类',
'Edit Upload Category' => '编辑上传分类',
'Delete Upload Category' => '删除上传分类',
'Upload File' => '上传文件',
'Delete Upload File' => '删除上传文件',
'Edit Upload File' => '编辑上传文件',
'Get Upload File List' => '获取上传文件列表',
'Login Title'=>'管理员登录',
'toolbar Lock'=>'锁屏',
'toolbar Search'=>'搜索菜单',
'toolbar Notification'=>'查看通知',
'toolbar FullScreen'=>'全屏/退出全屏',
'toolbar House'=>'网站首页',
'toolbar Control'=>'网站前台控制台',
'userDropdownMenu updateSelf'=>'管理员信息',
'Logout Success'=>'退出成功',
'PIN Code Cannot Be Empty'=>'PIN码不能为空',
'Please Enter 6 Digits PIN Code'=>'请输入6位PIN码',
'Lock Success'=>'锁定成功',
'Unlock Success'=>'解锁成功',
'form_basic_title'=>'基础信息',
'Settings_basic_web_name'=>'应用名称'
];
@@ -0,0 +1,5 @@
<?php
return [
'success' => '成功',
];
@@ -0,0 +1,17 @@
<?php
namespace plugin\marketing\utils\enum;
use app\expose\enum\builder\Enum;
class BillingCycle extends Enum
{
const MONTH = [
'label' => '按月',
'value' => 'month'
];
const YEAR = [
'label' => '按年',
'value' => 'year'
];
}
@@ -0,0 +1,17 @@
<?php
namespace plugin\marketing\utils\enum;
use app\expose\enum\builder\Enum;
class CouponRule extends Enum
{
const FULL_PRICE = [
'label' => '满减券',
'value' => 'full_price'
];
const DISCOUNT = [
'label' => '打折券',
'value' => 'discount'
];
}
@@ -0,0 +1,17 @@
<?php
namespace plugin\marketing\utils\enum;
use app\expose\enum\builder\Enum;
class PlanKey extends Enum
{
const BASIC = [
'label' => '基础版',
'value' => 'basic'
];
const PRO = [
'label' => '专业版',
'value' => 'pro'
];
}
@@ -0,0 +1,37 @@
<?php
namespace plugin\marketing\utils\enum;
use app\expose\enum\builder\Enum;
class ReceiveType extends Enum
{
const REPEAT_DAY = [
'label' => '每日可领',
'value' => 'repeat_day',
'props' => [
'type' => 'primary'
]
];
const REPEAT_WEEK= [
'label' => '每周可领',
'value' => 'repeat_week',
'props' => [
'type' => 'primary'
]
];
const REPEAT_MONTH = [
'label' => '每月可领',
'value' => 'repeat_month',
'props' => [
'type' => 'primary'
]
];
const USER_ONLY = [
'label' => '账户唯一',
'value' => 'user_only',
'props' => [
'type' => 'success'
]
];
}
@@ -0,0 +1,30 @@
<?php
namespace plugin\marketing\utils\enum;
use app\expose\enum\builder\Enum;
class UseState extends Enum
{
const ON= [
'label' => '可用',
'value' => 0,
'props' => [
'type' => 'success'
]
];
const USED = [
'label' => '已使用',
'value' => 10,
'props' => [
'type' => 'info'
]
];
const EXPIRE= [
'label' => '过期',
'value' => 99,
'props' => [
'type' => 'danger'
]
];
}
@@ -0,0 +1,23 @@
<?php
namespace plugin\marketing\utils\enum;
use app\expose\enum\builder\Enum;
class UseType extends Enum
{
const UNLIMITED= [
'label' => '无限制',
'value' => 'unlimited',
'props' => [
'type' => 'danger'
]
];
const FIRST_ORDER = [
'label' => '首单可用',
'value' => 'first_order',
'props' => [
'type' => 'success'
]
];
}