初始上传
This commit is contained in:
41
addon/manjian/api/controller/Manjian.php
Executable file
41
addon/manjian/api/controller/Manjian.php
Executable file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\api\controller;
|
||||
|
||||
use app\api\controller\BaseApi;
|
||||
use addon\manjian\model\Manjian as ManjianModel;
|
||||
|
||||
/**
|
||||
* 满减
|
||||
*/
|
||||
class Manjian extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 信息
|
||||
* @param int $id
|
||||
* @return false|string
|
||||
*/
|
||||
public function info($id = 0)
|
||||
{
|
||||
$goods_id = $this->params['goods_id'] ?? 0;
|
||||
if (!empty($id)) {
|
||||
$goods_id = $id;
|
||||
}
|
||||
if (empty($goods_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_GOODS_ID'));
|
||||
}
|
||||
$manjian_model = new ManjianModel();
|
||||
$res = $manjian_model->getGoodsManjianInfo($goods_id, $this->site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
}
|
||||
38
addon/manjian/config/diy_view.php
Executable file
38
addon/manjian/config/diy_view.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
return [
|
||||
|
||||
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
|
||||
'template' => [],
|
||||
|
||||
// 后台自定义组件——装修
|
||||
'util' => [],
|
||||
|
||||
// 自定义页面路径
|
||||
'link' => [],
|
||||
|
||||
// 自定义图标库
|
||||
'icon_library' => [],
|
||||
|
||||
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
|
||||
'component' => [],
|
||||
|
||||
// uni-app 页面,多个逗号隔开
|
||||
'pages' => [],
|
||||
|
||||
// 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
|
||||
'info' => [],
|
||||
|
||||
// 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
|
||||
'theme' => [],
|
||||
|
||||
// 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
|
||||
'data' => []
|
||||
];
|
||||
37
addon/manjian/config/event.php
Executable file
37
addon/manjian/config/event.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// 事件定义文件
|
||||
return [
|
||||
'bind' => [
|
||||
|
||||
],
|
||||
|
||||
'listen' => [
|
||||
//满减开启
|
||||
'OpenManjian' => [
|
||||
'addon\manjian\event\OpenManjian',
|
||||
],
|
||||
//满减关闭
|
||||
'CloseManjian' => [
|
||||
'addon\manjian\event\CloseManjian',
|
||||
],
|
||||
//展示活动
|
||||
'ShowPromotion' => [
|
||||
'addon\manjian\event\ShowPromotion',
|
||||
],
|
||||
// 订单支付
|
||||
'OrderPayAfter' => [
|
||||
'addon\manjian\event\OrderPayAfter'
|
||||
],
|
||||
//会员账户类型(操作来源)
|
||||
'MemberAccountFromType' => [
|
||||
'addon\manjian\event\MemberAccountFromType',
|
||||
],
|
||||
//退款后收回奖励
|
||||
'OrderRefundAllFinish' => [
|
||||
'addon\manjian\event\OrderRefundAllFinish'
|
||||
]
|
||||
],
|
||||
|
||||
'subscribe' => [
|
||||
],
|
||||
];
|
||||
21
addon/manjian/config/info.php
Executable file
21
addon/manjian/config/info.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
return [
|
||||
'name' => 'manjian',
|
||||
'title' => '满减送活动',
|
||||
'description' => '满减送活动',
|
||||
'type' => 'promotion', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
|
||||
'status' => 1,
|
||||
'author' => '',
|
||||
'version' => '5.5.3',
|
||||
'version_no' => '553250709001',
|
||||
'content' => '',
|
||||
];
|
||||
61
addon/manjian/config/menu_shop.php
Executable file
61
addon/manjian/config/menu_shop.php
Executable file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 平台端菜单设置
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
[
|
||||
'name' => 'PROMOTION_MANJIAN',
|
||||
'title' => '满减送活动',
|
||||
'url' => 'manjian://shop/manjian/lists',
|
||||
'parent' => 'PROMOTION_CENTER',
|
||||
'is_show' => 1,
|
||||
'is_control' => 1,
|
||||
'is_icon' => 0,
|
||||
'picture' => '',
|
||||
'picture_select' => '',
|
||||
'sort' => 100,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'PROMOTION_MANJIAN_DETAIL',
|
||||
'title' => '活动详情',
|
||||
'url' => 'manjian://shop/manjian/detail',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_MANJIAN_ADD',
|
||||
'title' => '添加活动',
|
||||
'url' => 'manjian://shop/manjian/add',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_MANJIAN_EDIT',
|
||||
'title' => '编辑活动',
|
||||
'url' => 'manjian://shop/manjian/edit',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_MANJIAN_CLOSE',
|
||||
'title' => '关闭活动',
|
||||
'url' => 'manjian://shop/manjian/close',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_MANJIAN_DELETE',
|
||||
'title' => '删除活动',
|
||||
'url' => 'manjian://shop/manjian/delete',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
|
||||
]
|
||||
],
|
||||
];
|
||||
1
addon/manjian/data/install.sql
Executable file
1
addon/manjian/data/install.sql
Executable file
@@ -0,0 +1 @@
|
||||
SET NAMES 'utf8';
|
||||
1
addon/manjian/data/uninstall.sql
Executable file
1
addon/manjian/data/uninstall.sql
Executable file
@@ -0,0 +1 @@
|
||||
SET NAMES 'utf8';
|
||||
28
addon/manjian/event/CloseManjian.php
Executable file
28
addon/manjian/event/CloseManjian.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
use addon\manjian\model\Manjian;
|
||||
|
||||
/**
|
||||
* 关闭活动
|
||||
*/
|
||||
class CloseManjian
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$manjian = new Manjian();
|
||||
$res = $manjian->cronCloseManjian($params['relate_id']);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
31
addon/manjian/event/Install.php
Executable file
31
addon/manjian/event/Install.php
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
/**
|
||||
* 应用安装
|
||||
*/
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
execute_sql('addon/manjian/data/install.sql');
|
||||
return success();
|
||||
} catch (\Exception $e) {
|
||||
return error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
37
addon/manjian/event/MemberAccountFromType.php
Executable file
37
addon/manjian/event/MemberAccountFromType.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
/**
|
||||
* 会员账户变化来源类型
|
||||
*/
|
||||
class MemberAccountFromType
|
||||
{
|
||||
|
||||
public function handle($data)
|
||||
{
|
||||
$from_type = [
|
||||
'point' => [
|
||||
'manjian' => [
|
||||
'type_name' => '满减送',
|
||||
'type_url' => '',
|
||||
],
|
||||
]
|
||||
];
|
||||
if ($data == '') {
|
||||
return $from_type;
|
||||
} else {
|
||||
return $from_type[$data] ?? [];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
28
addon/manjian/event/OpenManjian.php
Executable file
28
addon/manjian/event/OpenManjian.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
use addon\manjian\model\Manjian;
|
||||
|
||||
/**
|
||||
* 启动活动
|
||||
*/
|
||||
class OpenManjian
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$manjian = new Manjian();
|
||||
$res = $manjian->cronOpenManjian($params['relate_id']);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
28
addon/manjian/event/OrderPayAfter.php
Executable file
28
addon/manjian/event/OrderPayAfter.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
use addon\manjian\model\Order;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 订单完成
|
||||
*/
|
||||
class OrderPayAfter
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$order = new Order();
|
||||
$order->orderPay($params);
|
||||
}
|
||||
}
|
||||
70
addon/manjian/event/OrderRefundAllFinish.php
Executable file
70
addon/manjian/event/OrderRefundAllFinish.php
Executable file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
use addon\coupon\model\MemberCoupon;
|
||||
use app\dict\member_account\AccountDict;
|
||||
use app\model\member\MemberAccount;
|
||||
|
||||
/**
|
||||
* 订单完全退款后收回奖励
|
||||
*/
|
||||
class OrderRefundAllFinish
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$order_info = $params['order_info'];
|
||||
$member_id = $order_info['member_id'];
|
||||
$site_id = $order_info['site_id'];
|
||||
//散客不参与
|
||||
if ($member_id > 0) {
|
||||
$order_id = $order_info['order_id'];
|
||||
$list = model('promotion_mansong_record')->getList([['order_id', '=', $order_id], ['status', '=', 1]]);
|
||||
if (!empty($list)) {
|
||||
$member_coupon_model = new MemberCoupon();
|
||||
foreach ($list as $item) {
|
||||
try {
|
||||
// 发放积分
|
||||
$point = $item[ 'point' ] ?? 0;
|
||||
if ($point > 0) {
|
||||
$member_account = new Memberaccount();
|
||||
$member_account->addMemberAccount($site_id, $member_id, AccountDict::point, -$point, 'point_cancel', $item[ 'manjian_id' ], '活动奖励取消');
|
||||
}
|
||||
// 发放优惠券
|
||||
$coupon = $item['coupon'] ?? '';
|
||||
$coupon_num = $item['coupon_num'] ?? '';
|
||||
if ($coupon && $coupon_num) {
|
||||
$coupon_list = explode(',', $coupon);
|
||||
$coupon_num = explode(',', $coupon_num);
|
||||
$coupon_data = [];
|
||||
foreach ($coupon_list as $k => $coupon_item) {
|
||||
$coupon_data[] = [
|
||||
'coupon_type_id' => $coupon_item,
|
||||
'num' => $coupon_num[ $k ] ?? 1
|
||||
];
|
||||
}
|
||||
$member_coupon_model->cancelByPromotion([
|
||||
'coupon_data' => $coupon_data,
|
||||
'member_id' => $member_id,
|
||||
]);
|
||||
}
|
||||
// 定义为收回奖励
|
||||
model('promotion_mansong_record')->update([ 'status' => 2 ], [ [ 'id', '=', $item[ 'id' ] ] ]);
|
||||
model('promotion_mansong_record')->commit();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_mansong_record')->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
90
addon/manjian/event/ShowPromotion.php
Executable file
90
addon/manjian/event/ShowPromotion.php
Executable file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
*/
|
||||
class ShowPromotion
|
||||
{
|
||||
public $promotion_type = 'time_limit';
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function handle($params = [])
|
||||
{
|
||||
$data = [
|
||||
'shop' => [
|
||||
[
|
||||
//插件名称
|
||||
'name' => 'manjian',
|
||||
//店铺端展示分类 shop:营销活动 member:互动营销
|
||||
'show_type' => 'shop',
|
||||
//展示主题
|
||||
'title' => '满减活动',
|
||||
//展示介绍
|
||||
'description' => '购满指定金额享受优惠',
|
||||
//展示图标
|
||||
'icon' => 'addon/manjian/icon.png',
|
||||
//跳转链接
|
||||
'url' => 'manjian://shop/manjian/lists',
|
||||
'summary' => $this->summary($params)
|
||||
]
|
||||
]
|
||||
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 营销活动概况
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
private function summary($params)
|
||||
{
|
||||
if (empty($params)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
|
||||
return [];
|
||||
}
|
||||
|
||||
//获取活动数量
|
||||
if (isset($params[ 'count' ])) {
|
||||
$count = model("promotion_manjian")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
|
||||
return [
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
//获取活动概况,需要获取开始时间与结束时间
|
||||
if (isset($params[ 'summary' ])) {
|
||||
$list = model("promotion_manjian")->getList([
|
||||
[ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
|
||||
[ 'site_id', '=', $params[ 'site_id' ] ],
|
||||
[ 'status', '<>', -1 ]
|
||||
], 'manjian_name as promotion_name,manjian_id as promotion_id,start_time,end_time');
|
||||
return !empty($list) ? [
|
||||
'time_limit' => [
|
||||
'count' => count($list),
|
||||
'detail' => $list,
|
||||
'color' => '#FFA666'
|
||||
]
|
||||
] : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
31
addon/manjian/event/UnInstall.php
Executable file
31
addon/manjian/event/UnInstall.php
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\event;
|
||||
|
||||
/**
|
||||
* 应用卸载
|
||||
*/
|
||||
class UnInstall
|
||||
{
|
||||
/**
|
||||
* 执行卸载
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
return error('', "系统插件不允许删除");
|
||||
//execute_sql('addon/manjian/data/uninstall.sql');
|
||||
//return success();
|
||||
} catch (\Exception $e) {
|
||||
return error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
addon/manjian/icon.png
Executable file
BIN
addon/manjian/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
489
addon/manjian/model/Manjian.php
Executable file
489
addon/manjian/model/Manjian.php
Executable file
@@ -0,0 +1,489 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\model;
|
||||
|
||||
use app\model\system\Cron;
|
||||
use app\model\BaseModel;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 满减
|
||||
*/
|
||||
class Manjian extends BaseModel
|
||||
{
|
||||
//满减送状态
|
||||
private $manjian_status = [
|
||||
0 => '未开始',
|
||||
1 => '进行中',
|
||||
2 => '已结束',
|
||||
-1 => '已关闭',
|
||||
];
|
||||
|
||||
public function getManjianStatus()
|
||||
{
|
||||
return $this->manjian_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加满减
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function addManjian($data)
|
||||
{
|
||||
//时间检测
|
||||
if ($data[ 'end_time' ] < time()) {
|
||||
return $this->error('', '结束时间不能早于当前时间');
|
||||
}
|
||||
|
||||
$manjian_activity_info = model('promotion_manjian')->getInfo([
|
||||
[ 'status', 'in', "0,1" ],
|
||||
[ 'site_id', '=', $data[ 'site_id' ] ],
|
||||
[ 'manjian_type', '=', 1 ],
|
||||
[ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]
|
||||
], 'manjian_name,start_time,end_time');
|
||||
if (!empty($manjian_activity_info)) {
|
||||
$key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
|
||||
Cache::set($key, [ 'list' => [ $manjian_activity_info ], 'type' => 'activity', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
|
||||
return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
|
||||
}
|
||||
|
||||
if ($data[ 'manjian_type' ] == 2) {
|
||||
$join = [
|
||||
[ 'promotion_manjian pm', 'pm.manjian_id = pmg.manjian_id', 'left' ],
|
||||
[ 'goods g', 'g.goods_id = pmg.goods_id', 'left' ]
|
||||
];
|
||||
|
||||
// 查询存在交集的满减活动商品
|
||||
$condition_bing = [
|
||||
[ 'pmg.status', 'in', "0,1" ],
|
||||
[ 'pmg.site_id', '=', $data[ 'site_id' ] ],
|
||||
[ 'pmg.goods_id', 'in', $data[ 'goods_ids' ] ],
|
||||
[ '', 'exp', Db::raw('not ( (pmg.start_time > ' . $data[ 'end_time' ] . ' and pmg.start_time > ' . $data[ 'start_time' ] . ' ) or (pmg.end_time < ' . $data[ 'start_time' ] . ' and pmg.end_time < ' . $data[ 'end_time' ] . '))') ]
|
||||
];
|
||||
$manjian_count = model('promotion_manjian_goods')->getList($condition_bing, 'pmg.start_time,pmg.end_time,pm.manjian_name,g.goods_name', '', 'pmg', $join);
|
||||
if (!empty($manjian_count)) {
|
||||
$key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
|
||||
Cache::set($key, [ 'list' => $manjian_count, 'type' => 'goods', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
|
||||
return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
|
||||
}
|
||||
}
|
||||
|
||||
$data[ 'create_time' ] = time();
|
||||
if ($data[ 'start_time' ] <= time()) {
|
||||
$data[ 'status' ] = 1;//直接启动
|
||||
} else {
|
||||
$data[ 'status' ] = 0;
|
||||
}
|
||||
$goods_ids_arr = $data[ 'goods_ids' ];
|
||||
$data[ 'goods_ids' ] = "," . $data[ 'goods_ids' ] . ",";
|
||||
|
||||
model('promotion_manjian')->startTrans();
|
||||
try {
|
||||
$manjian_id = model('promotion_manjian')->add($data);
|
||||
if ($data[ 'manjian_type' ] != 1) {
|
||||
$goods_ids = explode(',', $goods_ids_arr);
|
||||
$goods_data = [];
|
||||
foreach ($goods_ids as $v) {
|
||||
$goods_data[] = [
|
||||
'manjian_id' => $manjian_id,
|
||||
'site_id' => $data['site_id'],
|
||||
'goods_id' => $v,
|
||||
'manjian_type' => $data['manjian_type'],
|
||||
'status' => $data['status'],
|
||||
'rule_json' => $data['rule_json'],
|
||||
'start_time' => $data['start_time'],
|
||||
'end_time' => $data['end_time']
|
||||
];
|
||||
}
|
||||
model('promotion_manjian_goods')->addList($goods_data);
|
||||
}
|
||||
|
||||
$cron = new Cron();
|
||||
if ($data[ 'start_time' ] <= time()) {
|
||||
$cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
|
||||
} else {
|
||||
$cron->addCron(1, 0, "满减开启", "OpenManjian", $data[ 'start_time' ], $manjian_id);
|
||||
$cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
|
||||
}
|
||||
|
||||
model('promotion_manjian')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_manjian')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改满减
|
||||
* @param unknown $data
|
||||
* @return multitype:string
|
||||
*/
|
||||
public function editManjian($data)
|
||||
{
|
||||
$manjian_id = $data[ 'manjian_id' ];
|
||||
unset($data[ 'manjian_id' ]);
|
||||
$manjian_status = model('promotion_manjian')->getInfo([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'manjian_id', '=', $manjian_id ] ], 'status');
|
||||
if ($manjian_status[ 'status' ] != 0 && $manjian_status[ 'status' ] != 1) {
|
||||
return $this->error('', '只有未开始和进行中的满减活动才能进行修改');
|
||||
}
|
||||
|
||||
//时间检测
|
||||
if ($data[ 'end_time' ] < time()) {
|
||||
return $this->error('', '结束时间不能早于当前时间');
|
||||
}
|
||||
|
||||
$manjian_activity_info = model('promotion_manjian')->getInfo([
|
||||
[ 'status', 'in', "0,1" ],
|
||||
[ 'site_id', '=', $data[ 'site_id' ] ],
|
||||
[ 'manjian_type', '=', 1 ],
|
||||
[ 'manjian_id', '<>', $manjian_id ],
|
||||
[ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]
|
||||
], 'manjian_name,start_time,end_time');
|
||||
if (!empty($manjian_activity_info)) {
|
||||
$key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
|
||||
Cache::set($key, [ 'list' => [ $manjian_activity_info ], 'type' => 'activity', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
|
||||
return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
|
||||
}
|
||||
|
||||
if ($data[ 'manjian_type' ] == 2) {
|
||||
$join = [
|
||||
[ 'promotion_manjian pm', 'pm.manjian_id = pmg.manjian_id', 'left' ],
|
||||
[ 'goods g', 'g.goods_id = pmg.goods_id', 'left' ]
|
||||
];
|
||||
// 查询存在交集的满减活动商品
|
||||
$condition_jiao = [
|
||||
[ 'pmg.status', 'in', "0,1" ],
|
||||
[ 'pmg.site_id', '=', $data[ 'site_id' ] ],
|
||||
[ 'pmg.manjian_id', '<>', $manjian_id ],
|
||||
[ 'pmg.goods_id', 'in', $data[ 'goods_ids' ] ],
|
||||
[ '', 'exp', Db::raw('not ( (pmg.start_time > ' . $data[ 'end_time' ] . ' and pmg.start_time > ' . $data[ 'start_time' ] . ' ) or (pmg.end_time < ' . $data[ 'start_time' ] . ' and pmg.end_time < ' . $data[ 'end_time' ] . '))') ]
|
||||
];
|
||||
$manjian_goods_count = model('promotion_manjian_goods')->getList($condition_jiao, 'pmg.start_time,pmg.end_time,pm.manjian_name,g.goods_name', '', 'pmg', $join);
|
||||
if (!empty($manjian_goods_count)) {
|
||||
$key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
|
||||
Cache::set($key, [ 'list' => $manjian_goods_count, 'type' => 'goods', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
|
||||
return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
|
||||
}
|
||||
}
|
||||
|
||||
if ($data[ 'start_time' ] <= time()) {
|
||||
$data[ 'status' ] = 1;//直接启动
|
||||
} else {
|
||||
$data[ 'status' ] = 0;
|
||||
}
|
||||
|
||||
model('promotion_manjian')->startTrans();
|
||||
try {
|
||||
|
||||
$goods_ids_arr = $data[ 'goods_ids' ];
|
||||
$data[ 'goods_ids' ] = "," . $data[ 'goods_ids' ] . ",";
|
||||
|
||||
model('promotion_manjian')->update($data, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'manjian_id', '=', $manjian_id ] ]);
|
||||
model('promotion_manjian_goods')->delete([
|
||||
[ 'site_id', '=', $data[ 'site_id' ] ],
|
||||
[ 'manjian_id', '=', $manjian_id ]
|
||||
]);
|
||||
|
||||
if ($data[ 'manjian_type' ] != 1) {
|
||||
//获取商品id
|
||||
$goods_ids = explode(',', $goods_ids_arr);
|
||||
$goods_data = [];
|
||||
foreach ($goods_ids as $v) {
|
||||
$goods_data[] = [
|
||||
'manjian_id' => $manjian_id,
|
||||
'site_id' => $data['site_id'],
|
||||
'goods_id' => $v,
|
||||
'manjian_type' => $data['manjian_type'],
|
||||
'status' => $data['status'],
|
||||
'rule_json' => $data['rule_json'],
|
||||
'start_time' => $data['start_time'],
|
||||
'end_time' => $data['end_time']
|
||||
];
|
||||
}
|
||||
model('promotion_manjian_goods')->addList($goods_data);
|
||||
}
|
||||
|
||||
$cron = new Cron();
|
||||
$cron->deleteCron([ [ 'event', '=', 'CloseManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
|
||||
$cron->deleteCron([ [ 'event', '=', 'OpenManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
|
||||
if ($data[ 'start_time' ] <= time()) {
|
||||
$cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
|
||||
} else {
|
||||
$cron->addCron(1, 0, "满减开启", "OpenManjian", $data[ 'start_time' ], $manjian_id);
|
||||
$cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
|
||||
}
|
||||
model('promotion_manjian')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_manjian')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除满减
|
||||
* @param unknown $manjian_id
|
||||
*/
|
||||
public function deleteManjian($manjian_id, $site_id)
|
||||
{
|
||||
$condition = [
|
||||
[ 'manjian_id', '=', $manjian_id ],
|
||||
[ 'site_id', '=', $site_id ]
|
||||
];
|
||||
$res = model('promotion_manjian')->delete($condition);
|
||||
if ($res) {
|
||||
model('promotion_manjian_goods')->delete($condition);
|
||||
$cron = new Cron();
|
||||
$cron->deleteCron([ [ 'event', '=', 'OpenManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
|
||||
$cron->deleteCron([ [ 'event', '=', 'CloseManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取满减信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
*/
|
||||
public function getManjianInfo($condition, $field = '*')
|
||||
{
|
||||
$res = model('promotion_manjian')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减详情
|
||||
* @param $manjian_id
|
||||
* @param $site_id
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getManjianDetail($manjian_id, $site_id, $field = '*')
|
||||
{
|
||||
$res = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', '=', $site_id ] ], $field);
|
||||
if (!empty($res)) {
|
||||
//获取商品信息
|
||||
if ($res[ 'manjian_type' ] == 2) {//指定商品
|
||||
$field = 'g.goods_id,g.goods_name,g.goods_stock,g.price,g.goods_image';
|
||||
$alias = 'mg';
|
||||
$join = [
|
||||
[
|
||||
'goods g',
|
||||
'g.goods_id = mg.goods_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
|
||||
$goods_list = model('promotion_manjian_goods')->getList([ [ 'mg.manjian_id', '=', $manjian_id ], [ 'mg.site_id', '=', $site_id ] ], $field, '', $alias, $join);
|
||||
}
|
||||
|
||||
if (isset($res[ 'rule_json' ])) {
|
||||
$rule = json_decode($res[ 'rule_json' ], true);
|
||||
foreach ($rule as $key => $item) {
|
||||
if (isset($item[ 'coupon' ]) && !empty($item[ 'coupon' ])) {
|
||||
$coupon = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $item[ 'coupon' ] ] ], 'coupon_type_id,coupon_name,type,at_least,money,discount');
|
||||
$rule[ $key ][ 'coupon_data' ] = $coupon;
|
||||
$rule[ $key ][ 'coupon_num' ] = explode(',', $item[ 'coupon_num' ]);
|
||||
}
|
||||
}
|
||||
$res[ 'rule' ] = $rule;
|
||||
}
|
||||
$res[ 'goods_list' ] = $goods_list ?? [];
|
||||
$res[ 'goods_list_count' ] = count($res[ 'goods_list' ]);
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取满减列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param string $limit
|
||||
*/
|
||||
public function getManjianList($condition = [], $field = '*', $order = 'manjian_id desc', $limit = null)
|
||||
{
|
||||
$list = model('promotion_manjian')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取满减列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param string $limit
|
||||
*/
|
||||
public function getManjianGoodsList($condition = [], $field = '', $order = 'id desc', $limit = null)
|
||||
{
|
||||
$list = model('promotion_manjian_goods')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新一条商品满减活动
|
||||
* @param int $goods_id
|
||||
* @param int $site_id
|
||||
*/
|
||||
public function getGoodsManjianInfo($goods_id, $site_id)
|
||||
{
|
||||
$condition = [
|
||||
[ 'site_id', '=', $site_id ],
|
||||
[ 'status', '=', 1 ],
|
||||
[ 'end_time', '>', time() ],
|
||||
[ 'manjian_type', '=', 1 ]
|
||||
];
|
||||
$first_info = model('promotion_manjian')->getFirstData($condition, 'manjian_id,site_id,manjian_name,manjian_type,type,goods_ids,status,start_time,end_time,rule_json', 'create_time desc');
|
||||
if (empty($first_info)) {
|
||||
$condition = [
|
||||
[ 'site_id', '=', $site_id ],
|
||||
[ 'status', '=', 1 ],
|
||||
[ 'end_time', '>', time() ],
|
||||
[ 'manjian_type', '=', 2 ],
|
||||
[ 'goods_ids', 'like', [ '%,' . $goods_id . ',%', '' ], 'or' ]
|
||||
];
|
||||
$first_info = model('promotion_manjian')->getFirstData($condition, 'manjian_id,site_id,manjian_name,manjian_type,type,goods_ids,status,start_time,end_time,rule_json', 'create_time desc');
|
||||
}
|
||||
if (!empty($first_info)) {
|
||||
$rule = json_decode($first_info[ 'rule_json' ], true);
|
||||
foreach ($rule as $key => $item) {
|
||||
if (isset($item[ 'coupon' ]) && !empty($item[ 'coupon' ])) {
|
||||
$coupon = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $item[ 'coupon' ] ] ], 'coupon_name,type,at_least,money,discount');
|
||||
$rule[ $key ][ 'coupon_num' ] = empty($item[ 'coupon_num' ]) ? [ 1 ] : explode(',', $item[ 'coupon_num' ]);
|
||||
$rule[ $key ][ 'coupon_data' ] = $coupon;
|
||||
}
|
||||
}
|
||||
$first_info[ 'rule_json' ] = $rule;
|
||||
}
|
||||
|
||||
return $this->success($first_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取满减分页列表
|
||||
* @param array $condition
|
||||
* @param number $page
|
||||
* @param string $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getManjianPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
|
||||
{
|
||||
$list = model('promotion_manjian')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动满减
|
||||
* @param unknown $manjian_id
|
||||
*/
|
||||
public function cronOpenManjian($manjian_id)
|
||||
{
|
||||
$manjian_info = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ] ], 'start_time,status');
|
||||
if (!empty($manjian_info)) {
|
||||
if ($manjian_info[ 'start_time' ] <= time() && $manjian_info[ 'status' ] == 0) {
|
||||
model('promotion_manjian')->startTrans();
|
||||
try {
|
||||
model('promotion_manjian')->update([ 'status' => 1 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
|
||||
model('promotion_manjian_goods')->update([ 'status' => 1 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
|
||||
model('promotion_manjian')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_manjian')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
return $this->error("", "满减活动已开启或者关闭");
|
||||
}
|
||||
} else {
|
||||
return $this->error("", "满减活动不存在");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束满减 自动事件
|
||||
* @param unknown $manjian_id
|
||||
*/
|
||||
public function cronCloseManjian($manjian_id)
|
||||
{
|
||||
$manjian_info = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ] ], 'end_time,status');
|
||||
if (!empty($manjian_info)) {
|
||||
if ($manjian_info[ 'end_time' ] <= time() && $manjian_info[ 'status' ] == 1) {
|
||||
model('promotion_manjian')->startTrans();
|
||||
try {
|
||||
|
||||
model('promotion_manjian')->update([ 'status' => 2 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
|
||||
model('promotion_manjian_goods')->update([ 'status' => 2 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
|
||||
|
||||
model('promotion_manjian')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
model('promotion_manjian')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->error("", "满减活动已关闭");
|
||||
}
|
||||
} else {
|
||||
return $this->error("", "满减活动不存在");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭满减 手动关闭
|
||||
* @param unknown $manjian_id
|
||||
*/
|
||||
public function closeManjian($manjian_id, $site_id)
|
||||
{
|
||||
$condition = array (
|
||||
[ 'manjian_id', '=', $manjian_id ],
|
||||
[ 'site_id', "=", $site_id ]
|
||||
);
|
||||
$manjian_info = model('promotion_manjian')->getInfo($condition, 'start_time,end_time,status');
|
||||
if (!empty($manjian_info)) {
|
||||
if ($manjian_info[ 'status' ] == 1) {
|
||||
|
||||
if ($manjian_info[ 'status' ] == 1) {
|
||||
|
||||
model('promotion_manjian')->startTrans();
|
||||
try {
|
||||
|
||||
model('promotion_manjian')->update([ 'status' => -1 ], [ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', "=", $site_id ] ]);
|
||||
model('promotion_manjian_goods')->update([ 'status' => -1 ], [ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', "=", $site_id ] ]);
|
||||
|
||||
model('promotion_manjian')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
model('promotion_manjian')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->error("", "满减活动已关闭");
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->error("", "满减活动已关闭");
|
||||
}
|
||||
} else {
|
||||
return $this->error("", "满减活动不存在");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
69
addon/manjian/model/Order.php
Executable file
69
addon/manjian/model/Order.php
Executable file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\model;
|
||||
|
||||
use addon\coupon\model\Coupon;
|
||||
use app\model\BaseModel;
|
||||
use app\model\member\MemberAccount;
|
||||
use app\model\order\Order as BaseOrder;
|
||||
use app\model\order\OrderCommon;
|
||||
use think\facade\Log;
|
||||
|
||||
class Order extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 订单完成发放满减送所送积分
|
||||
* @param $order_id
|
||||
*/
|
||||
public function orderPay($order_info)
|
||||
{
|
||||
$pay_status = $order_info['pay_status'];
|
||||
if($pay_status == 1){
|
||||
$member_id = $order_info[ 'member_id' ];
|
||||
$order_id = $order_info['order_id'];
|
||||
//存在散客的情况
|
||||
if ($member_id > 0) {
|
||||
$mansong_record = model('promotion_mansong_record')->getList([ [ 'order_id', '=', $order_id ], [ 'status', '=', 0 ] ]);
|
||||
if (!empty($mansong_record)) {
|
||||
model('promotion_mansong_record')->startTrans();
|
||||
foreach ($mansong_record as $item) {
|
||||
try {
|
||||
// 发放积分
|
||||
if (!empty($item[ 'point' ])) {
|
||||
$member_account = new Memberaccount();
|
||||
$member_account->addMemberAccount($item[ 'site_id' ], $item[ 'member_id' ], 'point', $item[ 'point' ], 'manjian', $item[ 'manjian_id' ], "活动奖励发放");
|
||||
}
|
||||
// 发放优惠券
|
||||
if (!empty($item[ 'coupon' ])) {
|
||||
$coupon = new Coupon();
|
||||
$coupon_list = explode(',', $item[ 'coupon' ]);
|
||||
$coupon_num = explode(',', $item[ 'coupon_num' ]);
|
||||
$coupon_data = [];
|
||||
foreach ($coupon_list as $k => $coupon_item) {
|
||||
$coupon_data[] = [
|
||||
'coupon_type_id' => $coupon_item,
|
||||
'num' => $coupon_num[ $k ] ?? 1
|
||||
];
|
||||
}
|
||||
$coupon->giveCoupon($coupon_data, $item[ 'site_id' ], $item[ 'member_id' ], Coupon::GET_TYPE_ACTIVITY_GIVE, $item['id']);
|
||||
}
|
||||
// 变更发放状态
|
||||
model('promotion_mansong_record')->update([ 'status' => 1 ], [ [ 'id', '=', $item[ 'id' ] ] ]);
|
||||
model('promotion_mansong_record')->commit();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_mansong_record')->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
221
addon/manjian/shop/controller/Manjian.php
Executable file
221
addon/manjian/shop/controller/Manjian.php
Executable file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\manjian\shop\controller;
|
||||
|
||||
use addon\coupon\model\CouponType;
|
||||
use app\model\member\MemberLevel;
|
||||
use app\shop\controller\BaseShop;
|
||||
use addon\manjian\model\Manjian as ManjianModel;
|
||||
use think\App;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 满减控制器
|
||||
*/
|
||||
class Manjian extends BaseShop
|
||||
{
|
||||
public function __construct(App $app = null)
|
||||
{
|
||||
$this->replace = [
|
||||
'MANJIAN_IMG' => __ROOT__ . '/addon/manjian/shop/view/public/img',
|
||||
'MANJIAN_JS' => __ROOT__ . '/addon/manjian/shop/view/public/js',
|
||||
'MANJIAN_CSS' => __ROOT__ . '/addon/manjian/shop/view/public/css',
|
||||
];
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$page = input('page', 1);
|
||||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||||
$manjian_name = input('manjian_name', '');
|
||||
$status = input('status', '');
|
||||
$condition = [];
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'manjian_name', 'like', '%' . $manjian_name . '%' ];
|
||||
if ($status != null) {
|
||||
$condition[] = [ 'status', '=', $status ];
|
||||
}
|
||||
|
||||
$start_time = input('start_time', '');
|
||||
$end_time = input('end_time', '');
|
||||
|
||||
if ($start_time && !$end_time) {
|
||||
$condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
|
||||
} elseif (!$start_time && $end_time) {
|
||||
$condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
|
||||
} elseif ($start_time && $end_time) {
|
||||
$start_timestamp = date_to_time($start_time);
|
||||
$end_timestamp = date_to_time($end_time);
|
||||
$sql = "start_time between {$start_timestamp} and {$end_timestamp}";
|
||||
$sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
|
||||
$sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
|
||||
$condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
|
||||
}
|
||||
|
||||
$order = 'create_time desc';
|
||||
$field = 'manjian_id,manjian_name,start_time,end_time,create_time,status';
|
||||
|
||||
$manjian_model = new ManjianModel();
|
||||
$res = $manjian_model->getManjianPageList($condition, $page, $page_size, $order, $field);
|
||||
|
||||
//获取状态名称
|
||||
$manjian_status_arr = $manjian_model->getManjianStatus();
|
||||
foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
|
||||
$res[ 'data' ][ 'list' ][ $key ][ 'status_name' ] = $manjian_status_arr[ $val[ 'status' ] ];
|
||||
}
|
||||
return $res;
|
||||
|
||||
} else {
|
||||
//满减状态
|
||||
$manjian_model = new ManjianModel();
|
||||
$manjian_status_arr = $manjian_model->getManjianStatus();
|
||||
$this->assign('manjian_status_arr', $manjian_status_arr);
|
||||
|
||||
return $this->fetch("manjian/lists");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$member_level_model = new MemberLevel();
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'manjian_name' => input('manjian_name', ''),
|
||||
'manjian_type' => input('manjian_type', ''),
|
||||
'type' => input('type', 0),
|
||||
'number' => input('number', 0),
|
||||
'goods_ids' => input('goods_ids', ''),
|
||||
'start_time' => strtotime(input('start_time', '')),
|
||||
'end_time' => strtotime(input('end_time', '')),
|
||||
'rule_json' => input('rule_json', ''),
|
||||
'remark' => input('remark', '')
|
||||
];
|
||||
|
||||
$manjian_model = new ManjianModel();
|
||||
return $manjian_model->addManjian($data);
|
||||
} else {
|
||||
//获取优惠券列表
|
||||
$coupon_model = new CouponType();
|
||||
$condition = [
|
||||
[ 'status', '=', 1 ],
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
];
|
||||
//优惠券字段
|
||||
$coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time,goods_type,max_fetch';
|
||||
$coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
|
||||
$this->assign('coupon_list', $coupon_list);
|
||||
$this->assign('level_time', $member_level_model->level_time);
|
||||
return $this->fetch("manjian/add");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$member_level_model = new MemberLevel();
|
||||
$manjian_model = new ManjianModel();
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'manjian_id' => input('manjian_id', 0),
|
||||
'site_id' => $this->site_id,
|
||||
'manjian_name' => input('manjian_name', ''),
|
||||
'manjian_type' => input('manjian_type', ''),
|
||||
'type' => input('type', 0),
|
||||
'goods_ids' => input('goods_ids', ''),
|
||||
'start_time' => strtotime(input('start_time', '')),
|
||||
'end_time' => strtotime(input('end_time', '')),
|
||||
'rule_json' => input('rule_json', ''),
|
||||
'remark' => input('remark', '')
|
||||
];
|
||||
return $manjian_model->editManjian($data);
|
||||
} else {
|
||||
|
||||
$manjian_id = input('manjian_id', 0);
|
||||
$this->assign('manjian_id', $manjian_id);
|
||||
|
||||
$manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
|
||||
if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', href_url('manjian://shop/manjian/lists'));
|
||||
$this->assign('manjian_info', $manjian_info[ 'data' ]);
|
||||
//获取优惠券列表
|
||||
$coupon_model = new CouponType();
|
||||
$condition = [
|
||||
[ 'status', '=', 1 ],
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
];
|
||||
//优惠券字段
|
||||
$coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time,goods_type,max_fetch';
|
||||
$coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
|
||||
$this->assign('coupon_list', $coupon_list);
|
||||
$this->assign('level_time', $member_level_model->level_time);
|
||||
return $this->fetch("manjian/edit");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减详情
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$manjian_id = input('manjian_id', 0);
|
||||
$manjian_model = new ManjianModel();
|
||||
$manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
|
||||
if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', href_url('manjian://shop/manjian/lists'));
|
||||
$this->assign('manjian_info', $manjian_info[ 'data' ]);
|
||||
return $this->fetch('manjian/detail');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减关闭
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$manjian_id = input('manjian_id', 0);
|
||||
$manjian_model = new ManjianModel();
|
||||
return $manjian_model->closeManjian($manjian_id, $this->site_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减删除
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$manjian_id = input('manjian_id', 0);
|
||||
$manjian_model = new ManjianModel();
|
||||
return $manjian_model->deleteManjian($manjian_id, $this->site_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动冲突商品
|
||||
*/
|
||||
public function conflict()
|
||||
{
|
||||
$key = input('key', '');
|
||||
$conflict_data = Cache::get($key);
|
||||
$this->assign('conflict_data', $conflict_data);
|
||||
return $this->fetch('manjian/conflict');
|
||||
}
|
||||
}
|
||||
452
addon/manjian/shop/view/manjian/add.html
Executable file
452
addon/manjian/shop/view/manjian/add.html
Executable file
@@ -0,0 +1,452 @@
|
||||
<style>
|
||||
.discount { display: flex; justify-content: space-between; height: 34px; line-height: 34px; padding: 5px 15px; background-color: #F6FBFD; border: 1px dashed #BCE8F1; }
|
||||
.manjian-rule .level-head{display: flex;justify-content: space-between;background: #eee;padding: 0 10px;margin-bottom: 15px;}
|
||||
.manjian-rule .title { color: #454545;font-weight: 600; }
|
||||
.manjian-rule .wrap .layui-form-label { width: 140px; }
|
||||
.manjian-rule .wrap .layui-form-label + .layui-input-block { margin-left: 140px }
|
||||
.manjian-rule .wrap .layui-form-checkbox[lay-skin=primary] {margin-top: 0}
|
||||
.manjian-rule .wrap .discount-cont {padding-left: 28px;min-height: 36px}
|
||||
.manjian-rule .discount-item .word-aux {margin-left: 0}
|
||||
.layui-form-item .layui-input-inline.end-time{float: none;}
|
||||
.layui-table-body{max-height: 480px !important;}
|
||||
.goods-title{display: flex;align-items: center;}
|
||||
.goods-title .goods-img{display: flex;align-items: center;justify-content: center;width: 55px;height: 55px;margin-right: 5px;}
|
||||
.goods-title .goods-img img{max-height: 100%;max-width: 100%;}
|
||||
.goods-title .goods-name{flex: 1;line-height: 1.6;}
|
||||
.select-coupon-layer .layui-layer-content{ overflow-y: scroll!important; }
|
||||
.goods-item{height: 325px;overflow: hidden;display: block;overflow-y: auto;}
|
||||
.table-title-name{width: 100px ; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;margin-right: 135px!important;}
|
||||
.coupon-end-time{padding-right: 63px !important;}
|
||||
.word-aux{margin-left: 200px;margin-top: 0}
|
||||
.goods_num {padding-left: 20px;}
|
||||
</style>
|
||||
|
||||
<div class="layui-form form-wrap">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>活动名称:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="manjian_name" lay-verify="required|len" class="layui-input len-long" autocomplete="off" maxlength="40">
|
||||
</div>
|
||||
|
||||
<div class="word-aux">
|
||||
<p>活动名称最多为25个字符</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>活动时间:</label>
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline len-mid">
|
||||
<input type="text" class="layui-input" name="start_time" lay-verify="required" id="start_time" autocomplete="off" readonly>
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
<span class="layui-form-mid">-</span>
|
||||
<div class="layui-input-inline len-mid end-time">
|
||||
<input type="text" class="layui-input" name="end_time" lay-verify="required|time" id="end_time" autocomplete="off" readonly>
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>条件类型:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="type" lay-filter="type" value="0" title="满N元" checked>
|
||||
<input type="radio" name="type" lay-filter="type" value="1" title="满N件">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-form manjian-rule">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠设置:</label>
|
||||
|
||||
<div class="layui-input-block discount-level">
|
||||
<div class="level-item">
|
||||
<div class="level-head">
|
||||
<label class="title">活动层级1:</label>
|
||||
</div>
|
||||
<div class="wrap">
|
||||
<div class="condition">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠门槛:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="type-0">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="money" value="" lay-verify="manjian_money" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
<div class="type-1 layui-hide">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="num" value="" lay-verify="manjian_num" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">件</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠内容:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="discount-item discount-money">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="discount_money" class="input-checkbox" lay-skin="primary"><span>订单金额优惠</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div class="layui-form-mid">减</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" value="" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item">
|
||||
<div>
|
||||
<input type="checkbox" name="" value="free_shipping" class="input-checkbox" lay-skin="primary"><span>包邮</span>
|
||||
</div>
|
||||
<div class="word-aux" >
|
||||
<p>仅参与该活动的商品包邮,非整单包邮</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item point">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="point" class="input-checkbox" lay-skin="primary"><span>送积分</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div class="layui-form-mid">送</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="" value="" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">积分</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item coupon">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="coupon" class="input-checkbox" lay-skin="primary"><span>送优惠券</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div><a href="javascript:;" class="text-color select-coupon">选择优惠券</a></div>
|
||||
<div class="word-aux">
|
||||
<p>请确认优惠券数量是否充足,优惠券数量不足将导致赠送失败</p>
|
||||
</div>
|
||||
<div>
|
||||
<table class="layui-table" lay-skin="nob">
|
||||
<colgroup>
|
||||
<col width="30%">
|
||||
<col width="30%">
|
||||
<col width="20%">
|
||||
<col width="20%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>优惠券</th>
|
||||
<th>优惠内容</th>
|
||||
<th>赠券数 <i title="每人每次参加该活动赠送的优惠券数量" class="iconfont iconwenhao1"></i> </th>
|
||||
<th style="text-align:center;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" onclick="addDiscountLevel()">添加活动层级</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>活动商品:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="manjian_type" lay-filter="manjian_type" value="1" title="全部商品参与" checked>
|
||||
<input type="radio" name="manjian_type" lay-filter="manjian_type" value="2" title="指定商品参与">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item goods_list" style="display:none">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<table id="selected_goods_list"></table>
|
||||
<button class="layui-btn" onclick="addGoods()">选择商品</button> <span class="goods_num">已选商品(<span id="goods_num" class="text-color">0</span>)</span>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="goods_ids" lay-verify="goods_num">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">备注:</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="remark" class="layui-textarea len-long" maxlength="150"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">提交</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="backManjianList()">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作 -->
|
||||
<script type="text/html" id="operation">
|
||||
<div class="table-btn">
|
||||
<a class="layui-btn" onclick="delGoods({{d.goods_id}})">删除</a>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="MANJIAN_JS/add.js"></script>
|
||||
|
||||
<!-- 优惠券 -->
|
||||
<script type="text/html" id="couponList">
|
||||
<div class="coupon-box">
|
||||
<div class="single-filter-box">
|
||||
<div class="layui-form">
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="coupon_name" placeholder="请输入优惠券名称" class="layui-input">
|
||||
<button type="button" class="layui-btn layui-btn-primary" lay-filter="coupon-search" lay-submit>
|
||||
<i class="layui-icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gods-box">
|
||||
<table class="layui-table" lay-skin="line" lay-size="lg">
|
||||
<colgroup>
|
||||
<col width="8%">
|
||||
<col width="50%">
|
||||
<col width="15%">
|
||||
<col width="27%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="check-box">
|
||||
<div class="layui-form">
|
||||
<input type="checkbox" name="" lay-filter="selectAll" lay-skin="primary">
|
||||
</div>
|
||||
</th>
|
||||
<th class="layui-elip">优惠券名称</th>
|
||||
<th class="layui-elip">优惠金额/折扣</th>
|
||||
<th class="layui-elip">结束时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<table class="layui-table" id="goods" lay-skin="line" lay-size="lg">
|
||||
<!-- <colgroup>
|
||||
<col width="8%">
|
||||
<col width="50%">
|
||||
<col width="15%">
|
||||
<col width="27%">
|
||||
</colgroup> -->
|
||||
<tbody class="goods-item">
|
||||
{foreach $coupon_list.data as $coupon_list_k => $coupon_list_v}
|
||||
<tr>
|
||||
<td class="check-box">
|
||||
<div class="layui-form">
|
||||
{{# var a = {$coupon_list_v.coupon_type_id} }}
|
||||
{{# if($.inArray(a.toString(), d.coupon_id) != -1){ }}
|
||||
<input type="checkbox" name="" lay-filter="select{$coupon_list_k}" lay-skin="primary" checked>
|
||||
{{# }else{ }}
|
||||
<input type="checkbox" name="" lay-filter="select{$coupon_list_k}" lay-skin="primary">
|
||||
{{# } }}
|
||||
<input type="hidden" id="coupon_id" value="{$coupon_list_v.coupon_type_id}">
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-title">
|
||||
<div class="title-pic">
|
||||
{if condition="$coupon_list_v.image"}
|
||||
<img src="{:img($coupon_list_v.image)}">
|
||||
{else/}
|
||||
<img src="__ROOT__/public/uniapp/game/coupon.png">
|
||||
{/if}
|
||||
</div>
|
||||
<div class="title-content table-title-name">
|
||||
<p class="multi-line-hiding">{$coupon_list_v.coupon_name}</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
{if $coupon_list_v.type == 'reward'}
|
||||
<td class="layui-elip coupon-money">{$coupon_list_v.money}元</td>
|
||||
{else/}
|
||||
<td class="layui-elip coupon-money">{$coupon_list_v.discount}折</td>
|
||||
{/if}
|
||||
{if $coupon_list_v.validity_type == 0}
|
||||
<td class="layui-elip coupon-end-time">{:time_to_date($coupon_list_v.end_time)}</td>
|
||||
{elseif $coupon_list_v.validity_type == 1}
|
||||
<td class="layui-elip coupon-end-time">领取之日起{$coupon_list_v.fixed_term}天有效</td>
|
||||
{else/}
|
||||
<td class="layui-elip coupon-end-time">长期有效</td>
|
||||
{/if}
|
||||
<input type="hidden" name="at_least" value="{$coupon_list_v.at_least}">
|
||||
<input type="hidden" name="type" value="{$coupon_list_v.type}">
|
||||
<input type="hidden" name="discount" value="{$coupon_list_v.discount}">
|
||||
<input type="hidden" name="money" value="{$coupon_list_v.money}">
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button class="layui-btn" onclick="couponSelected()">确定</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 优惠券 -->
|
||||
<script type="text/html" id="couponListSearch">
|
||||
<div class="coupon-box">
|
||||
<div class="single-filter-box">
|
||||
<div class="layui-form">
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="coupon_name" placeholder="请输入优惠券名称" class="layui-input">
|
||||
<button type="button" class="layui-btn layui-btn-primary" lay-filter="coupon-search" lay-submit>
|
||||
<i class="layui-icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gods-box">
|
||||
<table class="layui-table" lay-skin="line" lay-size="lg">
|
||||
<colgroup>
|
||||
<col width="8%">
|
||||
<col width="50%">
|
||||
<col width="15%">
|
||||
<col width="27%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="check-box">
|
||||
<div class="layui-form">
|
||||
<input type="checkbox" name="" lay-filter="selectAll" lay-skin="primary">
|
||||
</div>
|
||||
</th>
|
||||
<th class="layui-elip">优惠券名称</th>
|
||||
<th class="layui-elip">优惠金额/折扣</th>
|
||||
<th class="layui-elip">结束时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<table class="layui-table" id="goods" lay-skin="line" lay-size="lg">
|
||||
<!-- <colgroup>
|
||||
<col width="8%">
|
||||
<col width="50%">
|
||||
<col width="15%">
|
||||
<col width="27%">
|
||||
</colgroup> -->
|
||||
<tbody class="goods-item">
|
||||
|
||||
{{# layui.each(d.list, function(index, item){ }}
|
||||
<tr>
|
||||
<td class="check-box">
|
||||
<div class="layui-form">
|
||||
{{# var a = item.coupon_type_id }}
|
||||
{{# if($.inArray(a.toString(), d.coupon_id) != -1){ }}
|
||||
<input type="checkbox" name="" lay-filter="select{{item.index}}" lay-skin="primary" checked>
|
||||
{{# }else{ }}
|
||||
<input type="checkbox" name="" lay-filter="select{{item.index}}" lay-skin="primary">
|
||||
{{# } }}
|
||||
<input type="hidden" id="coupon_id" value="{{item.coupon_type_id}}">
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-title">
|
||||
<div class="title-pic">
|
||||
{{#if(item.image) { }}
|
||||
<img src="{{item.image}}">
|
||||
{{# }else{ }}
|
||||
<img src="__ROOT__/public/uniapp/game/coupon.png">
|
||||
{{# } }}
|
||||
</div>
|
||||
<div class="title-content table-title-name">
|
||||
<p class="multi-line-hiding">{{item.coupon_name}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
{{#if(item.type == 'reward') { }}
|
||||
<td class="layui-elip coupon-money">{{item.money}}元</td>
|
||||
{{# }else{ }}
|
||||
<td class="layui-elip coupon-money">{{item.discount}}折</td>
|
||||
{{# } }}
|
||||
{{#if(item.validity_type == 0) { }}
|
||||
|
||||
<td class="layui-elip coupon-end-time">{{layui.util.toDateString(item.end_time * 1000,'yyyy-MM-dd HH:mm:ss')}}</td>
|
||||
{{# }else{ }}
|
||||
<td class="layui-elip coupon-end-time">领取之日起{{item.fixed_term}}天有效</td>
|
||||
{{# } }}
|
||||
<input type="hidden" name="at_least" value="{{item.at_least}}">
|
||||
<input type="hidden" name="type" value="{{item.type}}">
|
||||
<input type="hidden" name="discount" value="{{item.discount}}">
|
||||
<input type="hidden" name="money" value="{{item.money}}">
|
||||
</tr>
|
||||
{{# }); }}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button class="layui-btn" onclick="couponSelected()">确定</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 优惠券-名称 -->
|
||||
<script type="text/html" id="couponName">
|
||||
<div class="table-tuwen-box">
|
||||
<div class="font-box">
|
||||
<p class="multi-line-hiding">{{d.coupon_name}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 优惠券-操作 -->
|
||||
<script type="text/html" id="couponOperation">
|
||||
|
||||
{{# var select_coupon_list = ','+coupon_list+','}}
|
||||
|
||||
{{# if(select_coupon_list.indexOf(','+d.coupon_type_id+',') != -1){ }}
|
||||
<p title="该优惠券已参加">已添加</p>
|
||||
{{# }else{ }}
|
||||
<a class="layui-btn" lay-event="add">添加</a>
|
||||
{{# } }}
|
||||
|
||||
</script>
|
||||
<!-- 批量操作 -->
|
||||
<script type="text/html" id="batchOperation">
|
||||
<button class="layui-btn layui-btn-primary" lay-event="add">批量添加</button>
|
||||
</script>
|
||||
<script type="text/html" id="addCoupon">
|
||||
{{# for(var i = 0; i < d.length; i++){ }}
|
||||
<tr data-coupon="{{ d[i].coupon_type_id }}">
|
||||
<td>{{d[i].coupon_name}}</td>
|
||||
{{# if(d[i].at_least > 0){}}
|
||||
<td>满{{d[i].at_least}}{{d[i].type == 'discount' ? '打'+ d[i].discount +'折' : '减' + d[i].money}}</td>
|
||||
{{#} else {}}
|
||||
<td>无门槛,{{d[i].type == 'discount' ? '打'+ d[i].discount +'折' : '减' + d[i].money}}</td>
|
||||
{{#}}}
|
||||
<td><input type="number" name="number" value="1" class="layui-input len-short" lay-verify="coupon_num"></td>
|
||||
<td style="text-align:center;">
|
||||
<a href="javascript:;" onClick="deleteCoupon(this, {{i}})" className="text-color">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{# } }}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['carousel'], function() {
|
||||
var carousel = layui.carousel;
|
||||
carousel.render({
|
||||
elem: '#carousel'
|
||||
, width: '100%' //设置容器宽度
|
||||
, arrow: 'always' //始终显示箭头
|
||||
});
|
||||
})
|
||||
</script>
|
||||
57
addon/manjian/shop/view/manjian/conflict.html
Executable file
57
addon/manjian/shop/view/manjian/conflict.html
Executable file
@@ -0,0 +1,57 @@
|
||||
{if $conflict_data.type == 'goods'}
|
||||
<div class="detail-card tips-wrap">
|
||||
<div class="detail-con">
|
||||
<p class="detail-line">同一活动时间内,同一个商品只可参加一个满减活动,当前活动中有<span class="conflict-num red-color"></span>件商品与以下商品冲突</p>
|
||||
<p class="detail-line">活动类型:{$conflict_data.promotion}</p>
|
||||
<p class="detail-line">当前活动时间:{:time_to_date($conflict_data.start_time)} - {:time_to_date($conflict_data.end_time)}</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if $conflict_data.type == 'activity'}
|
||||
<div class="detail-card tips-wrap">
|
||||
<div class="detail-con">
|
||||
<p class="detail-line">同一活动时间内,同一个店铺只能同时存在一个全选商品的满减/送活动</p>
|
||||
<p class="detail-line">当前活动与以下<span class="conflict-num red-color"></span>个活动存在冲突</p>
|
||||
<p class="detail-line">当前活动时间:{:time_to_date($conflict_data.start_time)} - {:time_to_date($conflict_data.end_time)}</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<table id="goods_list"></table>
|
||||
|
||||
<script>
|
||||
layui.use(['form'], function() {
|
||||
var table,form = layui.form;
|
||||
form.render();
|
||||
|
||||
var list = {:json_encode($conflict_data.list, JSON_UNESCAPED_UNICODE)};
|
||||
$(".conflict-num").text(list.length);
|
||||
|
||||
table = new Table({
|
||||
elem: '#goods_list',
|
||||
cols: [
|
||||
[
|
||||
{if $conflict_data.type == 'goods'}
|
||||
{
|
||||
field: 'goods_name',
|
||||
title: '商品名称',
|
||||
unresize: 'false',
|
||||
},
|
||||
{/if}
|
||||
{
|
||||
field: 'manjian_name',
|
||||
title: '活动名称',
|
||||
unresize: 'false',
|
||||
}, {
|
||||
title: '活动时间',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
return ns.time_to_date(data.start_time) +'至'+ ns.time_to_date(data.end_time);
|
||||
}
|
||||
}]
|
||||
],
|
||||
data: list
|
||||
});
|
||||
});
|
||||
</script>
|
||||
114
addon/manjian/shop/view/manjian/detail.html
Executable file
114
addon/manjian/shop/view/manjian/detail.html
Executable file
@@ -0,0 +1,114 @@
|
||||
<link rel="stylesheet" href="STATIC_CSS/promotion_detail.css">
|
||||
<style>
|
||||
.discount { justify-content: space-between;line-height: 30px;padding: 0px 15px;background-color: #F6FBFD;border: 1px dashed #BCE8F1; margin-bottom: 5px;}
|
||||
</style>
|
||||
|
||||
<div class="layui-card card-common card-brief">
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">基本信息</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
<div class="promotion-view">
|
||||
<div class="promotion-view-item">
|
||||
<label>活动名称:</label>
|
||||
<span>{$manjian_info.manjian_name}</span>
|
||||
</div>
|
||||
<div class="promotion-view-item">
|
||||
<label>开始时间:</label>
|
||||
<span>{:date('Y-m-d H:i:s',$manjian_info.start_time)}</span>
|
||||
</div>
|
||||
<div class="promotion-view-item">
|
||||
<label>结束时间:</label>
|
||||
<span>{:date('Y-m-d H:i:s',$manjian_info.end_time)}</span>
|
||||
</div>
|
||||
{if $manjian_info.manjian_type == 1}
|
||||
<div class="promotion-view-item">
|
||||
<label>活动商品:</label>
|
||||
<span>全部商品参与</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="promotion-view">
|
||||
<div class="promotion-view-item-line">
|
||||
<label class="promotion-view-item-custom-label">满减规则:</label>
|
||||
<div class="promotion-view-item-custom-box">
|
||||
<div class="discount-box">
|
||||
{foreach name="$manjian_info.rule" item="vo"}
|
||||
<div class="discount">
|
||||
<div class="discount-con">
|
||||
<p>单笔订单满
|
||||
{if $manjian_info.type == 0}
|
||||
<span class="red-color money-num">{:sprintf('%.2f', $vo.limit)}</span>元
|
||||
{else/}
|
||||
<span class="red-color money-num">{:number_format($vo.limit)}</span>件
|
||||
{/if}
|
||||
{if isset($vo.discount_money)},减{$vo.discount_money}元 {/if}
|
||||
{if isset($vo.free_shipping)},包邮 {/if}
|
||||
{if isset($vo.point)},送{$vo.point}积分 {/if}
|
||||
{if isset($vo.coupon)}
|
||||
{foreach name="$vo.coupon_data" item="coupon"}
|
||||
,送优惠券<a href="{:href_url('coupon://shop/coupon/detail', ['coupon_type_id' => $coupon.coupon_type_id ])}" target="_blank">【{$coupon.coupon_name}】</a>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{if $manjian_info.manjian_type != 1}
|
||||
<div class="layui-card card-common card-brief">
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">活动商品</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
<div class='promotion-view-list'>
|
||||
<table id="promotion_list"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<script type='text/html' id="promotion_list_item_box_html">
|
||||
<div class="promotion-list-item-title">
|
||||
<div class="promotion-list-item-title-icon">
|
||||
<img src="{{ d.goods_image ? ns.img(d.goods_image.split(",")[0],'small') : '' }}" alt="">
|
||||
</div>
|
||||
<p class="promotion-list-item-title-name multi-line-hiding">{{ d.goods_name }}</p>
|
||||
</div>
|
||||
</script>
|
||||
<script>
|
||||
var promotion_list = {:json_encode($manjian_info.goods_list, JSON_UNESCAPED_UNICODE)};
|
||||
|
||||
layui.use('table', function() {
|
||||
|
||||
new Table({
|
||||
elem: '#promotion_list',
|
||||
page: false,
|
||||
limit: Number.MAX_VALUE,
|
||||
cols: [
|
||||
[{
|
||||
field: 'goods_name',
|
||||
title: '商品名称',
|
||||
unresize: 'false',
|
||||
width: '60%',
|
||||
templet: "#promotion_list_item_box_html"
|
||||
}, {
|
||||
field: 'price',
|
||||
title: '商品价格(元)',
|
||||
unresize: 'false',
|
||||
align: 'right',
|
||||
width: '40%',
|
||||
templet: function(data) {
|
||||
return '¥' + data.price;
|
||||
}
|
||||
}],
|
||||
],
|
||||
data: promotion_list,
|
||||
});
|
||||
});
|
||||
</script>
|
||||
433
addon/manjian/shop/view/manjian/edit.html
Executable file
433
addon/manjian/shop/view/manjian/edit.html
Executable file
@@ -0,0 +1,433 @@
|
||||
<style>
|
||||
.discount { display: flex; justify-content: space-between; height: 34px; line-height: 34px; padding: 5px 15px; background-color: #F6FBFD; border: 1px dashed #BCE8F1; }
|
||||
.manjian-rule .level-head{display: flex;justify-content: space-between;background: #eee;padding: 0 10px;margin-bottom: 15px;}
|
||||
.manjian-rule .title { color: #454545;font-weight: 600; }
|
||||
.manjian-rule .wrap .layui-form-label { width: 140px; }
|
||||
.manjian-rule .wrap .layui-form-label + .layui-input-block { margin-left: 140px }
|
||||
.manjian-rule .wrap .layui-form-checkbox[lay-skin=primary] {margin-top: 0}
|
||||
.manjian-rule .wrap .discount-cont {padding-left: 28px;min-height: 36px}
|
||||
.manjian-rule .discount-item .word-aux {margin-left: 0}
|
||||
.layui-form-item .layui-input-inline.end-time{float: none;}
|
||||
.layui-table-body{max-height: 480px !important;}
|
||||
.goods-title{display: flex;align-items: center;}
|
||||
.goods-title .goods-img{display: flex;align-items: center;justify-content: center;width: 55px;height: 55px;margin-right: 5px;}
|
||||
.goods-title .goods-img img{max-height: 100%;max-width: 100%;}
|
||||
.goods-title .goods-name{flex: 1;line-height: 1.6;}
|
||||
.select-coupon-layer .layui-layer-content{ overflow-y: scroll!important; }
|
||||
.word-aux{margin-left: 200px;margin-top: 0}
|
||||
.goods_num {padding-left: 20px;}
|
||||
.goods-item{height: 325px;overflow: hidden;display: block;overflow: hidden;overflow-y: auto;}
|
||||
.table-title-name{width: 100px ; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;margin-right: 135px!important;}
|
||||
</style>
|
||||
|
||||
<div class="layui-form form-wrap">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>活动名称:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="manjian_name" lay-verify="required|len" value="{$manjian_info.manjian_name}" placeholder="请输入活动名称" class="layui-input len-long" autocomplete="off" maxlength="40">
|
||||
</div>
|
||||
<div class="word-aux">
|
||||
<p>活动名称最多为25个字符</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>活动时间:</label>
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline len-mid">
|
||||
<input type="text" value="{:date('Y-m-d H:i:s', $manjian_info.start_time)}" class="layui-input" name="start_time" lay-verify="required" id="start_time" autocomplete="off" readonly>
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
<span class="layui-form-mid">-</span>
|
||||
<div class="layui-input-inline len-mid end-time">
|
||||
<!-- <input type="text" {if condition="$manjian_info.status == 1"}disabled {/if} value="{:date('Y-m-d H:i:s', $manjian_info.end_time)}" class="layui-input" name="end_time" lay-verify="required|times" id="end_time" autocomplete="off" readonly> -->
|
||||
<input type="text" value="{:date('Y-m-d H:i:s', $manjian_info.end_time)}" class="layui-input" name="end_time" lay-verify="required|times" id="end_time" autocomplete="off" readonly>
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
</div>
|
||||
<!-- {if condition="$manjian_info.status == 1"}
|
||||
<div class="word-aux">
|
||||
<p>活动进行中时间不可更改</p>
|
||||
</div>
|
||||
{/if} -->
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>条件类型:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="type" lay-filter="type" value="0" title="满N元" {if $manjian_info.type == 0}checked{/if}>
|
||||
<input type="radio" name="type" lay-filter="type" value="1" title="满N件" {if $manjian_info.type == 1}checked{/if}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-form manjian-rule">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠设置:</label>
|
||||
|
||||
<div class="layui-input-block discount-level">
|
||||
{foreach name="$manjian_info.rule" item="vo" index="k"}
|
||||
<div class="level-item">
|
||||
<div class="level-head">
|
||||
<label class="title">活动层级{$k}:</label>
|
||||
{if $k > 1}<a href="javascript:;" class="text-color" onclick="deleteLevel(this)">删除</a>{/if}
|
||||
</div>
|
||||
<div class="wrap">
|
||||
<div class="condition">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠门槛:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="type-0 {if $manjian_info.type != 0}layui-hide{/if}">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="money" value="{:sprintf('%.2f',$vo.limit)}" lay-verify="manjian_money" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
<div class="type-1 {if $manjian_info.type != 1}layui-hide{/if}">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="num" value="{:number_format($vo.limit)}" lay-verify="manjian_num" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">件</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠内容:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="discount-item discount-money">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="discount_money" class="input-checkbox" lay-skin="primary" {if isset($vo.discount_money)}checked{/if}><span>订单金额优惠</span>
|
||||
</div>
|
||||
<div class="discount-cont {if !isset($vo.discount_money)}layui-hide{/if}">
|
||||
<div class="layui-form-mid">减</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" value="{if isset($vo.discount_money)}{$vo.discount_money}{/if}" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item">
|
||||
<div>
|
||||
<input type="checkbox" name="" value="free_shipping" class="input-checkbox" lay-skin="primary" {if isset($vo.free_shipping)}checked{/if}><span>包邮</span>
|
||||
</div>
|
||||
<div class="word-aux" >
|
||||
<p>仅参与该活动的商品包邮,非整单包邮</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item point">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="point" class="input-checkbox" lay-skin="primary" {if isset($vo.point)}checked{/if}><span>送积分</span>
|
||||
</div>
|
||||
<div class="discount-cont {if !isset($vo.point)}layui-hide{/if}">
|
||||
<div class="layui-form-mid">送</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="" value="{if isset($vo.point)}{$vo.point}{/if}" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">积分</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item coupon">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="coupon" class="input-checkbox" lay-skin="primary" {if isset($vo.coupon)}checked{/if}><span>送优惠券</span>
|
||||
</div>
|
||||
<div class="discount-cont {if !isset($vo.coupon)}layui-hide{/if}">
|
||||
<div><a href="javascript:;" class="text-color select-coupon">选择优惠券</a></div>
|
||||
<div class="word-aux">
|
||||
<p>请确认优惠券数量是否充足,优惠券数量不足将导致赠送失败</p>
|
||||
</div>
|
||||
<div>
|
||||
<table class="layui-table" lay-skin="nob">
|
||||
<colgroup>
|
||||
<col width="30%">
|
||||
<col width="30%">
|
||||
<col width="20%">
|
||||
<col width="20%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="layui-elip">优惠券名称</th>
|
||||
<th class="layui-elip">优惠内容</th>
|
||||
<th class="layui-elip">赠券数</th>
|
||||
<th style="text-align:center;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{if isset($vo.coupon) && isset($vo.coupon_data) && !empty($vo.coupon_data)}
|
||||
{foreach name="$vo.coupon_data" item="coupon_data" key="kk"}
|
||||
<tr data-coupon="{$coupon_data.coupon_type_id}">
|
||||
<td>{$coupon_data.coupon_name }</td>
|
||||
{if $coupon_data.at_least > 0 }
|
||||
<td>满{$coupon_data.at_least }{$coupon_data.type == 'discount' ? '打'. $coupon_data.discount .'折' : '减' . $coupon_data.money }</td>
|
||||
{else/}
|
||||
<td>无门槛,{$coupon_data.type == 'discount' ? '打'. $coupon_data.discount .'折' : '减' . $coupon_data.money }</td>
|
||||
{/if}
|
||||
<td><input type="number" name="number" value="{$vo['coupon_num'][$kk] ?? 1}" class="layui-input len-short"></td>
|
||||
<td style="text-align:center;"><a href="javascript:;" onclick="deleteCoupon(this)" class="text-color">删除</a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" onclick="addDiscountLevel()">添加活动层级</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="layui-form-item">
|
||||
<div class="layui-form">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">满减规则:</label>
|
||||
|
||||
<div class="discount-box">
|
||||
</div>
|
||||
|
||||
<div class="layui-input-block form-row">
|
||||
<span class="layui-form-mid">单笔订单满</span>
|
||||
<div class="layui-input-inline">
|
||||
<input type="number" class="layui-input len-short" id="money" lay-verify="num" autocomplete="off">
|
||||
</div>
|
||||
<span class="layui-form-mid">元,立减现金</span>
|
||||
<div class="layui-input-inline">
|
||||
<input type="number" class="layui-input len-short" id="discount_money" lay-verify="num" autocomplete="off">
|
||||
</div>
|
||||
<span class="layui-form-mid">元</span>
|
||||
</div>
|
||||
|
||||
<div class="word-aux">
|
||||
<p>价格不能小于0,可保留两位小数</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" onclick="submitRule()">确定规则设置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>活动商品:</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="manjian_type" lay-filter="manjian_type" lay-verify="required|manjian_type" value="1" title="全部商品参与" {if $manjian_info.manjian_type == 1} checked {/if}>
|
||||
<input type="radio" name="manjian_type" lay-filter="manjian_type" lay-verify="required|manjian_type" value="2" title="指定商品参与" {if $manjian_info.manjian_type == 2} checked {/if}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if $manjian_info.manjian_type == 1}
|
||||
<div class="layui-form-item goods_list" style="display:none">
|
||||
{else /}
|
||||
<div class="layui-form-item goods_list">
|
||||
{/if}
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<!-- <table class="layui-table" id="goods" lay-skin="line" lay-size="lg">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>商品名称</th>
|
||||
<th>商品价格(元)</th>
|
||||
<th>库存</th>
|
||||
<th>编辑</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{if empty($manjian_info.goods_list)}
|
||||
<tr>
|
||||
<td class="goods-empty" colspan="3">
|
||||
<div>该活动还未选择商品</div>
|
||||
</td>
|
||||
</tr>
|
||||
{else /}
|
||||
{foreach $manjian_info.goods_list as $v}
|
||||
<tr data-sku_id="{$v.goods_id}">
|
||||
<td>{$v.goods_name}</td>
|
||||
<td>{$v.price}</td>
|
||||
<td>{$v.goods_stock}</td>
|
||||
<td><button class="layui-btn" onclick="delRule(this)">删除</button></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</tbody>
|
||||
</table> -->
|
||||
<table id="selected_sku_list"></table>
|
||||
|
||||
<button class="layui-btn" onclick="addGoods()">选择商品</button> <span class="goods_num">已选商品(<span id="goods_num" class="text-color">{$manjian_info.goods_list_count}</span>)</span>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="goods_ids" lay-verify="goods_num" value = '{$manjian_info.goods_list_count}'>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">备注:</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="remark" class="layui-textarea len-long" maxlength="150">{$manjian_info.remark}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="backManjianList()">返回</button>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="manjian_id" value="{$manjian_info.manjian_id}" />
|
||||
<input type="hidden" name="rule_json" value='{$manjian_info.rule_json}' id="rule_json" />
|
||||
</div>
|
||||
|
||||
<!-- 操作 -->
|
||||
<script type="text/html" id="operation">
|
||||
<div class="table-btn">
|
||||
<a class="layui-btn" onclick="delGoods({{d.goods_id}})">删除</a>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var goods_list = {:json_encode($manjian_info.goods_list, JSON_UNESCAPED_UNICODE)};
|
||||
var coupon_list = {:json_encode($coupon_list.data, JSON_UNESCAPED_UNICODE)};
|
||||
var manjian_info = {:json_encode($manjian_info.rule, JSON_UNESCAPED_UNICODE)};
|
||||
</script>
|
||||
<script type="text/javascript" src="MANJIAN_JS/edit.js"></script>
|
||||
|
||||
<!-- 优惠券 -->
|
||||
<script type="text/html" id="couponList">
|
||||
<div class="coupon-box">
|
||||
<div class="single-filter-box">
|
||||
<div class="layui-form">
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="coupon_name" placeholder="请输入优惠券名称" class="layui-input">
|
||||
<button type="button" class="layui-btn layui-btn-primary" lay-filter="coupon-search" lay-submit>
|
||||
<i class="layui-icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gods-box">
|
||||
<table class="layui-table" lay-skin="line" lay-size="lg">
|
||||
<colgroup>
|
||||
<col width="8%">
|
||||
<col width="50%">
|
||||
<col width="15%">
|
||||
<col width="27%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="check-box">
|
||||
<div class="layui-form">
|
||||
<input type="checkbox" name="" lay-filter="selectAll" lay-skin="primary">
|
||||
</div>
|
||||
</th>
|
||||
<th class="layui-elip">优惠券名称</th>
|
||||
<th class="layui-elip">优惠金额/折扣</th>
|
||||
<th class="layui-elip">结束时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<table class="layui-table" id="goods" lay-skin="line" lay-size="lg">
|
||||
<colgroup>
|
||||
<col width="8%">
|
||||
<col width="50%">
|
||||
<col width="15%">
|
||||
<col width="27%">
|
||||
</colgroup>
|
||||
<tbody class="goods-item">
|
||||
{foreach $coupon_list.data as $coupon_list_k => $coupon_list_v}
|
||||
<tr>
|
||||
<td class="check-box">
|
||||
|
||||
<div class="layui-form">
|
||||
{{# var a = {$coupon_list_v.coupon_type_id} }}
|
||||
{{# if($.inArray(a, d.coupon_id) != -1){ }}
|
||||
<input type="checkbox" name="" lay-filter="select{$coupon_list_k}" lay-skin="primary" checked>
|
||||
{{# }else{ }}
|
||||
<input type="checkbox" name="" lay-filter="select{$coupon_list_k}" lay-skin="primary">
|
||||
{{# } }}
|
||||
<input type="hidden" id="coupon_id" value="{$coupon_list_v.coupon_type_id}">
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-title">
|
||||
<div class="title-pic">
|
||||
{if condition="$coupon_list_v.image"}
|
||||
<img src="{:img($coupon_list_v.image)}">
|
||||
{else/}
|
||||
<img src="__ROOT__/public/uniapp/game/coupon.png">
|
||||
{/if}
|
||||
</div>
|
||||
<div class="title-content table-title-name">
|
||||
<p class="multi-line-hiding">{$coupon_list_v.coupon_name}</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
{if $coupon_list_v.type == 'reward'}
|
||||
<td class="layui-elip coupon-money">{$coupon_list_v.money}元</td>
|
||||
{else/}
|
||||
<td class="layui-elip coupon-money">{$coupon_list_v.discount}折</td>
|
||||
{/if}
|
||||
{if $coupon_list_v.validity_type == 0}
|
||||
<td class="layui-elip coupon-end-time">{:time_to_date($coupon_list_v.end_time)}</td>
|
||||
{elseif $coupon_list_v.validity_type == 1}
|
||||
<td class="layui-elip coupon-end-time">领取之日起{$coupon_list_v.fixed_term}天有效</td>
|
||||
{else/}
|
||||
<td class="layui-elip coupon-end-time">长期有效</td>
|
||||
{/if}
|
||||
<input type="hidden" name="at_least" value="{$coupon_list_v.at_least}">
|
||||
<input type="hidden" name="type" value="{$coupon_list_v.type}">
|
||||
<input type="hidden" name="discount" value="{$coupon_list_v.discount}">
|
||||
<input type="hidden" name="money" value="{$coupon_list_v.money}">
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button class="layui-btn" onclick="couponSelected()">确定</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 优惠券-名称 -->
|
||||
<script type="text/html" id="couponName">
|
||||
<div class="table-tuwen-box">
|
||||
<div class="font-box">
|
||||
<p class="multi-line-hiding">{{d.coupon_name}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 优惠券-操作 -->
|
||||
<script type="text/html" id="couponOperation">
|
||||
{{# if($.inArray(d.coupon_type_id, coupon_list) != -1){ }}
|
||||
<p title="该优惠券已参加积分兑换活动">已添加</p>
|
||||
{{# }else{ }}
|
||||
<a class="layui-btn" lay-event="add">添加</a>
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="addCoupon">
|
||||
{{# for(var i = 0; i < d.length; i++){ }}
|
||||
<tr data-coupon="{{ d[i].coupon_type_id }}">
|
||||
<td>{{d[i].coupon_name}}</td>
|
||||
{{# if(d[i].at_least > 0){}}
|
||||
<td>满{{d[i].at_least}}{{d[i].type == 'discount' ? '打'+ d[i].discount +'折' : '减' + d[i].money}}</td>
|
||||
{{#} else {}}
|
||||
<td>无门槛,{{d[i].type == 'discount' ? '打'+ d[i].discount +'折' : '减' + d[i].money}}</td>
|
||||
{{#}}}
|
||||
<td><input type="number" name="number" value="1" class="layui-input len-short" lay-verify="coupon_num"></td>
|
||||
<td style="text-align:center;">
|
||||
<a href="javascript:;" onClick="deleteCoupon(this, {{i}})" className="text-color">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{# } }}
|
||||
</script>
|
||||
283
addon/manjian/shop/view/manjian/lists.html
Executable file
283
addon/manjian/shop/view/manjian/lists.html
Executable file
@@ -0,0 +1,283 @@
|
||||
<style>
|
||||
.layui-layout-admin .layui-form-item .layui-input-inline{background-color: #fff;}
|
||||
.layui-layout-admin .table-tab .layui-tab-title{margin-bottom: 15px;}
|
||||
</style>
|
||||
|
||||
<div class="single-filter-box">
|
||||
<button class="layui-btn" onclick="add()">添加活动</button>
|
||||
</div>
|
||||
<!-- 搜索框 -->
|
||||
<div class="screen layui-collapse" lay-filter="selection_panel">
|
||||
<div class="layui-colla-item">
|
||||
<form class="layui-colla-content layui-form layui-show">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">活动名称:</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="manjian_name" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">活动时间:</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" class="layui-input" name="start_time" placeholder="开始时间" id="start_time" readonly>
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
<div class="layui-form-mid">-</div>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" class="layui-input" name="end_time" placeholder="结束时间" id="end_time" readonly>
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<button type="button" class="layui-btn" lay-filter="search" lay-submit>筛选</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-tab table-tab" lay-filter="manjian_tab">
|
||||
<ul class="layui-tab-title">
|
||||
<li class="layui-this" lay-id="">所有活动</li>
|
||||
<li lay-id="1">进行中</li>
|
||||
<li lay-id="2">已结束</li>
|
||||
<li lay-id="-1">已关闭</li>
|
||||
<li lay-id="0">未开始</li>
|
||||
</ul>
|
||||
<div class="layui-tab-content">
|
||||
<!-- 列表 -->
|
||||
<table id="manjian_list" lay-filter="manjian_list"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作 -->
|
||||
<script type="text/html" id="operation">
|
||||
<div class="table-btn">
|
||||
<a class="layui-btn" lay-event="detail">详情</a>
|
||||
{{# if(d.status == 0 || d.status == 1) { }}
|
||||
<a class="layui-btn" lay-event="edit">编辑</a>
|
||||
{{# } }}
|
||||
{{# if(d.status == 0) { }}
|
||||
<a class="layui-btn" lay-event="delete">删除</a>
|
||||
{{# }else if(d.status == 1) { }}
|
||||
<a class="layui-btn" lay-event="close">关闭</a>
|
||||
{{# }else if(d.status == 2 || d.status == -1) { }}
|
||||
<a class="layui-btn" lay-event="delete">删除</a>
|
||||
{{# } }}
|
||||
</div>
|
||||
</script>
|
||||
<!-- 时间 -->
|
||||
<script id="time" type="text/html">
|
||||
<div class="layui-elip">开始:{{ns.time_to_date(d.start_time)}}</div>
|
||||
<div class="layui-elip">结束:{{ns.time_to_date(d.end_time)}}</div>
|
||||
</script>
|
||||
<!-- 状态 -->
|
||||
<script type="text/html" id="status">
|
||||
{foreach $manjian_status_arr as $manjian_status_k => $manjian_status_v}
|
||||
{{# if(d.status == {$manjian_status_k}){ }}
|
||||
{$manjian_status_v}
|
||||
{{# } }}
|
||||
{/foreach}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
layui.use(['form','element','laydate'], function() {
|
||||
var table,
|
||||
form = layui.form,
|
||||
element = layui.element,
|
||||
laydate = layui.laydate,
|
||||
repeat_flag = false; //防重复标识
|
||||
form.render();
|
||||
|
||||
element.on('tab(manjian_tab)', function(){
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
where: {
|
||||
'status':this.getAttribute('lay-id')
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
table = new Table({
|
||||
elem: '#manjian_list',
|
||||
url: ns.url("manjian://shop/manjian/lists"),
|
||||
cols: [
|
||||
[{
|
||||
field: 'manjian_name',
|
||||
title: '活动名称',
|
||||
unresize: 'false',
|
||||
width: '25%'
|
||||
}, {
|
||||
title: '活动时间',
|
||||
unresize: 'false',
|
||||
width: '21%',
|
||||
templet: '#time'
|
||||
}, {
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
unresize: 'false',
|
||||
width: '13%',
|
||||
templet: '#status'
|
||||
}, {
|
||||
title: '操作',
|
||||
toolbar: '#operation',
|
||||
unresize: 'false',
|
||||
align:'right'
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听工具栏操作
|
||||
*/
|
||||
table.tool(function(obj) {
|
||||
var data = obj.data;
|
||||
switch (obj.event) {
|
||||
case 'edit': //编辑
|
||||
location.hash = ns.hash("manjian://shop/manjian/edit", {"manjian_id": data.manjian_id});
|
||||
break;
|
||||
case 'detail': //详情
|
||||
location.hash = ns.hash("manjian://shop/manjian/detail", {"manjian_id": data.manjian_id});
|
||||
break;
|
||||
case 'delete': //删除
|
||||
deleteManjian(data.manjian_id);
|
||||
break;
|
||||
case 'close': //关闭
|
||||
close(data.manjian_id);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
//开始时间
|
||||
laydate.render({
|
||||
elem: '#start_time', //指定元素
|
||||
type: 'datetime'
|
||||
});
|
||||
//结束时间
|
||||
laydate.render({
|
||||
elem: '#end_time', //指定元素
|
||||
type: 'datetime'
|
||||
});
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
function deleteManjian(manjian_id) {
|
||||
if (repeat_flag) return false;
|
||||
repeat_flag = true;
|
||||
|
||||
layer.confirm('确定要删除该满减活动吗?', function(index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
url: ns.url("manjian://shop/manjian/delete"),
|
||||
data: {
|
||||
manjian_id
|
||||
},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function(res) {
|
||||
layer.msg(res.message);
|
||||
repeat_flag = false;
|
||||
|
||||
if (res.code == 0) {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, function () {
|
||||
layer.close();
|
||||
repeat_flag = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭
|
||||
*/
|
||||
function close(manjian_id) {
|
||||
if (repeat_flag) return false;
|
||||
repeat_flag = true;
|
||||
|
||||
layer.confirm('确定关闭该活动吗?', function(index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
url: ns.url("manjian://shop/manjian/close"),
|
||||
data: {
|
||||
manjian_id
|
||||
},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function(res) {
|
||||
layer.msg(res.message);
|
||||
repeat_flag = false;
|
||||
|
||||
if (res.code == 0) {
|
||||
table.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索功能
|
||||
*/
|
||||
form.on('submit(search)', function(data) {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
where: data.field
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function add() {
|
||||
location.hash = ns.hash("manjian://shop/manjian/add");
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- 详情弹框html -->
|
||||
<script type="text/html" id="detail">
|
||||
<table class="layui-table">
|
||||
<colgroup>
|
||||
<col width="120">
|
||||
<col width="270">
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>活动名称</td>
|
||||
<td>{{d.manjian_name}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>开始时间</td>
|
||||
<td>{{ ns.time_to_date(d.start_time, "Y-m-d H:i:s") }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>结束时间</td>
|
||||
<td>{{ ns.time_to_date(d.end_time, "Y-m-d H:i:s") }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td id="rule_name">满减规则</td>
|
||||
<td id="rule">
|
||||
{{# var rule = JSON.parse(d.rule_json); }}
|
||||
{{# for(var key in rule){ }}
|
||||
<p>单笔订单满<span class="money-num">{{ rule[key].money }}</span>元,立减现金<span class="discount_money-num">{{ rule[key].discount_money }}</span>元</p>
|
||||
{{# } }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>备注</td>
|
||||
<td>{{ d.remark }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</script>
|
||||
642
addon/manjian/shop/view/public/js/add.js
Executable file
642
addon/manjian/shop/view/public/js/add.js
Executable file
@@ -0,0 +1,642 @@
|
||||
var goods_list = [], selectedGoodsId = [], goods_id=[], coupon_id = [], addCoupon, currIndex;
|
||||
|
||||
var laytpl, table, form, laydate, repeat_flag = false, //防重复标识
|
||||
currentDate = new Date(), //当前时间
|
||||
minDate = "";
|
||||
|
||||
layui.use(['form', 'laydate', 'laytpl','util'], function() {
|
||||
form = layui.form,
|
||||
laydate = layui.laydate;
|
||||
laytpl = layui.laytpl;
|
||||
util = layui.util;
|
||||
|
||||
form.render();
|
||||
renderTable(goods_list); // 初始化表格
|
||||
|
||||
currentDate.setDate(currentDate.getDate() + 30); //当前时间+30之后的时间戳
|
||||
|
||||
// 开始时间
|
||||
laydate.render({
|
||||
elem: '#start_time' ,//指定元素
|
||||
type: 'datetime',
|
||||
value: new Date(),
|
||||
done: function(value){
|
||||
minDate = value;
|
||||
reRender();
|
||||
}
|
||||
});
|
||||
|
||||
//结束时间
|
||||
laydate.render({
|
||||
elem: '#end_time' ,//指定元素
|
||||
type: 'datetime',
|
||||
value: new Date(currentDate)
|
||||
});
|
||||
|
||||
/**
|
||||
* 重新渲染结束时间
|
||||
* */
|
||||
function reRender(){
|
||||
$("#end_time").remove();
|
||||
$(".end-time").html('<input type="text" id="end_time" name="end_time" placeholder="请输入结束时间" lay-verify="required|time" class="layui-input len-mid" autocomplete="off"><i class=" iconrili iconfont calendar"></i>');
|
||||
laydate.render({
|
||||
elem: '#end_time',
|
||||
type: 'datetime',
|
||||
min: minDate
|
||||
});
|
||||
}
|
||||
|
||||
//监听活动商品类型
|
||||
form.on('radio(manjian_type)', function(data){
|
||||
var value = data.value;
|
||||
|
||||
if(value == 1){
|
||||
$(".goods_list").hide();
|
||||
}
|
||||
if(value == 2){
|
||||
$(".goods_list").show();
|
||||
}
|
||||
});
|
||||
|
||||
form.on('radio(type)', function(data){
|
||||
var value = data.value;
|
||||
$('.level-item .type-' + value).removeClass('layui-hide').siblings('div').addClass('layui-hide');
|
||||
});
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
*/
|
||||
form.verify({
|
||||
len: function(value) {
|
||||
if (value.length > 25) {
|
||||
return "活动名称最多为25个字符!";
|
||||
}
|
||||
},
|
||||
time: function(value) {
|
||||
var now_time = (new Date()).getTime();
|
||||
var start_time = (new Date($("#start_time").val())).getTime();
|
||||
var end_time = (new Date(value)).getTime();
|
||||
if (now_time > end_time) {
|
||||
return '结束时间不能小于当前时间!'
|
||||
}
|
||||
if (start_time > end_time) {
|
||||
return '结束时间不能小于开始时间!';
|
||||
}
|
||||
},
|
||||
num: function(value) {
|
||||
if (value == '') {
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
return '数字不能小于0!';
|
||||
}
|
||||
if (value * 100 % 1 != 0) {
|
||||
return '数字最多保留两位小数!';
|
||||
}
|
||||
},
|
||||
manjian_money: function(value){
|
||||
var type = $('[name="type"]:checked').val();
|
||||
if (type == 0) {
|
||||
if (!/[\S]+/.test(value)) {
|
||||
return '请输入金额';
|
||||
}
|
||||
if (value < 0) {
|
||||
return '金额不能小于0!';
|
||||
}
|
||||
}
|
||||
},
|
||||
manjian_num: function(value){
|
||||
var type = $('[name="type"]:checked').val();
|
||||
if (type == 1) {
|
||||
if (!/[\S]+/.test(value)) {
|
||||
return '请输入数量';
|
||||
}
|
||||
if (value < 0) {
|
||||
return '数量不能小于0!';
|
||||
}
|
||||
}
|
||||
},
|
||||
coupon_num: function(value){
|
||||
if (!/[\S]+/.test(value)) {
|
||||
return '请输入优惠券赠送数量';
|
||||
}
|
||||
if (value < 1) {
|
||||
return '优惠券赠送数量不能少于一张';
|
||||
}
|
||||
},
|
||||
goods_num:function (value) {
|
||||
var manjian_type = $('[name="manjian_type"]:checked').val();
|
||||
if(manjian_type == 2){
|
||||
if(value == ''){
|
||||
return '请选择活动商品!';
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听提交
|
||||
*/
|
||||
form.on('submit(save)', function(data) {
|
||||
var rule = {},
|
||||
verify = true,
|
||||
type = $('[name="type"]:checked').val();
|
||||
$('.manjian-rule .level-item').each(function(i, e) {
|
||||
var limit = parseFloat($(this).find('.type-'+ type +' .layui-input').val()).toFixed(2);
|
||||
if (i > 0) {
|
||||
var prevLimit = $('.manjian-rule .level-item:eq('+ (i - 1) +') .type-'+ type +' .layui-input').val();
|
||||
if (parseFloat(prevLimit) >= parseFloat(limit)) {
|
||||
showErrMsg('优惠门槛需大于上一级优惠门槛', $(this).find('.type-'+ type +' .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
rule[limit] = {
|
||||
limit: limit
|
||||
};
|
||||
if ($(this).find('[value="discount_money"]').is(':checked')) {
|
||||
var discount_money = $(this).find('.discount-item.discount-money .layui-input').val();
|
||||
if (!/[\S]+/.test(discount_money)) {
|
||||
showErrMsg('请输入优惠金额', $(this).find('.discount-item.discount-money .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
discount_money = parseFloat(discount_money);
|
||||
if (discount_money <= 0) {
|
||||
showErrMsg('优惠金额不能小于等于0', $(this).find('.discount-item.discount-money .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == 0 && discount_money > parseFloat(limit)) {
|
||||
showErrMsg('优惠金额请勿超出优惠门槛', $(this).find('.discount-item.discount-money .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
rule[limit].discount_money = discount_money;
|
||||
}
|
||||
|
||||
if ($(this).find('[value="free_shipping"]').is(':checked')) {
|
||||
rule[limit].free_shipping = 1;
|
||||
}
|
||||
|
||||
if ($(this).find('[value="point"]').is(':checked')) {
|
||||
var point = $(this).find('.discount-item.point .layui-input').val();
|
||||
rule[limit].point = point;
|
||||
if (!/[\S]+/.test(point)) {
|
||||
showErrMsg('请输入赠送积分数', $(this).find('.discount-item.point .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
if (point <= 0) {
|
||||
showErrMsg('赠送积分数不能小于等于0', $(this).find('.discount-item.point .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var coupon = [];
|
||||
var coupon_num = [];
|
||||
if ($(this).find('[value="coupon"]').is(':checked')) {
|
||||
|
||||
$(this).find('tr[data-coupon]').each(function (i, e) {
|
||||
coupon.push($(e).attr('data-coupon'));
|
||||
});
|
||||
$(this).find(".coupon input[name='number']").each(function(j,item){
|
||||
coupon_num.push(item.value);
|
||||
});
|
||||
if (!coupon.length) {
|
||||
showErrMsg('请选择要赠送的优惠券');
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
rule[limit].coupon = coupon.toString();
|
||||
rule[limit].coupon_num = coupon_num.toString();
|
||||
}
|
||||
|
||||
// if ($(this).find('[value="coupon"]').is(':checked')) {
|
||||
// var coupon = $(this).find('.coupon tr[data-coupon]').each(function (i, e) {coupon.push($(e).attr('data-coupon'));})
|
||||
//
|
||||
// if (coupon == undefined) {
|
||||
// showErrMsg('请选择要赠送的优惠券');
|
||||
// verify = false;
|
||||
// return false;
|
||||
// }
|
||||
// rule[limit].coupon = coupon;
|
||||
// }
|
||||
|
||||
if (rule[limit].discount_money == undefined && rule[limit].free_shipping == undefined && rule[limit].point == undefined && rule[limit].coupon == undefined) {
|
||||
showErrMsg('请选择活动层级'+ (i + 1) +'的优惠内容');
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!verify) return;
|
||||
|
||||
data.field.rule_json = JSON.stringify(rule);
|
||||
|
||||
if(data.field.manjian_type != 1){
|
||||
if(data.field.goods_ids == ''){
|
||||
layer.msg("请选择商品");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: ns.url("manjian://shop/manjian/add"),
|
||||
data: data.field,
|
||||
dataType: 'JSON',
|
||||
success: function (res) {
|
||||
repeat_flag = false;
|
||||
|
||||
if (res.code == 0) {
|
||||
layer.confirm('添加成功', {
|
||||
title:'操作提示',
|
||||
btn: ['返回列表', '继续添加'],
|
||||
closeBtn: 0,
|
||||
yes: function(index, layero){
|
||||
location.hash = ns.hash("manjian://shop/manjian/lists")
|
||||
layer.close(index);
|
||||
},
|
||||
btn2: function(index, layero) {
|
||||
listenerHash(); // 刷新页面
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
} else if (res.code == -10077){
|
||||
var key = res.data.key;
|
||||
layer.confirm('在同一活动时间内,部分商品已参加其他的满减活动', {
|
||||
title:'活动冲突提醒',
|
||||
btn: ['取消', '查看详情'],
|
||||
closeBtn: 0,
|
||||
btn1: function(index, layero){
|
||||
listenerHash(); // 刷新页面
|
||||
layer.close(index);
|
||||
},
|
||||
btn2: function(index, layero) {
|
||||
location.hash = ns.hash("manjian://shop/manjian/conflict", {"key": key});
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function showErrMsg(msg, e){
|
||||
layer.msg(msg, { icon: 5, shift: 6 });
|
||||
if (e != undefined) {
|
||||
$(e).focus();
|
||||
}
|
||||
}
|
||||
|
||||
form.on('submit(coupon-search)', function(data) {
|
||||
|
||||
data.field.status = 1;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
url: ns.url("coupon://shop/coupon/lists"),
|
||||
data: data.field,
|
||||
success: function(res) {
|
||||
repeat_flag = false;
|
||||
if (res.code == 0) {
|
||||
coupon_list=res.data;
|
||||
laytpl($("#couponListSearch").html()).render(coupon_list, function (html) {
|
||||
$(".layui-layer-content").html(html);
|
||||
if ($("tbody tr input:checked").length == $(".coupon-box tbody tr").length) {
|
||||
$("input[lay-filter='selectAll']").prop("checked", true);
|
||||
}
|
||||
form.render();
|
||||
});
|
||||
}else{
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
// 表格渲染
|
||||
function renderTable(goods_list) {
|
||||
//展示已知数据
|
||||
table = new Table({
|
||||
elem: '#selected_goods_list',
|
||||
page: false,
|
||||
limit: Number.MAX_VALUE,
|
||||
cols: [
|
||||
[{
|
||||
field: 'goods_name',
|
||||
title: '商品名称',
|
||||
unresize: 'false',
|
||||
width: '50%',
|
||||
templet: function(data) {
|
||||
var html = '';
|
||||
html += `
|
||||
<div class="goods-title">
|
||||
<div class="goods-img">
|
||||
<img src="${data.goods_image ? ns.img(data.goods_image.split(",")[0],'small') : ''}" alt="">
|
||||
</div>
|
||||
<p class="multi-line-hiding goods-name">${data.goods_name}</p>
|
||||
</div>
|
||||
`;
|
||||
return html;
|
||||
}
|
||||
}, {
|
||||
field: 'price',
|
||||
title: '商品价格(元)',
|
||||
unresize: 'false',
|
||||
align: 'right',
|
||||
width: '20%',
|
||||
templet: function(data) {
|
||||
return '¥' + data.price;
|
||||
}
|
||||
}, {
|
||||
field: 'goods_stock',
|
||||
title: '库存',
|
||||
unresize: 'false',
|
||||
align: 'center',
|
||||
width: '20%'
|
||||
}, {
|
||||
title: '操作',
|
||||
toolbar: '#operation',
|
||||
unresize: 'false',
|
||||
align:'right'
|
||||
}],
|
||||
],
|
||||
data: goods_list,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除选中商品
|
||||
function delGoods(id) {
|
||||
var i, j;
|
||||
$.each(goods_list, function(index, item) {
|
||||
var goods_id = item.goods_id;
|
||||
|
||||
if (id == Number(goods_id)) {
|
||||
i = index;
|
||||
}
|
||||
});
|
||||
goods_list.splice(i, 1);
|
||||
renderTable(goods_list);
|
||||
|
||||
$.each(selectedGoodsId, function(index, item) {
|
||||
if (id == Number(item)) {
|
||||
j = index;
|
||||
}
|
||||
});
|
||||
selectedGoodsId.splice(j, 1);
|
||||
goods_id = selectedGoodsId;
|
||||
$("#goods_num").html(selectedGoodsId.length);
|
||||
$("input[name='goods_ids']").val(goods_id.toString());
|
||||
}
|
||||
|
||||
/* 商品 */
|
||||
function addGoods(){
|
||||
goodsSelect(function (data) {
|
||||
|
||||
goods_id = [];
|
||||
goods_list = [];
|
||||
|
||||
for (var key in data) {
|
||||
goods_id.push(data[key].goods_id);
|
||||
goods_list.push(data[key]);
|
||||
}
|
||||
|
||||
renderTable(goods_list);
|
||||
$("input[name='goods_ids']").val(goods_id.toString());
|
||||
selectedGoodsId = goods_id;
|
||||
$("#goods_num").html(selectedGoodsId.length)
|
||||
}, selectedGoodsId, {mode: "spu"});
|
||||
}
|
||||
|
||||
function backManjianList() {
|
||||
location.hash = ns.hash("manjian://shop/manjian/lists");
|
||||
}
|
||||
|
||||
// 添加优惠层级
|
||||
function addDiscountLevel(){
|
||||
var type = $('[name="type"]:checked').val();
|
||||
length = $('.discount-level .level-item').length;
|
||||
if (length == 5) {
|
||||
layer.msg('最多支持五个活动层级');
|
||||
return;
|
||||
}
|
||||
var template = `<div class="level-item">
|
||||
<div class="level-head">
|
||||
<label class="title">活动层级{{ d.length + 1 }}:</label>
|
||||
<a href="javascript:;" class="text-color" onclick="deleteLevel(this)">删除</a>
|
||||
</div>
|
||||
<div class="wrap">
|
||||
<div class="condition">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠门槛:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="type-0 {{ d.type != 0 ? 'layui-hide' : '' }}">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="money" value="" lay-verify="manjian_money" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
<div class="type-1 {{ d.type != 1 ? 'layui-hide' : '' }}">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="num" value="" lay-verify="manjian_num" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">件</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠内容:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="discount-item discount-money">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="discount_money" class="input-checkbox" lay-skin="primary"><span>订单金额优惠</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div class="layui-form-mid">减</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" value="" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="free_shipping" class="input-checkbox" lay-skin="primary"><span>包邮</span>
|
||||
</div>
|
||||
<div class="word-aux" style="margin-left: 28px;margin-top: 0">
|
||||
<p>仅参与该活动的商品包邮,非整单包邮</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item point">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="point" class="input-checkbox" lay-skin="primary"><span>送积分</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div class="layui-form-mid">送</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="" value="" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">积分</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item coupon">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="coupon" class="input-checkbox" lay-skin="primary"><span>送优惠券</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div><a href="javascript:;" class="text-color select-coupon">选择优惠券</a></div>
|
||||
<div class="word-aux">
|
||||
<p>请确认优惠券数量是否充足,优惠券数量不足将导致赠送失败</p>
|
||||
</div>
|
||||
<div>
|
||||
<table class="layui-table" lay-skin="nob">
|
||||
<colgroup>
|
||||
<col width="30%">
|
||||
<col width="30%">
|
||||
<col width="20%">
|
||||
<col width="20%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>优惠券</th>
|
||||
<th>优惠内容</th>
|
||||
<th>赠券数</th>
|
||||
<th style="text-align:center;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
laytpl(template).render({
|
||||
length: length,
|
||||
type: type
|
||||
}, function(string){
|
||||
$('.discount-level .level-item:last').after(string);
|
||||
form.render();
|
||||
});
|
||||
}
|
||||
|
||||
// 选择优惠
|
||||
$('body').off('click', '.discount-item .layui-form-checkbox').on('click', '.discount-item .layui-form-checkbox', function(e){
|
||||
if ($(this).prev('[name="discount_type"]').is(':checked')) {
|
||||
$(this).parents('.discount-item').find('.discount-cont').removeClass('layui-hide');
|
||||
} else {
|
||||
$(this).parents('.discount-item').find('.discount-cont').addClass('layui-hide');
|
||||
}
|
||||
});
|
||||
|
||||
$('body').off('click', '.discount-item .select-coupon').on('click', '.discount-item .select-coupon', function(e){
|
||||
currIndex = $(this).parents('.level-item').index();
|
||||
var data = {};
|
||||
data.coupon_id = coupon_id[currIndex] != undefined ? coupon_id[currIndex] : [];
|
||||
|
||||
laytpl($("#couponList").html()).render(data, function(html) {
|
||||
coupon_list = layer.open({
|
||||
title: '优惠券列表',
|
||||
skin: 'layer-tips-class',
|
||||
type: 1,
|
||||
area: ['850px', '600px'],
|
||||
content: html,
|
||||
});
|
||||
|
||||
if ($("tbody tr input:checked").length == $(".coupon-box tbody tr").length) {
|
||||
$("input[lay-filter='selectAll']").prop("checked", true);
|
||||
}
|
||||
|
||||
form.render();
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听全选按钮
|
||||
*/
|
||||
form.on('checkbox(selectAll)', function(data) {
|
||||
if (data.elem.checked) {
|
||||
$("tr .check-box input:checkbox").each(function(index) {
|
||||
$(this).prop("checked", true);
|
||||
});
|
||||
} else {
|
||||
$("tr .check-box input:checkbox").each(function() {
|
||||
$(this).prop("checked", false);
|
||||
});
|
||||
}
|
||||
form.render();
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听每一行的多选按钮
|
||||
*/
|
||||
var len = $(".coupon-box tbody tr").length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
form.on('checkbox(select' + i + ')', function(data) {
|
||||
if ($("tbody tr input:checked").length == len) {
|
||||
$("input[lay-filter='selectAll']").prop("checked", true);
|
||||
} else {
|
||||
$("input[lay-filter='selectAll']").prop("checked", false);
|
||||
}
|
||||
|
||||
form.render();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function couponSelected() {
|
||||
if (!$("#goods tbody tr input:checked").length) {
|
||||
layer.msg('请选择优惠券');
|
||||
return;
|
||||
}
|
||||
|
||||
layer.closeAll('page');
|
||||
|
||||
coupon_id[currIndex] = [];
|
||||
|
||||
$("#coupon_selected tbody").empty();
|
||||
|
||||
var data = [];
|
||||
$("#goods tr input:checked").each(function(){
|
||||
var tr = $(this).parents('tr');
|
||||
coupon_id[currIndex].push(tr.find("#coupon_id").val());
|
||||
data.push({
|
||||
coupon_type_id: tr.find("#coupon_id").val(),
|
||||
coupon_name: tr.find(".title-content p").text(),
|
||||
at_least: tr.find('[name="at_least"]').val(),
|
||||
type: tr.find('[name="type"]').val(),
|
||||
discount: tr.find('[name="discount"]').val(),
|
||||
money: tr.find('[name="money"]').val()
|
||||
})
|
||||
});
|
||||
|
||||
laytpl($("#addCoupon").html()).render(data, function(string){
|
||||
$('.level-item:eq('+ currIndex +') .discount-cont tbody').html(string);
|
||||
layer.closeAll();
|
||||
});
|
||||
}
|
||||
|
||||
// 删除优惠层级
|
||||
function deleteLevel(e){
|
||||
$(e).parents('.level-item').remove();
|
||||
}
|
||||
|
||||
// 删除优惠券
|
||||
function deleteCoupon(e,index){
|
||||
index = $(e).parents('.level-item').index();
|
||||
coupon_id[index].splice(index, 1);
|
||||
$(e).parents('tr').remove();
|
||||
}
|
||||
596
addon/manjian/shop/view/public/js/edit.js
Executable file
596
addon/manjian/shop/view/public/js/edit.js
Executable file
@@ -0,0 +1,596 @@
|
||||
var selectedGoodsId = [], goods_id=[], coupon_id = [], addCoupon, currIndex;
|
||||
$.each(goods_list, function(index, item) {
|
||||
var id = item.goods_id;
|
||||
selectedGoodsId.push(id);
|
||||
goods_id.push(id);
|
||||
});
|
||||
|
||||
$("input[name='goods_ids']").val(goods_id.toString());
|
||||
|
||||
Object.values(manjian_info).forEach((item,index)=>{
|
||||
if (item.coupon_data) {
|
||||
var arr = [];
|
||||
item.coupon_data.forEach((subItem,subIndex)=>{
|
||||
arr.push(subItem.coupon_type_id);
|
||||
});
|
||||
coupon_id.push(arr);
|
||||
}
|
||||
});
|
||||
|
||||
var table, form, laydate, laytpl, repeat_flag = false; //防重复标识
|
||||
|
||||
layui.use(['form', 'laydate', 'laytpl'], function() {
|
||||
form = layui.form,
|
||||
laydate = layui.laydate,
|
||||
laytpl = layui.laytpl;
|
||||
|
||||
form.render();
|
||||
|
||||
renderTable(goods_list); // 初始化表格
|
||||
|
||||
laydate.render({
|
||||
elem: '#start_time',
|
||||
type: 'datetime'
|
||||
});
|
||||
|
||||
laydate.render({
|
||||
elem: '#end_time',
|
||||
type: 'datetime'
|
||||
});
|
||||
|
||||
//监听活动商品类型
|
||||
form.on('radio(manjian_type)', function(data){
|
||||
var value = data.value;
|
||||
|
||||
if(value == 1){
|
||||
$(".goods_list").hide();
|
||||
}
|
||||
if(value == 2){
|
||||
$(".goods_list").show();
|
||||
}
|
||||
});
|
||||
|
||||
form.on('radio(type)', function(data){
|
||||
var value = data.value;
|
||||
$('.level-item .type-' + value).removeClass('layui-hide').siblings('div').addClass('layui-hide');
|
||||
});
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
*/
|
||||
form.verify({
|
||||
len: function(value) {
|
||||
if (value.length > 25) {
|
||||
return "活动名称最多为25个字符!";
|
||||
}
|
||||
},
|
||||
time: function(value) {
|
||||
var now_time = (new Date()).getTime();
|
||||
var time = (new Date(value)).getTime();
|
||||
if (time < now_time) {
|
||||
return '开始时间不能小于当前时间!';
|
||||
}
|
||||
},
|
||||
times: function(value) {
|
||||
var start_time = (new Date($("#start_time").val())).getTime();
|
||||
var end_time = (new Date(value)).getTime();
|
||||
if (start_time > end_time) {
|
||||
return '结束时间不能小于开始时间!';
|
||||
}
|
||||
},
|
||||
num: function(value) {
|
||||
if (value == '') {
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
return '数字不能小于0!';
|
||||
}
|
||||
if (value * 100 % 1 != 0) {
|
||||
return '数字最多保留两位小数!';
|
||||
}
|
||||
},
|
||||
manjian_money: function(value){
|
||||
var type = $('[name="type"]:checked').val();
|
||||
if (type == 0) {
|
||||
if (!/[\S]+/.test(value)) {
|
||||
return '请输入金额';
|
||||
}
|
||||
if (value < 0) {
|
||||
return '金额不能小于0!';
|
||||
}
|
||||
}
|
||||
},
|
||||
manjian_num: function(value){
|
||||
var type = $('[name="type"]:checked').val();
|
||||
if (type == 1) {
|
||||
if (!/[\S]+/.test(value)) {
|
||||
return '请输入数量';
|
||||
}
|
||||
if (value < 0) {
|
||||
return '数量不能小于0!';
|
||||
}
|
||||
}
|
||||
},
|
||||
coupon_num: function(value){
|
||||
if (!/[\S]+/.test(value)) {
|
||||
return '请输入优惠券赠送数量';
|
||||
}
|
||||
if (value < 1) {
|
||||
return '优惠券赠送数量不能少于一张';
|
||||
}
|
||||
},
|
||||
goods_num:function (value) {
|
||||
var manjian_type = $('[name="manjian_type"]:checked').val();
|
||||
if(manjian_type == 2){
|
||||
if(value == 0){
|
||||
return '请选择活动商品!';
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听提交
|
||||
*/
|
||||
form.on('submit(save)', function(data) {
|
||||
var rule = {},
|
||||
verify = true,
|
||||
type = $('[name="type"]:checked').val();
|
||||
$('.manjian-rule .level-item').each(function(i, e) {
|
||||
var limit = parseFloat($(this).find('.type-'+ type +' .layui-input').val()).toFixed(2);
|
||||
if (i > 0) {
|
||||
var prevLimit = $('.manjian-rule .level-item:eq('+ (i - 1) +') .type-'+ type +' .layui-input').val();
|
||||
if (parseFloat(prevLimit) >= parseFloat(limit)) {
|
||||
showErrMsg('优惠门槛需大于上一级优惠门槛', $(this).find('.type-'+ type +' .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
rule[limit] = {
|
||||
limit: limit
|
||||
};
|
||||
if ($(this).find('[value="discount_money"]').is(':checked')) {
|
||||
var discount_money = $(this).find('.discount-item.discount-money .layui-input').val();
|
||||
if (!/[\S]+/.test(discount_money)) {
|
||||
showErrMsg('请输入优惠金额', $(this).find('.discount-item.discount-money .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
discount_money = parseFloat(discount_money);
|
||||
if (discount_money <= 0) {
|
||||
showErrMsg('优惠金额不能小于等于0', $(this).find('.discount-item.discount-money .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == 0 && discount_money > parseFloat(limit)) {
|
||||
showErrMsg('优惠金额请勿超出优惠门槛', $(this).find('.discount-item.discount-money .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
rule[limit].discount_money = discount_money;
|
||||
}
|
||||
|
||||
if ($(this).find('[value="free_shipping"]').is(':checked')) {
|
||||
rule[limit].free_shipping = 1;
|
||||
}
|
||||
|
||||
if ($(this).find('[value="point"]').is(':checked')) {
|
||||
var point = $(this).find('.discount-item.point .layui-input').val();
|
||||
rule[limit].point = point;
|
||||
if (!/[\S]+/.test(point)) {
|
||||
showErrMsg('请输入赠送积分数', $(this).find('.discount-item.point .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
if (point <= 0) {
|
||||
showErrMsg('赠送积分数不能小于等于0', $(this).find('.discount-item.point .layui-input'));
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var coupon = [];
|
||||
var coupon_num = [];
|
||||
if ($(this).find('[value="coupon"]').is(':checked')) {
|
||||
|
||||
$(this).find('tr[data-coupon]').each(function (i, e) {
|
||||
coupon.push($(e).attr('data-coupon'));
|
||||
});
|
||||
$(this).find(".coupon input[name='number']").each(function(j,item){
|
||||
coupon_num.push(item.value);
|
||||
});
|
||||
if (!coupon.length) {
|
||||
showErrMsg('请选择要赠送的优惠券');
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
rule[limit].coupon = coupon.toString();
|
||||
rule[limit].coupon_num = coupon_num.toString();
|
||||
}
|
||||
|
||||
if (rule[limit].discount_money == undefined && rule[limit].free_shipping == undefined && rule[limit].point == undefined && rule[limit].coupon == undefined) {
|
||||
showErrMsg('请选择活动层级'+ (i + 1) +'的优惠内容');
|
||||
verify = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!verify) return;
|
||||
|
||||
data.field.rule_json = JSON.stringify(rule);
|
||||
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: ns.url("manjian://shop/manjian/edit"),
|
||||
data: data.field,
|
||||
dataType: 'JSON',
|
||||
success: function (res) {
|
||||
repeat_flag = false;
|
||||
|
||||
if (res.code == 0) {
|
||||
layer.confirm('编辑成功', {
|
||||
title:'操作提示',
|
||||
btn: ['返回列表', '继续编辑'],
|
||||
yes: function(index, layero){
|
||||
location.hash = ns.hash("manjian://shop/manjian/lists")
|
||||
layer.close(index);
|
||||
},
|
||||
btn2: function(index, layero) {
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
} else if (res.code == -10077){
|
||||
var key = res.data.key;
|
||||
layer.confirm('在同一活动时间内,部分商品已参加其他的满减活动', {
|
||||
title:'活动冲突提醒',
|
||||
btn: ['取消', '查看详情'],
|
||||
btn1: function(index, layero){
|
||||
listenerHash(); // 刷新页面
|
||||
layer.close(index);
|
||||
},
|
||||
btn2: function(index, layero) {
|
||||
location.hash = ns.hash("manjian://shop/manjian/conflict", {"key": key});
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function showErrMsg(msg, e){
|
||||
layer.msg(msg, { icon: 5, shift: 6 });
|
||||
if (e != undefined) {
|
||||
$(e).focus();
|
||||
}
|
||||
}
|
||||
|
||||
form.on('submit(coupon-search)', function(data) {
|
||||
couponTable.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
where: data.field
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
// 表格渲染
|
||||
function renderTable(goods_list) {
|
||||
//展示已知数据
|
||||
table = new Table({
|
||||
elem: '#selected_sku_list',
|
||||
page: false,
|
||||
limit: Number.MAX_VALUE,
|
||||
cols: [
|
||||
[{
|
||||
field: 'goods_name',
|
||||
title: '商品名称',
|
||||
unresize: 'false',
|
||||
width: '50%',
|
||||
templet: function(data) {
|
||||
var html = '';
|
||||
html += `
|
||||
<div class="goods-title">
|
||||
<div class="goods-img">
|
||||
<img src="${data.goods_image ? ns.img(data.goods_image.split(",")[0],'small') : ''}" alt="">
|
||||
</div>
|
||||
<p class="multi-line-hiding goods-name">${data.goods_name}</p>
|
||||
</div>
|
||||
`;
|
||||
return html;
|
||||
}
|
||||
}, {
|
||||
field: 'price',
|
||||
title: '商品价格(元)',
|
||||
unresize: 'false',
|
||||
align: 'right',
|
||||
width: '20%',
|
||||
templet: function(data) {
|
||||
return '¥' + data.price;
|
||||
}
|
||||
}, {
|
||||
field: 'goods_stock',
|
||||
title: '库存',
|
||||
unresize: 'false',
|
||||
align: 'center',
|
||||
width: '20%'
|
||||
}, {
|
||||
title: '操作',
|
||||
toolbar: '#operation',
|
||||
unresize: 'false',
|
||||
align:'right'
|
||||
}],
|
||||
],
|
||||
data: goods_list,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除选中商品
|
||||
function delGoods(id) {
|
||||
var i, j;
|
||||
$.each(goods_list, function(index, item) {
|
||||
var goods_id = item.goods_id;
|
||||
|
||||
if (id == goods_id) {
|
||||
i = index;
|
||||
}
|
||||
});
|
||||
goods_list.splice(i, 1);
|
||||
renderTable(goods_list);
|
||||
|
||||
$.each(selectedGoodsId, function(index, item) {
|
||||
if (id == item) {
|
||||
j = index;
|
||||
}
|
||||
});
|
||||
selectedGoodsId.splice(j, 1);
|
||||
goods_id = selectedGoodsId;
|
||||
$("#goods_num").html(selectedGoodsId.length);
|
||||
$("input[name='goods_ids']").val(goods_id.toString());
|
||||
}
|
||||
|
||||
function addGoods(){
|
||||
goodsSelect(function (data) {
|
||||
|
||||
goods_id = [];
|
||||
goods_list = [];
|
||||
|
||||
for (var key in data) {
|
||||
goods_id.push(data[key].goods_id);
|
||||
goods_list.push(data[key]);
|
||||
}
|
||||
|
||||
renderTable(goods_list);
|
||||
$("input[name='goods_ids']").val(goods_id.toString());
|
||||
selectedGoodsId = goods_id;
|
||||
$("#goods_num").html(selectedGoodsId.length)
|
||||
}, selectedGoodsId, {mode: "spu"});
|
||||
}
|
||||
|
||||
function backManjianList() {
|
||||
location.hash = ns.hash("manjian://shop/manjian/lists");
|
||||
}
|
||||
|
||||
// 添加优惠层级
|
||||
function addDiscountLevel(){
|
||||
var type = $('[name="type"]:checked').val();
|
||||
length = $('.discount-level .level-item').length;
|
||||
if (length == 5) {
|
||||
layer.msg('最多支持五个活动层级');
|
||||
return;
|
||||
}
|
||||
var template = `<div class="level-item">
|
||||
<div class="level-head">
|
||||
<label class="title">活动层级{{ d.length + 1 }}:</label>
|
||||
<a href="javascript:;" class="text-color" onclick="deleteLevel(this)">删除</a>
|
||||
</div>
|
||||
<div class="wrap">
|
||||
<div class="condition">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠门槛:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="type-0 {{ d.type != 0 ? 'layui-hide' : '' }}">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="money" value="" lay-verify="manjian_money" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
<div class="type-1 {{ d.type != 1 ? 'layui-hide' : '' }}">
|
||||
<div class="layui-form-mid">满</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="num" value="" lay-verify="manjian_num" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">件</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<label class="layui-form-label"><span class="required">*</span>优惠内容:</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="discount-item discount-money">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="discount_money" class="input-checkbox" lay-skin="primary"><span>订单金额优惠</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div class="layui-form-mid">减</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" value="" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">元</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="free_shipping" class="input-checkbox" lay-skin="primary"><span>包邮</span>
|
||||
</div>
|
||||
<div class="word-aux" style="margin-left: 28px;margin-top: 0">
|
||||
<p>仅参与该活动的商品包邮,非整单包邮</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item point">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="point" class="input-checkbox" lay-skin="primary"><span>送积分</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div class="layui-form-mid">送</div>
|
||||
<div class="layui-input-inline len-short">
|
||||
<input type="number" name="" value="" placeholder="" autocomplete="off" class="layui-input len-short">
|
||||
</div>
|
||||
<div class="layui-form-mid">积分</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="discount-item coupon">
|
||||
<div>
|
||||
<input type="checkbox" name="discount_type" value="coupon" class="input-checkbox" lay-skin="primary"><span>送优惠券</span>
|
||||
</div>
|
||||
<div class="discount-cont layui-hide">
|
||||
<div><a href="javascript:;" class="text-color select-coupon">选择优惠券</a></div>
|
||||
<div class="word-aux">
|
||||
<p>请确认优惠券数量是否充足,优惠券数量不足将导致赠送失败</p>
|
||||
</div>
|
||||
<div>
|
||||
<table class="layui-table" lay-skin="nob">
|
||||
<colgroup>
|
||||
<col width="30%">
|
||||
<col width="30%">
|
||||
<col width="20%">
|
||||
<col width="20%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>优惠券</th>
|
||||
<th>优惠内容</th>
|
||||
<th>赠券数</th>
|
||||
<th style="text-align:center;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
laytpl(template).render({
|
||||
length: length,
|
||||
type: type
|
||||
}, function(string){
|
||||
$('.discount-level .level-item:last').after(string);
|
||||
form.render();
|
||||
});
|
||||
}
|
||||
|
||||
// 选择优惠
|
||||
$('body').off('click', '.discount-item .layui-form-checkbox').on('click', '.discount-item .layui-form-checkbox', function(e){
|
||||
if ($(this).prev('[name="discount_type"]').is(':checked')) {
|
||||
$(this).parents('.discount-item').find('.discount-cont').removeClass('layui-hide');
|
||||
} else {
|
||||
$(this).parents('.discount-item').find('.discount-cont').addClass('layui-hide');
|
||||
}
|
||||
});
|
||||
|
||||
$('body').off('click', '.discount-item .select-coupon').on('click', '.discount-item .select-coupon', function(e){
|
||||
currIndex = $(this).parents('.level-item').index();
|
||||
var data = {};
|
||||
data.coupon_id = coupon_id[currIndex] != undefined ? coupon_id[currIndex] : [];
|
||||
|
||||
laytpl($("#couponList").html()).render(data, function(html) {
|
||||
coupon_list = layer.open({
|
||||
title: '优惠券列表',
|
||||
skin: 'layer-tips-class',
|
||||
type: 1,
|
||||
area: ['850px', '600px'],
|
||||
content: html,
|
||||
});
|
||||
|
||||
if ($("tbody tr input:checked").length == $(".coupon-box tbody tr").length) {
|
||||
$("input[lay-filter='selectAll']").prop("checked", true);
|
||||
}
|
||||
|
||||
form.render();
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听全选按钮
|
||||
*/
|
||||
form.on('checkbox(selectAll)', function(data) {
|
||||
if (data.elem.checked) {
|
||||
$("tr .check-box input:checkbox").each(function(index) {
|
||||
$(this).prop("checked", true);
|
||||
});
|
||||
} else {
|
||||
$("tr .check-box input:checkbox").each(function() {
|
||||
$(this).prop("checked", false);
|
||||
});
|
||||
}
|
||||
form.render();
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听每一行的多选按钮
|
||||
*/
|
||||
var len = $(".coupon-box tbody tr").length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
form.on('checkbox(select' + i + ')', function(data) {
|
||||
if ($("tbody tr input:checked").length == len) {
|
||||
$("input[lay-filter='selectAll']").prop("checked", true);
|
||||
} else {
|
||||
$("input[lay-filter='selectAll']").prop("checked", false);
|
||||
}
|
||||
|
||||
form.render();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function couponSelected() {
|
||||
layer.closeAll('page');
|
||||
|
||||
coupon_id[currIndex] = [];
|
||||
var _len = $("#goods tbody tr input:checked").length;
|
||||
// if (!_len) {
|
||||
// layer.msg('请选择优惠券');
|
||||
// return;
|
||||
// }
|
||||
|
||||
$("#coupon_selected tbody").empty();
|
||||
|
||||
var data = [];
|
||||
$("#goods tr input:checked").each(function(){
|
||||
var tr = $(this).parents('tr');
|
||||
coupon_id[currIndex].push(tr.find("#coupon_id").val());
|
||||
data.push({
|
||||
coupon_type_id: tr.find("#coupon_id").val(),
|
||||
coupon_name: tr.find(".title-content p").text(),
|
||||
at_least: tr.find('[name="at_least"]').val(),
|
||||
type: tr.find('[name="type"]').val(),
|
||||
discount: tr.find('[name="discount"]').val(),
|
||||
money: tr.find('[name="money"]').val()
|
||||
})
|
||||
});
|
||||
|
||||
laytpl($("#addCoupon").html()).render(data, function(string){
|
||||
$('.level-item:eq('+ currIndex +') .discount-cont tbody').html(string);
|
||||
layer.closeAll();
|
||||
});
|
||||
}
|
||||
// 删除优惠层级
|
||||
function deleteLevel(e){
|
||||
$(e).parents('.level-item').remove();
|
||||
}
|
||||
|
||||
// 删除优惠券
|
||||
function deleteCoupon(e,index){
|
||||
index = $(e).parents('.level-item').index();
|
||||
coupon_id[index].splice(index, 1);
|
||||
$(e).parents('tr').remove();
|
||||
}
|
||||
Reference in New Issue
Block a user