初始上传
This commit is contained in:
81
addon/topic/api/controller/Ordercreate.php
Executable file
81
addon/topic/api/controller/Ordercreate.php
Executable file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Index.php
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2015-2025 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
* @author : niuteam
|
||||
* @date : 2022.8.8
|
||||
* @version : v5.0.0.1
|
||||
*/
|
||||
|
||||
namespace addon\topic\api\controller;
|
||||
|
||||
use addon\topic\model\TopicOrderCreate as OrderCreateModel;
|
||||
use app\api\controller\BaseOrderCreateApi;
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
*
|
||||
*/
|
||||
class Ordercreate extends BaseOrderCreateApi
|
||||
{
|
||||
/**
|
||||
* 创建订单
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
$order_create = new OrderCreateModel();
|
||||
$data = [
|
||||
'order_key' => $this->params['order_key'] ?? '',
|
||||
'is_balance' => $this->params['is_balance'] ?? 0,//是否使用余额
|
||||
];
|
||||
$res = $order_create->setParam(array_merge($data, $this->getInputParam(), $this->getCommonParam(), $this->getDeliveryParam(), $this->getInvoiceParam()))->create();
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算信息
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
$order_create = new OrderCreateModel();
|
||||
$data = [
|
||||
'order_key' => $this->params['order_key'] ?? '',//订单缓存
|
||||
'is_balance' => $this->params['is_balance'] ?? 0,//是否使用余额
|
||||
];
|
||||
$res = $order_create->setParam(array_merge($data, $this->getCommonParam(), $this->getDeliveryParam(), $this->getInvoiceParam()))->confirm();
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 待支付订单 数据初始化
|
||||
* @return string
|
||||
*/
|
||||
public function payment()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
$order_create = new OrderCreateModel();
|
||||
$data = [
|
||||
'id' => $this->params[ 'topic_goods_id' ] ?? '',//专题商品id
|
||||
'num' => $this->params[ 'num' ] ?? 1,//专题商品数量(买几套)
|
||||
];
|
||||
if (empty($data[ 'id' ])) {
|
||||
return $this->response($this->error('', '缺少必填参数商品数据'));
|
||||
}
|
||||
if ($data[ 'num' ] < 1) {
|
||||
return $this->response($this->error('', '购买数量不能小于1'));
|
||||
}
|
||||
$res = $order_create->setParam(array_merge($data, $this->getCommonParam(), $this->getDeliveryParam()))->orderPayment();
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
}
|
||||
40
addon/topic/api/controller/Topic.php
Executable file
40
addon/topic/api/controller/Topic.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\api\controller;
|
||||
|
||||
use app\api\controller\BaseApi;
|
||||
use addon\topic\model\Topic as TopicModel;
|
||||
|
||||
/**
|
||||
* 专题活动
|
||||
*/
|
||||
class Topic extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 列表信息
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
$condition = [
|
||||
[ 'status', '=', 2 ],
|
||||
[ 'site_id', '=', $this->site_id ]
|
||||
];
|
||||
$order = 'create_time desc';
|
||||
$field = 'topic_id,topic_name,topic_adv,status,remark,start_time,end_time';
|
||||
$topic_model = new TopicModel();
|
||||
$list = $topic_model->getTopicPageList($condition, $page, $page_size, $order, $field);
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
}
|
||||
147
addon/topic/api/controller/Topicgoods.php
Executable file
147
addon/topic/api/controller/Topicgoods.php
Executable file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\api\controller;
|
||||
|
||||
use addon\topic\model\Poster;
|
||||
use addon\topic\model\Topic as TopicModel;
|
||||
use addon\topic\model\TopicGoods as TopicGoodsModel;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\model\goods\GoodsApi;
|
||||
use app\model\system\Promotion as PromotionModel;
|
||||
|
||||
/**
|
||||
* 专题活动商品
|
||||
*/
|
||||
class Topicgoods extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 详情信息
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$this->checkToken();
|
||||
$id = $this->params['topic_id'] ?? 0;
|
||||
if (empty($id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
|
||||
$topic_goods_model = new TopicGoodsModel();
|
||||
$condition = [
|
||||
[ 'ptg.id', '=', $id ],
|
||||
[ 'pt.status', '=', 2 ]
|
||||
];
|
||||
$goods_sku_detail = $topic_goods_model->getTopicGoodsDetail($condition)[ 'data' ];
|
||||
|
||||
if (empty($goods_sku_detail)) return $this->response($this->error());
|
||||
|
||||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||||
|
||||
if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
|
||||
$goods_spec_format = $topic_goods_model->getGoodsSpecFormat($goods_sku_detail[ 'topic_id' ], $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
|
||||
$res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
}
|
||||
|
||||
// 处理公共数据
|
||||
$goods_sku_api = new GoodsApi();
|
||||
$goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ], $this->member_id, $this->site_id);
|
||||
|
||||
return $this->response($this->success($res));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品SKU集合
|
||||
* @return false|string
|
||||
*/
|
||||
public function goodsSku()
|
||||
{
|
||||
$goods_id = $this->params['goods_id'] ?? 0;
|
||||
$topic_id = $this->params['topic_id'] ?? 0;
|
||||
|
||||
if (empty($topic_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
if (empty($goods_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$topic_goods_model = new TopicGoodsModel();
|
||||
$condition = [
|
||||
[ 'ptg.topic_id', '=', $topic_id ],
|
||||
[ 'ptg.goods_id', '=', $goods_id ],
|
||||
[ 'pt.status', '=', 2 ]
|
||||
];
|
||||
$list = $topic_goods_model->getTopicGoodsSkuList($condition);
|
||||
if (!empty($list[ 'data' ])) {
|
||||
foreach ($list[ 'data' ] as $k => $v) {
|
||||
if (!empty($v[ 'goods_spec_format' ])) {
|
||||
$goods_spec_format = $topic_goods_model->getGoodsSpecFormat($v[ 'topic_id' ], $this->site_id, $v[ 'goods_spec_format' ]);
|
||||
$list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表信息
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
$topic_id = $this->params['topic_id'] ?? 0;
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
|
||||
if (empty($topic_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_TOPIC_ID'));
|
||||
}
|
||||
$condition = [
|
||||
[ 'nptg.topic_id', '=', $topic_id ],
|
||||
[ 'ngs.goods_state', '=', 1 ],
|
||||
[ 'ngs.is_delete', '=', 0 ],
|
||||
[ 'nptg.default', '=', 1 ]
|
||||
];
|
||||
$order = 'nptg.id asc';
|
||||
$topic_goods_model = new TopicGoodsModel();
|
||||
|
||||
$topic_model = new TopicModel();
|
||||
$info = $topic_model->getTopicInfo([ [ "topic_id", "=", $topic_id ] ], 'bg_color,topic_adv,topic_name');
|
||||
$info = $info[ 'data' ];
|
||||
|
||||
$res = $topic_goods_model->getTopicGoodsPageList($condition, $page, $page_size, $order);
|
||||
// $res[ 'data' ][ 'bg_color' ] = $info[ 'bg_color' ];
|
||||
$res[ 'data' ][ 'topic_adv' ] = $info[ 'topic_adv' ];
|
||||
$res[ 'data' ][ 'topic_name' ] = $info[ 'topic_name' ];
|
||||
|
||||
$promotion_model = new PromotionModel();
|
||||
$zone_config = $promotion_model->getPromotionZoneConfig('topic', $this->site_id)[ 'data' ][ 'value' ];
|
||||
$res[ 'data' ][ 'bg_color' ] = $zone_config[ 'bg_color' ];
|
||||
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品海报
|
||||
*/
|
||||
public function poster()
|
||||
{
|
||||
$this->checkToken();
|
||||
|
||||
$promotion_type = 'topic';
|
||||
$qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
|
||||
$qrcode_param[ 'source_member' ] = $this->member_id;
|
||||
$poster = new Poster();
|
||||
$res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
}
|
||||
56
addon/topic/config/diy_view.php
Executable file
56
addon/topic/config/diy_view.php
Executable file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
return [
|
||||
|
||||
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
|
||||
'template' => [],
|
||||
|
||||
// 后台自定义组件——装修
|
||||
'util' => [],
|
||||
|
||||
// 自定义页面路径
|
||||
'link' => [
|
||||
[
|
||||
'name' => 'THEMATIC_ACTIVITIES',
|
||||
'title' => '专题活动',
|
||||
'parent' => 'MARKETING_LINK',
|
||||
'wap_url' => '',
|
||||
'web_url' => '',
|
||||
'sort' => 0,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'THEMATIC_ACTIVITIES_LIST',
|
||||
'title' => '专题活动列表',
|
||||
'wap_url' => '/pages_promotion/topics/list',
|
||||
'web_url' => '',
|
||||
'sort' => 0
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
// 自定义图标库
|
||||
'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' => []
|
||||
];
|
||||
47
addon/topic/config/event.php
Executable file
47
addon/topic/config/event.php
Executable file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// 事件定义文件
|
||||
return [
|
||||
'bind' => [
|
||||
|
||||
],
|
||||
|
||||
'listen' => [
|
||||
//专题活动开启事件
|
||||
'OpenTopic' => [
|
||||
'addon\topic\event\OpenTopic',
|
||||
],
|
||||
//专题活动关闭事件
|
||||
'CloseTopic' => [
|
||||
'addon\topic\event\CloseTopic',
|
||||
],
|
||||
//展示活动
|
||||
'ShowPromotion' => [
|
||||
'addon\topic\event\ShowPromotion',
|
||||
],
|
||||
//用于订单
|
||||
'PromotionType' => [
|
||||
'addon\topic\event\PromotionType',
|
||||
],
|
||||
// 商品营销活动类型
|
||||
'GoodsPromotionType' => [
|
||||
'addon\topic\event\GoodsPromotionType',
|
||||
],
|
||||
|
||||
// 商品营销活动信息
|
||||
'GoodsPromotion' => [
|
||||
'addon\topic\event\GoodsPromotion',
|
||||
],
|
||||
// 订单营销活动类型
|
||||
'OrderPromotionType' => [
|
||||
'addon\topic\event\OrderPromotionType',
|
||||
],
|
||||
|
||||
// 活动专区——专题活动页面配置
|
||||
'PromotionZoneConfig' => [
|
||||
'addon\topic\event\TopicZoneConfig',
|
||||
]
|
||||
],
|
||||
|
||||
'subscribe' => [
|
||||
],
|
||||
];
|
||||
20
addon/topic/config/info.php
Executable file
20
addon/topic/config/info.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
return [
|
||||
'name' => 'topic',
|
||||
'title' => '专题活动',
|
||||
'description' => '专题活动功能',
|
||||
'type' => 'promotion', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:扩展营销插件 tool:工具插件
|
||||
'status' => 1,
|
||||
'author' => '',
|
||||
'version' => '5.5.3',
|
||||
'version_no' => '553250709001',
|
||||
'content' => '',
|
||||
];
|
||||
74
addon/topic/config/menu_shop.php
Executable file
74
addon/topic/config/menu_shop.php
Executable file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 平台端菜单设置
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
[
|
||||
'name' => 'PROMOTION_TOPIC',
|
||||
'title' => '专题活动',
|
||||
'url' => 'topic://shop/topic/lists',
|
||||
'parent' => 'PROMOTION_CENTER',
|
||||
'is_show' => 1,
|
||||
'is_control' => 1,
|
||||
'is_icon' => 0,
|
||||
'picture' => '',
|
||||
'picture_select' => '',
|
||||
'sort' => 100,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'PROMOTION_TOPIC_LIST',
|
||||
'title' => '活动管理',
|
||||
'url' => 'topic://shop/topic/lists',
|
||||
'parent' => 'PROMOTION_CENTER',
|
||||
'is_show' => 0,
|
||||
'is_control' => 1,
|
||||
'is_icon' => 0,
|
||||
'picture' => '',
|
||||
'picture_select' => '',
|
||||
'sort' => 100,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'PROMOTION_TOPIC_ADD',
|
||||
'title' => '添加活动',
|
||||
'url' => 'topic://shop/topic/add',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_TOPIC_EDIT',
|
||||
'title' => '编辑活动',
|
||||
'url' => 'topic://shop/topic/edit',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_TOPIC_DELETE',
|
||||
'title' => '删除活动',
|
||||
'url' => 'topic://shop/topic/delete',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_TOPIC_CLOSE',
|
||||
'title' => '关闭活动',
|
||||
'url' => 'topic://shop/topic/close',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
],
|
||||
[
|
||||
'name' => 'PROMOTION_TOPIC_DETAIL',
|
||||
'title' => '查看活动',
|
||||
'url' => 'topic://shop/topic/detail',
|
||||
'sort' => 1,
|
||||
'is_show' => 0,
|
||||
'type' => 'button',
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
1
addon/topic/data/install.sql
Executable file
1
addon/topic/data/install.sql
Executable file
@@ -0,0 +1 @@
|
||||
SET NAMES 'utf8';
|
||||
1
addon/topic/data/uninstall.sql
Executable file
1
addon/topic/data/uninstall.sql
Executable file
@@ -0,0 +1 @@
|
||||
SET NAMES 'utf8';
|
||||
28
addon/topic/event/CloseTopic.php
Executable file
28
addon/topic/event/CloseTopic.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
use addon\topic\model\Topic;
|
||||
|
||||
/**
|
||||
* 关闭活动
|
||||
*/
|
||||
class CloseTopic
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$topic = new Topic();
|
||||
$res = $topic->cronCloseTopic($params['relate_id']);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
71
addon/topic/event/GoodsPromotion.php
Executable file
71
addon/topic/event/GoodsPromotion.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
use addon\topic\model\TopicGoods;
|
||||
use app\model\goods\Goods as GoodsModel;
|
||||
|
||||
/**
|
||||
* 商品营销活动信息
|
||||
*/
|
||||
class GoodsPromotion
|
||||
{
|
||||
|
||||
/**
|
||||
* 商品营销活动信息
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function handle($param)
|
||||
{
|
||||
if (isset($param[ 'goods_sku_detail' ])) {
|
||||
$goods_info = $param[ 'goods_sku_detail' ];
|
||||
if (!empty($goods_info[ 'promotion_addon' ])) {
|
||||
$promotion_addon = json_decode($goods_info[ 'promotion_addon' ], true);
|
||||
if (!empty($promotion_addon[ 'topic' ])) {
|
||||
//查询商品对应活动id
|
||||
$info = ( new TopicGoods() )->getTopicIdByGoodsId($promotion_addon[ 'topic' ], $goods_info[ 'sku_id' ]);
|
||||
if (!empty($info)) {
|
||||
return [
|
||||
'promotion_type' => 'topic',
|
||||
'promotion_name' => '专题活动',
|
||||
'id' => $info[ 'id' ]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (empty($param[ 'goods_id' ])) return [];
|
||||
$goods_model = new GoodsModel();
|
||||
$goods_info = $goods_model->getGoodsInfo([ [ 'goods_id', '=', $param[ 'goods_id' ] ] ], 'promotion_addon')[ 'data' ];
|
||||
if (!empty($goods_info[ 'promotion_addon' ])) {
|
||||
$promotion_addon = json_decode($goods_info[ 'promotion_addon' ], true);
|
||||
if (!empty($promotion_addon[ 'topic' ])) {
|
||||
$topic_model = new TopicGoods();
|
||||
$condition = [
|
||||
[ 'pt.topic_id', '=', $promotion_addon[ 'topic' ] ],
|
||||
[ 'sku.sku_id', '=', $param[ 'sku_id' ] ],
|
||||
[ 'pt.status', '=', 2 ]
|
||||
];
|
||||
$field = 'sku.goods_id,sku.sku_id,sku.price,sku.site_id,ptg.id,ptg.topic_id,ptg.topic_price,pt.topic_name';
|
||||
$goods_detail = $topic_model->getTopicGoodsDetail($condition, $field)[ 'data' ];
|
||||
if (!empty($goods_detail)) {
|
||||
$goods_detail[ 'promotion_type' ] = 'topic';
|
||||
$goods_detail[ 'promotion_name' ] = '专题活动';
|
||||
return $goods_detail;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
27
addon/topic/event/GoodsPromotionType.php
Executable file
27
addon/topic/event/GoodsPromotionType.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class GoodsPromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ 'name' => '专题活动', 'short' => '专', 'type' => 'topic', 'color' => '#F1A750', 'url' => 'topic://shop/topic/lists' ];
|
||||
}
|
||||
}
|
||||
25
addon/topic/event/Install.php
Executable file
25
addon/topic/event/Install.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
/**
|
||||
* 应用安装
|
||||
*/
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
}
|
||||
}
|
||||
28
addon/topic/event/OpenTopic.php
Executable file
28
addon/topic/event/OpenTopic.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
use addon\topic\model\Topic;
|
||||
|
||||
/**
|
||||
* 启动活动
|
||||
*/
|
||||
class OpenTopic
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$topic = new Topic();
|
||||
$res = $topic->cronOpenTopic($params['relate_id']);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
27
addon/topic/event/OrderPromotionType.php
Executable file
27
addon/topic/event/OrderPromotionType.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
*/
|
||||
class OrderPromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "专题", "type" => "topic" ];
|
||||
}
|
||||
}
|
||||
27
addon/topic/event/PromotionType.php
Executable file
27
addon/topic/event/PromotionType.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class PromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "专题", "type" => "topic" ];
|
||||
}
|
||||
}
|
||||
89
addon/topic/event/ShowPromotion.php
Executable file
89
addon/topic/event/ShowPromotion.php
Executable file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
*/
|
||||
class ShowPromotion
|
||||
{
|
||||
public $promotion_type = 'time_limit';
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function handle($params = [])
|
||||
{
|
||||
$data = [
|
||||
'shop' => [
|
||||
[
|
||||
//插件名称
|
||||
'name' => 'topic',
|
||||
//展示分类(根据平台端设置,shop:店铺营销,member:会员营销, tool:应用工具)
|
||||
'show_type' => 'shop',
|
||||
//展示主题
|
||||
'title' => '专题活动',
|
||||
//展示介绍
|
||||
'description' => '打造主题营销专区',
|
||||
//展示图标
|
||||
'icon' => 'addon/topic/icon.png',
|
||||
//跳转链接
|
||||
'url' => 'topic://shop/topic/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_topic")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
|
||||
return [
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
//获取活动概况,需要获取开始时间与结束时间
|
||||
if (isset($params[ 'summary' ])) {
|
||||
$list = model("promotion_topic")->getList([
|
||||
[ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
|
||||
[ 'site_id', '=', $params[ 'site_id' ] ]
|
||||
], 'topic_name as promotion_name,topic_id as promotion_id,start_time,end_time');
|
||||
return !empty($list) ? [
|
||||
'time_limit' => [
|
||||
'count' => count($list),
|
||||
'detail' => $list,
|
||||
'color' => '#7BE295'
|
||||
]
|
||||
] : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
37
addon/topic/event/TopicZoneConfig.php
Executable file
37
addon/topic/event/TopicZoneConfig.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
|
||||
/**
|
||||
* 活动专区——专题活动页面配置
|
||||
*/
|
||||
class TopicZoneConfig
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
if (empty($params) || $params[ 'name' ] == 'topic') {
|
||||
$data = [
|
||||
'name' => 'topic', // 标识
|
||||
'title' => '专题活动', // 名称
|
||||
'url' => 'topic://shop/topic/lists', // 自定义跳转链接
|
||||
'preview' => 'addon/topic/shop/view/public/img/zone_preview.png', // 预览图
|
||||
// 页面配置
|
||||
'value' => [
|
||||
'bg_color' => '#F4F4F4'
|
||||
],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
25
addon/topic/event/UnInstall.php
Executable file
25
addon/topic/event/UnInstall.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\event;
|
||||
|
||||
/**
|
||||
* 应用卸载
|
||||
*/
|
||||
class UnInstall
|
||||
{
|
||||
/**
|
||||
* 执行卸载
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return error("系统插件不能删除");
|
||||
}
|
||||
}
|
||||
BIN
addon/topic/icon.png
Executable file
BIN
addon/topic/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
448
addon/topic/model/Poster.php
Executable file
448
addon/topic/model/Poster.php
Executable file
@@ -0,0 +1,448 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\model;
|
||||
|
||||
use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
|
||||
use app\model\BaseModel;
|
||||
use app\model\system\Site;
|
||||
use app\model\web\Config;
|
||||
use extend\Poster as PosterExtend;
|
||||
|
||||
/**
|
||||
* 海报生成类
|
||||
*/
|
||||
class Poster extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 商品海报
|
||||
*/
|
||||
public function goods($app_type, $page, $qrcode_param, $promotion_type, $site_id)
|
||||
{
|
||||
try {
|
||||
$goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ]);
|
||||
|
||||
if (empty($goods_info)) return $this->error('未获取到商品信息');
|
||||
|
||||
$qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
|
||||
|
||||
if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
|
||||
//判断海报是否存在或停用
|
||||
$template_info = $this->getTemplateInfo($goods_info[ 'template_id' ]);
|
||||
$site_model = new Site();
|
||||
$condition = array (
|
||||
[ "site_id", "=", $site_id ]
|
||||
);
|
||||
$site_info = $site_model->getSiteInfo($condition);
|
||||
if (!empty($qrcode_param[ 'source_member' ])) {
|
||||
$member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
|
||||
}
|
||||
|
||||
$upload_config_model = new Config();
|
||||
$upload_config_result = $upload_config_model->getDefaultImg($site_id);
|
||||
|
||||
if (empty($goods_info[ 'template_id' ]) || empty($template_info) || $template_info[ 'template_status' ] == 0) {
|
||||
$poster_width = 720;
|
||||
$poster_height = 1150;
|
||||
|
||||
$poster = new PosterExtend($poster_width, $poster_height);
|
||||
|
||||
$option = [
|
||||
[
|
||||
'action' => 'setBackground', // 设背景色
|
||||
'data' => [255, 255, 255]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品图
|
||||
'data' => [
|
||||
$goods_info['sku_image'],
|
||||
50,
|
||||
165,
|
||||
620,
|
||||
620,
|
||||
'square',
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品名称
|
||||
'data' => [
|
||||
$goods_info['sku_name'],
|
||||
22,
|
||||
[35, 35, 35],
|
||||
50,
|
||||
915,
|
||||
360,
|
||||
2,
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品二维码
|
||||
'data' => [
|
||||
$qrcode_info['data']['path'],
|
||||
435,
|
||||
825,
|
||||
240,
|
||||
240,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入提示
|
||||
'data' => [
|
||||
'长按识别二维码',
|
||||
19,
|
||||
[102, 102, 102],
|
||||
465,
|
||||
1110,
|
||||
490,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格单位
|
||||
'data' => [
|
||||
'¥',
|
||||
27,
|
||||
[255, 0, 0],
|
||||
50,
|
||||
860,
|
||||
490,
|
||||
2,
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格
|
||||
'data' => [
|
||||
$goods_info[ 'topic_price' ],
|
||||
30,
|
||||
[255, 0, 0],
|
||||
78,
|
||||
862,
|
||||
490,
|
||||
2,
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
];
|
||||
if (isset($member_info) && !empty($member_info)) {
|
||||
$member_option = [
|
||||
[
|
||||
'action' => 'imageCircularCopy', // 写入用户头像
|
||||
'data' => [
|
||||
!empty($member_info['headimg']) ? $member_info['headimg'] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
|
||||
50,
|
||||
30,
|
||||
100,
|
||||
100
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
$member_info['nickname'],
|
||||
22,
|
||||
[10, 10, 10],
|
||||
170,
|
||||
80,
|
||||
580,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
'分享给你一个商品',
|
||||
18,
|
||||
[102, 102, 102],
|
||||
170,
|
||||
115,
|
||||
580,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
]
|
||||
];
|
||||
$option = array_merge($option, $member_option);
|
||||
}
|
||||
} else {
|
||||
$condition = [
|
||||
[ 'template_id', '=', $goods_info[ 'template_id' ] ],
|
||||
[ 'site_id', '=', $site_id ]
|
||||
];
|
||||
$poster_template_model = new PosterTemplateModel();
|
||||
$poster_data = $poster_template_model->getPosterTemplateInfo($condition);
|
||||
$poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
|
||||
$poster_width = 720;
|
||||
$poster_height = 1280;
|
||||
$poster = new PosterExtend($poster_width, $poster_height);
|
||||
$fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
|
||||
if (!empty($poster_data[ 'data' ][ 'background' ])) {
|
||||
list($width, $height, $type, $attr) = getimagesize(img($poster_data[ 'data' ][ 'background' ]));
|
||||
$back_ground = [
|
||||
'action' => 'imageCopy', // 写入背景图
|
||||
'data' => [
|
||||
img($poster_data[ 'data' ][ 'background' ]),
|
||||
0,
|
||||
0,
|
||||
$poster_width,
|
||||
$poster_height,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
];
|
||||
} else {
|
||||
$back_ground = [
|
||||
'action' => 'setBackground', // 设背景色
|
||||
'data' => [ 255, 255, 255 ]
|
||||
];
|
||||
}
|
||||
$option = [
|
||||
$back_ground,
|
||||
[
|
||||
'action' => 'imageText', // 写入店铺名称
|
||||
'data' => [
|
||||
$site_info[ 'data' ][ 'site_name' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] * $fontRate,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'store_name_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_left' ] * 2,
|
||||
( $poster_data[ 'data' ][ 'template_json' ][ 'store_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] ) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_height' ] * 2,
|
||||
1,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 店铺logo
|
||||
'data' => [
|
||||
!empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : getUrl() . '/app/shop/view/public/img/shop_logo.png',
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_height' ] * 2,
|
||||
'square',
|
||||
1,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品图
|
||||
'data' => [
|
||||
$goods_info[ 'sku_image' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_height' ] * 2,
|
||||
!empty($poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ] : 'square',
|
||||
0,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品名称
|
||||
'data' => [
|
||||
$goods_info[ 'sku_name' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] * $fontRate,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_left' ] * 2,
|
||||
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] ) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_width' ] * 2,
|
||||
1,//文本行数 $poster_data['data']['template_json']['goods_name_height']*2,
|
||||
true,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品二维码
|
||||
'data' => [
|
||||
$qrcode_info[ 'data' ][ 'path' ],
|
||||
$poster_data[ 'data' ][ 'qrcode_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'qrcode_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'qrcode_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'qrcode_height' ] * 2,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格
|
||||
'data' => [
|
||||
'¥' . $goods_info[ 'topic_price' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] * $fontRate,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_left' ] * 2,
|
||||
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] ) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_height' ] * 2,
|
||||
1,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_is_show' ]
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
if ($goods_info['price'] ==0 ){
|
||||
$line = '一一一';
|
||||
}else{
|
||||
$line = '一一一一';
|
||||
}
|
||||
$market_price = [
|
||||
[
|
||||
'action' => 'imageText', // 写入商品划线价格
|
||||
'data' => [
|
||||
'¥' . $goods_info[ 'price' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2,
|
||||
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
|
||||
1,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ] ?? 0
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入线
|
||||
'data' => [
|
||||
$line,
|
||||
$poster_data['data']['template_json']['goods_market_price_font_size']*$fontRate*2,
|
||||
hex2rgb($poster_data['data']['template_json']['goods_market_price_color']),
|
||||
$poster_data['data']['template_json']['goods_market_price_left']*2-5,
|
||||
($poster_data['data']['template_json']['goods_market_price_top']+$poster_data['data']['template_json']['goods_market_price_font_size'])*2,
|
||||
$poster_data['data']['template_json']['goods_market_price_width']*2,
|
||||
$poster_data['data']['template_json']['goods_market_price_height']*2,
|
||||
true,
|
||||
$poster_data['data']['template_json']['goods_market_price_is_show']
|
||||
]
|
||||
],
|
||||
];
|
||||
$option = array_merge($option, $market_price);
|
||||
|
||||
if (!empty($member_info)) {
|
||||
$member_option = [
|
||||
[
|
||||
'action' => 'imageCopy', // 写入用户头像
|
||||
'data' => [
|
||||
!empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : 'public/static/img/default_img/head.png',
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
|
||||
!empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
|
||||
0,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
$member_info[ 'nickname' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
|
||||
( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] ) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
|
||||
0,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$ground = [
|
||||
[
|
||||
'action' => 'setBackground',
|
||||
'data' => [ 255, 255, 255 ]
|
||||
]
|
||||
];
|
||||
$option = array_merge($ground, $option, $member_option);
|
||||
}
|
||||
}
|
||||
$option_res = $poster->create($option);
|
||||
if (is_array($option_res)) return $option_res;
|
||||
|
||||
$res = $option_res->jpeg('upload/poster/goods', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . time() . '_' . $app_type);
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param unknown $member_id
|
||||
*/
|
||||
private function getMemberInfo($member_id)
|
||||
{
|
||||
$info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品信息
|
||||
* @param unknown $sku_id
|
||||
*/
|
||||
private function getGoodsInfo($id)
|
||||
{
|
||||
$alias = 'nptg';
|
||||
$join = [
|
||||
[ 'goods_sku ngs', 'nptg.sku_id = ngs.sku_id', 'inner' ]
|
||||
];
|
||||
$field = 'ngs.sku_name,ngs.introduction,ngs.sku_image,ngs.sku_id,nptg.topic_price,ngs.template_id,ngs.price';
|
||||
$info = model('promotion_topic_goods')->getInfo([ 'nptg.id' => $id ], $field, $alias, $join);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品二维码
|
||||
* @param unknown $app_type 请求类型
|
||||
* @param unknown $page uniapp页面路径
|
||||
* @param unknown $qrcode_param 二维码携带参数
|
||||
* @param string $promotion_type 活动类型 null为无活动
|
||||
*/
|
||||
private function getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id)
|
||||
{
|
||||
$res = event('Qrcode', [
|
||||
'site_id' => $site_id,
|
||||
'app_type' => $app_type,
|
||||
'type' => 'create',
|
||||
'data' => $qrcode_param,
|
||||
'page' => $page,
|
||||
'qrcode_path' => 'upload/qrcode/goods',
|
||||
'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
|
||||
], true);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取海报信息
|
||||
* @param unknown $template_id
|
||||
*/
|
||||
private function getTemplateInfo($template_id)
|
||||
{
|
||||
$info = model('poster_template')->getInfo([ 'template_id' => $template_id ], 'template_id,template_status');
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
301
addon/topic/model/Topic.php
Executable file
301
addon/topic/model/Topic.php
Executable file
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\goods\Goods;
|
||||
use app\model\system\Cron;
|
||||
use app\model\upload\Upload;
|
||||
|
||||
/**
|
||||
* 专题活动
|
||||
*/
|
||||
class Topic extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 添加专题活动
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function addTopic($data)
|
||||
{
|
||||
try {
|
||||
if (empty($data[ 'goods' ])) return $this->error('', '请选择活动商品');
|
||||
$topic_goods = $data[ 'goods' ];
|
||||
unset($data[ 'goods' ]);
|
||||
|
||||
model('promotion_topic')->startTrans();
|
||||
|
||||
$data[ 'status' ] = 1;
|
||||
if (time() > $data[ 'start_time' ] && time() < $data[ 'end_time' ]) {
|
||||
$data[ 'status' ] = 2;
|
||||
}
|
||||
$topic_id = model('promotion_topic')->add($data);
|
||||
$sku_list = [];
|
||||
$goods = new Goods();
|
||||
|
||||
foreach ($topic_goods as $good_item) {
|
||||
if (count($good_item) > 1) array_multisort(array_column($good_item, 'topic_price'), SORT_ASC, $good_item);
|
||||
foreach ($good_item as $k => $sku_item) {
|
||||
$sku_list[] = [
|
||||
'topic_id' => $topic_id,
|
||||
'start_time' => $data['start_time'],
|
||||
'end_time' => $data['end_time'],
|
||||
'site_id' => $data['site_id'],
|
||||
'sku_id' => $sku_item['sku_id'],
|
||||
'topic_price' => $sku_item['topic_price'],
|
||||
'goods_id' => $sku_item['goods_id'],
|
||||
'default' => $k == 0 ? 1 : 0
|
||||
];
|
||||
}
|
||||
$goods->modifyPromotionAddon($sku_item[ 'goods_id' ], [ 'topic' => $topic_id ]);
|
||||
}
|
||||
model('promotion_topic_goods')->addList($sku_list);
|
||||
|
||||
$cron = new Cron();
|
||||
if ($data[ 'status' ] == 2) {
|
||||
$cron->addCron(1, 0, "专题活动关闭", "CloseTopic", $data[ 'end_time' ], $topic_id);
|
||||
} else {
|
||||
$cron->addCron(1, 0, "专题活动开启", "OpenTopic", $data[ 'start_time' ], $topic_id);
|
||||
$cron->addCron(1, 0, "专题活动关闭", "CloseTopic", $data[ 'end_time' ], $topic_id);
|
||||
}
|
||||
model('promotion_topic')->commit();
|
||||
return $this->success($topic_id);
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_topic')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改专题活动
|
||||
* @param $data
|
||||
* @param $site_id
|
||||
* @param $del_id
|
||||
* @return array
|
||||
*/
|
||||
public function editTopic($data, $site_id, $del_id)
|
||||
{
|
||||
try {
|
||||
if (empty($data[ 'goods' ])) return $this->error('', '请选择活动商品');
|
||||
$topic_goods = $data[ 'goods' ];
|
||||
unset($data[ 'goods' ]);
|
||||
|
||||
model('promotion_topic')->startTrans();
|
||||
|
||||
$data[ 'status' ] = 1;
|
||||
if (time() > $data[ 'start_time' ] && time() < $data[ 'end_time' ]) {
|
||||
$data[ 'status' ] = 2;
|
||||
}
|
||||
|
||||
$topic_info = model('promotion_topic')->getInfo([ [ 'topic_id', '=', $data[ 'topic_id' ] ], [ 'site_id', '=', $site_id ] ]);
|
||||
if (!empty($topic_info[ 'topic_adv' ]) && !empty($data[ 'topic_adv' ]) && $topic_info[ 'topic_adv' ] != $data[ 'topic_adv' ]) {
|
||||
$upload_model = new Upload();
|
||||
$upload_model->deletePic($topic_info[ 'topic_adv' ], $site_id);
|
||||
}
|
||||
|
||||
$res = model('promotion_topic')->update($data, [ [ 'topic_id', '=', $data[ 'topic_id' ] ], [ 'site_id', '=', $site_id ] ]);
|
||||
|
||||
if (!empty($del_id)) {
|
||||
model('promotion_topic_goods')->delete([ [ 'id', 'in', explode(',', $del_id) ], [ 'topic_id', '=', $data[ 'topic_id' ] ], [ 'site_id', '=', $site_id ] ]);
|
||||
}
|
||||
|
||||
$sku_list = [];
|
||||
foreach ($topic_goods as $good_item) {
|
||||
if (count($good_item) > 1) array_multisort(array_column($good_item, 'topic_price'), SORT_ASC, $good_item);
|
||||
foreach ($good_item as $k => $sku_item) {
|
||||
if (!empty($sku_item[ 'id' ])) {
|
||||
model('promotion_topic_goods')->update([
|
||||
'topic_price' => $sku_item[ 'topic_price' ],
|
||||
'start_time' => $data[ 'start_time' ],
|
||||
'end_time' => $data[ 'end_time' ]
|
||||
], [
|
||||
[ 'topic_id', '=', $data[ 'topic_id' ] ],
|
||||
[ 'id', '=', $sku_item[ 'id' ] ],
|
||||
[ 'goods_id', '=', $sku_item[ 'goods_id' ] ],
|
||||
[ 'sku_id', '=', $sku_item[ 'sku_id' ] ],
|
||||
]);
|
||||
} else {
|
||||
$sku_list[] = [
|
||||
'topic_id' => $data['topic_id'],
|
||||
'start_time' => $data['start_time'],
|
||||
'end_time' => $data['end_time'],
|
||||
'site_id' => $site_id,
|
||||
'sku_id' => $sku_item['sku_id'],
|
||||
'topic_price' => $sku_item['topic_price'],
|
||||
'goods_id' => $sku_item['goods_id'],
|
||||
'default' => $k == 0 ? 1 : 0
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
model('promotion_topic_goods')->addList($sku_list);
|
||||
|
||||
$cron = new Cron();
|
||||
if ($data[ 'status' ] == 2) {
|
||||
//活动商品启动
|
||||
$this->cronOpenTopic($data[ 'topic_id' ]);
|
||||
$cron->deleteCron([ [ 'event', '=', 'OpenTopic' ], [ 'relate_id', '=', $data[ 'topic_id' ] ] ]);
|
||||
$cron->deleteCron([ [ 'event', '=', 'CloseTopic' ], [ 'relate_id', '=', $data[ 'topic_id' ] ] ]);
|
||||
|
||||
$cron->addCron(1, 0, "专题活动关闭", "CloseTopic", $data[ 'end_time' ], $data[ 'topic_id' ]);
|
||||
} else {
|
||||
$cron->deleteCron([ [ 'event', '=', 'OpenTopic' ], [ 'relate_id', '=', $data[ 'topic_id' ] ] ]);
|
||||
$cron->deleteCron([ [ 'event', '=', 'CloseTopic' ], [ 'relate_id', '=', $data[ 'topic_id' ] ] ]);
|
||||
|
||||
$cron->addCron(1, 0, "专题活动开启", "OpenTopic", $data[ 'start_time' ], $data[ 'topic_id' ]);
|
||||
$cron->addCron(1, 0, "专题活动关闭", "CloseTopic", $data[ 'end_time' ], $data[ 'topic_id' ]);
|
||||
}
|
||||
model('promotion_topic')->commit();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_topic')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除专题活动
|
||||
* @param unknown $topic_id
|
||||
*/
|
||||
public function deleteTopic($topic_id, $site_id)
|
||||
{
|
||||
try {
|
||||
model('promotion_topic')->startTrans();
|
||||
|
||||
$topic_info = model('promotion_topic')->getInfo([ [ 'topic_id', '=', $topic_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
if (!empty($topic_info[ 'topic_adv' ])) {
|
||||
$upload_model = new Upload();
|
||||
$upload_model->deletePic($topic_info[ 'topic_adv' ], $site_id);
|
||||
}
|
||||
|
||||
$topic_list = model("promotion_topic_goods")->getList([ [ 'topic_id', '=', $topic_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
$goods = new Goods();
|
||||
foreach ($topic_list as $k => $v) {
|
||||
$goods->modifyPromotionAddon($v[ 'goods_id' ], [ 'topic' => $topic_id ], true);
|
||||
}
|
||||
|
||||
$res = model('promotion_topic')->delete([ [ 'topic_id', '=', $topic_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
model('promotion_topic_goods')->delete([ [ 'topic_id', '=', $topic_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
model('promotion_topic')->commit();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_topic')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题活动信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
*/
|
||||
public function getTopicInfo($condition, $field = '*')
|
||||
{
|
||||
$res = model('promotion_topic')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题活动详情
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
*/
|
||||
public function getTopicDetail($condition)
|
||||
{
|
||||
$res = model('promotion_topic')->getInfo($condition, '*');
|
||||
if (!empty($res)) {
|
||||
$alias = 'nptg';
|
||||
$join = [
|
||||
[ 'goods g', 'nptg.goods_id = g.goods_id', 'inner' ],
|
||||
[ 'goods_sku ngs', 'nptg.sku_id = ngs.sku_id', 'inner' ],
|
||||
];
|
||||
$field = 'nptg.id,nptg.sku_id,nptg.topic_price,nptg.goods_id,ngs.price,ngs.stock,ngs.sku_name,ngs.sku_image';
|
||||
$res[ 'goods_list' ] = model('promotion_topic_goods')->getList([ [ 'nptg.topic_id', '=', $res[ 'topic_id' ] ], [ 'g.goods_state', '=', 1 ], [ 'g.is_delete', '=', 0 ] ], $field, 'id asc', $alias, $join);
|
||||
foreach ($res[ 'goods_list' ] as $k => $v) {
|
||||
$res[ 'goods_list' ][ $k ][ 'stock' ] = numberFormat($res[ 'goods_list' ][ $k ][ 'stock' ]);
|
||||
}
|
||||
$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 getTopicList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('promotion_topic')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题分页列表
|
||||
* @param array $condition
|
||||
* @param number $page
|
||||
* @param string $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getTopicPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'modify_time desc,create_time desc', $field = '*')
|
||||
{
|
||||
$list = model('promotion_topic')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启专题活动
|
||||
* @param $groupbuy_id
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function cronOpenTopic($topic_id)
|
||||
{
|
||||
$topic_info = model('promotion_topic')->getInfo([ [ 'topic_id', '=', $topic_id ] ], 'start_time,status');
|
||||
if (!empty($topic_info)) {
|
||||
if ($topic_info[ 'start_time' ] <= time() && $topic_info[ 'status' ] == 1) {
|
||||
$res = model('promotion_topic')->update([ 'status' => 2 ], [ [ 'topic_id', '=', $topic_id ] ]);
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error("", "专题活动已开启或者关闭");
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->error("", "专题活动不存在");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭专题活动
|
||||
* @param $groupbuy_id
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function cronCloseTopic($topic_id)
|
||||
{
|
||||
$topic_info = model('promotion_topic')->getInfo([ [ 'topic_id', '=', $topic_id ] ], 'start_time,status');
|
||||
if (!empty($topic_info)) {
|
||||
if ($topic_info[ 'status' ] != 3) {
|
||||
$res = model('promotion_topic')->update([ 'status' => 3 ], [ [ 'topic_id', '=', $topic_id ] ]);
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error("", "该活动已结束");
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->error("", "专题活动不存在");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
216
addon/topic/model/TopicGoods.php
Executable file
216
addon/topic/model/TopicGoods.php
Executable file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\goods\Goods;
|
||||
|
||||
/**
|
||||
* 专题活动
|
||||
*/
|
||||
class TopicGoods extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 添加专题商品
|
||||
* @param $topic_id
|
||||
* @param $site_id
|
||||
* @param $sku_ids
|
||||
* @return array
|
||||
*/
|
||||
public function addTopicGoods($topic_id, $site_id, $sku_ids)
|
||||
{
|
||||
$sku_list = model('goods_sku')->getList([
|
||||
[ 'sku_id', 'in', $sku_ids ],
|
||||
[ 'site_id', '=', $site_id ],
|
||||
], 'goods_id, sku_id, price');
|
||||
$topic_info = model("promotion_topic")->getInfo([ [ 'topic_id', '=', $topic_id ] ], 'start_time, end_time');
|
||||
$data = [];
|
||||
$goods = new Goods();
|
||||
foreach ($sku_list as $val) {
|
||||
$goods_count = model("promotion_topic_goods")->getCount([ 'topic_id' => $topic_id, 'sku_id' => $val[ 'sku_id' ] ]);
|
||||
if (empty($goods_count)) {
|
||||
$data[] = [
|
||||
'topic_id' => $topic_id,
|
||||
'site_id' => $site_id,
|
||||
'sku_id' => $val[ 'sku_id' ],
|
||||
'topic_price' => $val[ 'price' ],
|
||||
'start_time' => $topic_info[ 'start_time' ],
|
||||
'end_time' => $topic_info[ 'end_time' ]
|
||||
];
|
||||
$goods->modifyPromotionAddon($val[ 'goods_id' ], [ 'topic' => $topic_id ]);
|
||||
}
|
||||
}
|
||||
model("promotion_topic_goods")->addList($data);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改专题商品
|
||||
* @param $topic_id
|
||||
* @param $site_id
|
||||
* @param $sku_id
|
||||
* @param $price
|
||||
* @return array
|
||||
*/
|
||||
public function editTopicGoods($topic_id, $site_id, $sku_id, $price)
|
||||
{
|
||||
$data = [
|
||||
'topic_id' => $topic_id,
|
||||
'site_id' => $site_id,
|
||||
'sku_id' => $sku_id,
|
||||
'topic_price' => $price
|
||||
];
|
||||
model("promotion_topic_goods")->update($data, [ [ 'topic_id', '=', $topic_id ], [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除专题商品
|
||||
* @param $topic_id
|
||||
* @param $site_id
|
||||
* @param $sku_id
|
||||
* @return array
|
||||
*/
|
||||
public function deleteTopicGoods($topic_id, $site_id, $sku_id)
|
||||
{
|
||||
$goods_sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $sku_id ] ], 'goods_id');
|
||||
$goods = new Goods();
|
||||
$goods->modifyPromotionAddon($goods_sku_info[ 'goods_id' ], [ 'topic' => $topic_id ], true);
|
||||
model("promotion_topic_goods")->delete([ [ 'topic_id', '=', $topic_id ], [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
public function getTopicIdByGoodsId($topic_id, $sku_id)
|
||||
{
|
||||
$info = model("promotion_topic_goods")->getInfo([ [ 'topic_id', '=', $topic_id ], [ 'sku_id', '=', $sku_id ]], 'id');
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题商品详情
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getTopicGoodsDetail($condition, $field = '')
|
||||
{
|
||||
if (empty($field)) {
|
||||
$field = 'sku.goods_id,sku.sku_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.promotion_type,sku.stock,sku.click_num,
|
||||
(g.sale_num + g.virtual_sale) as sale_num,sku.collect_num,sku.sku_image,sku.sku_images,sku.site_id,sku.goods_content,
|
||||
sku.goods_state,sku.is_virtual,sku.is_free_shipping,sku.goods_spec_format,sku.goods_attr_format,sku.introduction,
|
||||
sku.support_trade_type,sku.unit,sku.video_url,sku.evaluate,sku.goods_service_ids,ptg.id,ptg.topic_id,ptg.start_time,
|
||||
ptg.end_time,ptg.topic_price,pt.topic_name,g.goods_image,g.goods_stock,g.goods_name,sku.qr_id,sku.market_price,
|
||||
g.stock_show,g.sale_show,g.market_price_show,g.barrage_show,g.label_name,pt.remark';
|
||||
}
|
||||
$alias = 'ptg';
|
||||
$join = [
|
||||
[ 'goods_sku sku', 'ptg.sku_id = sku.sku_id', 'inner' ],
|
||||
[ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ],
|
||||
[ 'promotion_topic pt', 'pt.topic_id = ptg.topic_id', 'inner' ],
|
||||
];
|
||||
|
||||
$info = model('promotion_topic_goods')->getInfo($condition, $field, $alias, $join);
|
||||
if (!empty($info)) {
|
||||
if (isset($info[ 'sale_num' ])) {
|
||||
$info[ 'sale_num' ] = numberFormat($info[ 'sale_num' ]);
|
||||
}
|
||||
if (isset($info[ 'stock' ])) {
|
||||
$info[ 'stock' ] = numberFormat($info[ 'stock' ]);
|
||||
}
|
||||
if (isset($info[ 'goods_stock' ])) {
|
||||
$info[ 'goods_stock' ] = numberFormat($info[ 'goods_stock' ]);
|
||||
}
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题商品详情
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getTopicGoodsSkuList($condition)
|
||||
{
|
||||
$field = 'sku.sku_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.stock,sku.sku_image,sku.sku_images,sku.goods_spec_format,ptg.id,ptg.topic_id,ptg.start_time,ptg.end_time,ptg.topic_price,pt.topic_name,g.goods_image';
|
||||
$alias = 'ptg';
|
||||
$join = [
|
||||
[ 'goods_sku sku', 'ptg.sku_id = sku.sku_id', 'inner' ],
|
||||
[ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ],
|
||||
[ 'promotion_topic pt', 'pt.topic_id = ptg.topic_id', 'inner' ],
|
||||
];
|
||||
|
||||
$list = model('promotion_topic_goods')->getList($condition, $field, 'ptg.id asc', $alias, $join);
|
||||
foreach ($list as $k => $v) {
|
||||
$list[ $k ][ 'stock' ] = numberFormat($list[ $k ][ 'stock' ]);
|
||||
}
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题商品列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTopicGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '')
|
||||
{
|
||||
$alias = 'nptg';
|
||||
if (empty($field)) {
|
||||
$field = 'ngs.sku_id, ngs.sku_name, ngs.sku_no, ngs.sku_spec_format, ngs.price, ngs.market_price,
|
||||
ngs.cost_price, ngs.discount_price, ngs.promotion_type, ngs.stock,
|
||||
ngs.weight, ngs.volume, ngs.click_num, (g.sale_num + g.virtual_sale) as sale_num, ngs.collect_num, ngs.sku_image,
|
||||
ngs.sku_images, ngs.goods_id, ngs.goods_class, ngs.goods_class_name, ngs.goods_attr_class,
|
||||
ngs.goods_attr_name, ngs.goods_name,ngs.goods_state,
|
||||
ngs.is_virtual, ngs.virtual_indate, ngs.is_free_shipping, ngs.shipping_template, ngs.goods_spec_format,
|
||||
ngs.goods_attr_format, ngs.is_delete, ngs.introduction, ngs.keywords, ngs.unit, ngs.sort,npt.topic_name,
|
||||
npt.topic_adv, npt.status, nptg.id,nptg.start_time, nptg.end_time, nptg.topic_price, npt.topic_id, g.stock_show,g.sale_show,g.market_price_show';
|
||||
}
|
||||
$join = [
|
||||
[ 'goods g', 'nptg.goods_id = g.goods_id', 'inner' ],
|
||||
[ 'goods_sku ngs', 'nptg.sku_id = ngs.sku_id', 'inner' ],
|
||||
[ 'promotion_topic npt', 'nptg.topic_id = npt.topic_id', 'inner' ],
|
||||
];
|
||||
$res = model('promotion_topic_goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
foreach ($res[ 'list' ] as $k => $v) {
|
||||
if (isset($v[ 'stock' ])) {
|
||||
$res[ 'list' ][ $k ][ 'stock' ] = numberFormat($res[ 'list' ][ $k ][ 'stock' ]);
|
||||
}
|
||||
if (isset($v[ 'sale_num' ])) {
|
||||
$res[ 'list' ][ $k ][ 'sale_num' ] = numberFormat($res[ 'list' ][ $k ][ 'sale_num' ]);
|
||||
}
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断规格值是否禁用
|
||||
* @param $topic_id
|
||||
* @param $site_id
|
||||
* @param string $goods_spec_format
|
||||
* @param int $sku_id
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getGoodsSpecFormat($topic_id, $site_id, $goods_spec_format = '')
|
||||
{
|
||||
//获取活动参与的商品sku_ids
|
||||
$sku_ids = model('promotion_topic_goods')->getColumn([ [ 'topic_id', '=', $topic_id ], [ 'site_id', '=', $site_id ] ], 'sku_id');
|
||||
$goods_model = new Goods();
|
||||
$res = $goods_model->getGoodsSpecFormat($sku_ids, $goods_spec_format);
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
255
addon/topic/model/TopicOrderCreate.php
Executable file
255
addon/topic/model/TopicOrderCreate.php
Executable file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\goods\GoodsStock;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\store\Store;
|
||||
use extend\exception\OrderException;
|
||||
use think\facade\Cache;
|
||||
use app\model\express\Express;
|
||||
use app\model\system\Pay;
|
||||
use app\model\express\Config as ExpressConfig;
|
||||
use app\model\order\Config;
|
||||
use app\model\express\Local;
|
||||
|
||||
/**
|
||||
* 订单创建(专题)
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class TopicOrderCreate extends BaseModel
|
||||
{
|
||||
|
||||
use OrderCreateTool;
|
||||
public $topic_id = 0;
|
||||
public $topic_info = [];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->promotion_type = 'topic';
|
||||
$this->promotion_type_name = '专题';
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//计算
|
||||
$this->confirm();
|
||||
if ($this->error > 0) {
|
||||
return $this->error([ 'error_code' => $this->error ], $this->error_msg);
|
||||
}
|
||||
//订单创建数据
|
||||
$order_insert_data = $this->getOrderInsertData([ 'discount' ], 'invert');
|
||||
$order_insert_data[ 'store_id' ] = $this->store_id;
|
||||
$order_insert_data[ 'create_time' ] = time();
|
||||
$order_insert_data[ 'is_enable_refund' ] = 0;
|
||||
//订单类型以及状态
|
||||
$this->orderType();
|
||||
$order_insert_data[ 'order_type' ] = $this->order_type[ 'order_type_id' ];
|
||||
$order_insert_data[ 'order_type_name' ] = $this->order_type[ 'order_type_name' ];
|
||||
$order_insert_data[ 'order_status_name' ] = $this->order_type[ 'order_status' ][ 'name' ];
|
||||
$order_insert_data[ 'order_status_action' ] = json_encode($this->order_type[ 'order_status' ], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
model('order')->startTrans();
|
||||
//循环生成多个订单
|
||||
try {
|
||||
$this->order_id = model('order')->add($order_insert_data);
|
||||
$order_goods_insert_data = [];
|
||||
//订单项目表
|
||||
foreach ($this->goods_list as &$order_goods_v) {
|
||||
$order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
|
||||
}
|
||||
model('order_goods')->addList($order_goods_insert_data);
|
||||
|
||||
//扣除余额(统一扣除)
|
||||
$this->useBalance();
|
||||
//批量库存处理(卡密商品支付后在扣出库存)
|
||||
$this->batchDecOrderGoodsStock();
|
||||
|
||||
model('order')->commit();
|
||||
//订单创建后事件
|
||||
$this->orderCreateAfter();
|
||||
//支付单据
|
||||
$pay = new Pay();
|
||||
$pay->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '', $this->order_id, $this->member_id);
|
||||
return $this->success($this->out_trade_no);
|
||||
} catch (\Exception $e) {
|
||||
model('order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算后的进一步计算(不存缓存,每次都是重新计算)
|
||||
* @return array
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$order_key = $this->param[ 'order_key' ];
|
||||
$this->getOrderCache($order_key);
|
||||
//初始化地址
|
||||
$this->initMemberAddress();
|
||||
//初始化门店信息
|
||||
$this->initStore();
|
||||
//配送计算
|
||||
$this->calculateDelivery();
|
||||
//批量校验配送方式
|
||||
$this->batchCheckDeliveryType();
|
||||
//计算发票相关
|
||||
$this->calculateInvoice();
|
||||
//计算余额
|
||||
$this->calculateBalcnce();
|
||||
$this->pay_money = $this->order_money - $this->balance_money;
|
||||
//设置过的商品项信息
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单计算
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
//初始化地址
|
||||
$this->initMemberAddress();
|
||||
//初始化会员账户
|
||||
$this->initMemberAccount();
|
||||
|
||||
//商品列表信息
|
||||
$this->getOrderGoodsCalculate();
|
||||
|
||||
//查询专题信息
|
||||
$topic_model = new Topic();
|
||||
|
||||
$this->topic_info = $topic_model->getTopicInfo([ [ 'topic_id', '=', $this->topic_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? [];
|
||||
if (empty($this->topic_info)) throw new OrderException('找不到可用的专题活动!');
|
||||
|
||||
//判断时间段是否符合
|
||||
$time = time();//当日时间戳
|
||||
|
||||
if ($this->topic_info[ 'status' ] != 2 || ($time < $this->topic_info[ 'start_time' ] || $time > $this->topic_info[ 'end_time' ])) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '当前商品专题活动未开启!';
|
||||
}
|
||||
|
||||
$this->shopOrderCalculate();
|
||||
|
||||
//获取发票相关
|
||||
$this->getInovice();
|
||||
$this->order_key = create_no();
|
||||
$this->setOrderCache(get_object_vars($this), $this->order_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 待付款订单
|
||||
*/
|
||||
public function orderPayment()
|
||||
{
|
||||
//计算
|
||||
$this->calculate();
|
||||
//配送数据
|
||||
$this->getDeliveryData();
|
||||
//订单初始项
|
||||
event('OrderPayment', [ 'order_object' => $this ]);
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的计算信息
|
||||
*/
|
||||
public function getOrderGoodsCalculate()
|
||||
{
|
||||
$this->getTopicGoodsInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题商品信息
|
||||
* @return array
|
||||
*/
|
||||
public function getTopicGoodsInfo()
|
||||
{
|
||||
$id = $this->param[ 'id' ];
|
||||
$num = $this->param[ 'num' ];
|
||||
//组装商品列表
|
||||
$field = 'ptg.sku_id,ptg.id,ptg.topic_id,ptg.topic_price,ngs.sku_name, ngs.sku_no,
|
||||
ngs.price, ngs.discount_price, ngs.cost_price, ngs.stock, ngs.weight, ngs.volume, ngs.sku_image,
|
||||
ngs.site_id, ns.site_name, ngs.goods_state, ngs.is_virtual, ngs.support_trade_type,ngs.supplier_id,ngs.form_id,
|
||||
ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name, ngs.goods_id,ngs.sku_spec_format,ngs.goods_name';
|
||||
$alias = 'ptg';
|
||||
$join = [
|
||||
[
|
||||
'goods_sku ngs',
|
||||
'ptg.sku_id = ngs.sku_id',
|
||||
'inner'
|
||||
],
|
||||
[
|
||||
'site ns',
|
||||
'ngs.site_id = ns.site_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
$info = model('promotion_topic_goods')->getInfo([ [ 'ptg.id', '=', $id ], [ 'ptg.site_id', '=', $this->site_id ] ], $field, $alias, $join);
|
||||
|
||||
if (empty($info)) throw new OrderException('商品不存在!');
|
||||
//判断是否是虚拟订单
|
||||
if ($info[ 'is_virtual' ]) {
|
||||
$this->is_virtual = 1;
|
||||
} else {
|
||||
$this->is_virtual = 0;
|
||||
}
|
||||
$this->topic_id = $info[ 'topic_id' ];
|
||||
$info[ 'stock' ] = numberFormat($info[ 'stock' ]);
|
||||
$info[ 'num' ] = $num;
|
||||
$price = $info[ 'topic_price' ];
|
||||
$info[ 'price' ] = $price;
|
||||
$goods_money = $price * $info[ 'num' ];
|
||||
$info[ 'goods_money' ] = $goods_money;
|
||||
$info[ 'real_goods_money' ] = $goods_money;//真实商品金额
|
||||
$info[ 'coupon_money' ] = 0;//优惠券金额
|
||||
$info[ 'promotion_money' ] = 0;//优惠金额
|
||||
|
||||
$this->site_name = $info[ 'site_name' ];
|
||||
$this->goods_money = $goods_money;
|
||||
$this->goods_list_str = $info[ 'sku_id' ] . ':' . $info[ 'num' ];
|
||||
$this->order_name = string_split('', ',', $info[ 'sku_name' ]);
|
||||
$this->goods_num = $info[ 'num' ];
|
||||
$this->goods_list[] = $info;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺订单计算
|
||||
*/
|
||||
public function shopOrderCalculate()
|
||||
{
|
||||
//重新计算订单总额
|
||||
$this->getOrderMoney();
|
||||
//理论上是多余的操作
|
||||
if ($this->order_money < 0) {
|
||||
$this->order_money = 0;
|
||||
}
|
||||
//总结计算
|
||||
$this->pay_money = $this->order_money;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
181
addon/topic/model/share/WchatShare.php
Executable file
181
addon/topic/model/share/WchatShare.php
Executable file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\model\share;
|
||||
|
||||
use addon\topic\model\Topic as TopicModel;
|
||||
use app\model\share\WchatShareBase as BaseModel;
|
||||
use addon\topic\model\TopicGoods as TopicGoodsModel;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WchatShare extends BaseModel
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '专题列表',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_TOPIC_LIST',
|
||||
'path' => [ '/pages_promotion/topics/list' ],
|
||||
'method_prefix' => 'topicList',
|
||||
],
|
||||
[
|
||||
'title' => '专题详情',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_TOPIC_DETAIL',
|
||||
'path' => [ '/pages_promotion/topics/detail' ],
|
||||
'method_prefix' => 'topicDetail',
|
||||
],
|
||||
[
|
||||
'title' => '专题商品详情',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_TOPIC_GOODS_DETAIL',
|
||||
'path' => [ '/pages_promotion/topics/goods_detail' ],
|
||||
'method_prefix' => 'goodsDetail',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 9;
|
||||
|
||||
/**
|
||||
* 专题列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function topicListShareData($param)
|
||||
{
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
$config_data = $this->topicListShareConfig($param)[ 'value' ];
|
||||
|
||||
$data = [
|
||||
'link' => $link,
|
||||
'desc' => $config_data[ 'desc' ],
|
||||
'imgUrl' => $config_data[ 'imgUrl' ],
|
||||
'title' => $config_data[ 'title' ]
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 专题列表分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function topicListShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => "专题列表",
|
||||
'desc' => "更多活动\n快来参与",
|
||||
'imgUrl' => ''
|
||||
];
|
||||
}
|
||||
if (empty($data[ 'value' ][ 'imgUrl' ])) {
|
||||
$data[ 'value' ][ 'imgUrl' ] = img('addon/topic/icon.png');
|
||||
}
|
||||
return [
|
||||
'value' => $data[ 'value' ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 专题详情
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function topicDetailShareData($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
//链接参数
|
||||
parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
|
||||
if (isset($query[ 'topic_id' ])) {
|
||||
$topic_model = new TopicModel();
|
||||
$topic_detail = $topic_model->getTopicDetail([
|
||||
[ 'topic_id', '=', $query[ 'topic_id' ] ],
|
||||
[ 'site_id', '=', $site_id ],
|
||||
])[ 'data' ];
|
||||
if (!empty($topic_detail)) {
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
$data = [
|
||||
'link' => $link,
|
||||
'desc' => $topic_detail[ 'remark' ],
|
||||
'imgUrl' => img($topic_detail[ 'topic_adv' ]),
|
||||
'title' => $topic_detail[ 'topic_name' ],
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 专题分享数据
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsDetailShareData($param)
|
||||
{
|
||||
$url = $param[ 'url' ];
|
||||
|
||||
$parse_res = parse_url($url);
|
||||
parse_str($parse_res[ 'query' ] ?? '', $query);
|
||||
|
||||
if (isset($query[ 'id' ]) || isset($query[ 'topic_id' ])) {
|
||||
$id = $query['id'] ?? $query['topic_id'];
|
||||
$goods = new TopicGoodsModel();
|
||||
$condition = [
|
||||
[ 'ptg.id', '=', $id ],
|
||||
[ 'pt.status', '=', 2 ]
|
||||
];
|
||||
$sku_info = $goods->getTopicGoodsDetail($condition)[ 'data' ];
|
||||
if (!empty($sku_info)) {
|
||||
$config_model = new \app\model\share\WchatShare();
|
||||
$config_data = $config_model->goodsDetailShareConfig($param);
|
||||
|
||||
$title = str_replace('{goods_name}', $sku_info[ 'sku_name' ], $config_data[ 'value' ][ 'title' ]);
|
||||
$desc = str_replace('{price}', $sku_info[ 'topic_price' ], $config_data[ 'value' ][ 'desc' ]);
|
||||
$link = $this->getShareLink($param);
|
||||
$image_url = $sku_info[ 'sku_image' ];
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'desc' => $desc,
|
||||
'link' => $link,
|
||||
'imgUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
90
addon/topic/model/share/WeappShare.php
Executable file
90
addon/topic/model/share/WeappShare.php
Executable file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\model\share;
|
||||
|
||||
use app\model\share\WeappShareBase;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WeappShare extends WeappShareBase
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '专题列表',
|
||||
'config_key' => 'WEAPP_SHARE_CONFIG_TOPIC_LIST',
|
||||
'path' => ['/pages_promotion/topics/list'],
|
||||
'method_prefix' => 'topicList',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 10;
|
||||
|
||||
/**
|
||||
* 专题列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function topicListShareData($param)
|
||||
{
|
||||
//获取和替换配置数据
|
||||
$config_data = $this->topicListShareConfig($param);
|
||||
$title = $config_data['value']['title'];
|
||||
$image_url = $config_data['value']['imageUrl'] ? img($config_data['value']['imageUrl']) : '';
|
||||
$path = $this->getSharePath($param);
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'path' => $path,
|
||||
'imageUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'onShareAppMessage' => true,
|
||||
'onShareTimeline' => true,
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 专题列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function topicListShareConfig($param)
|
||||
{
|
||||
$site_id = $param['site_id'];
|
||||
$config = $param['config'];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([
|
||||
['site_id', '=', $site_id],
|
||||
['app_module', '=', 'shop'],
|
||||
['config_key', '=', $config['config_key']],
|
||||
])['data'];
|
||||
if (empty($data['value'])) {
|
||||
$data['value'] = [
|
||||
'title' => '来看看有哪些你想要的商品吧',
|
||||
'imageUrl' => '',
|
||||
];
|
||||
}
|
||||
$variable = [];
|
||||
|
||||
return [
|
||||
'value' => $data['value'],
|
||||
'variable' => $variable,
|
||||
];
|
||||
}
|
||||
}
|
||||
183
addon/topic/shop/controller/Topic.php
Executable file
183
addon/topic/shop/controller/Topic.php
Executable file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\topic\shop\controller;
|
||||
|
||||
use app\shop\controller\BaseShop;
|
||||
use addon\topic\model\Topic as TopicModel;
|
||||
|
||||
/**
|
||||
* 专题活动
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class Topic extends BaseShop
|
||||
{
|
||||
/**
|
||||
* 专题活动列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$page = input('page', 1);
|
||||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||||
$topic_name = input('topic_name', '');
|
||||
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
if ($topic_name) {
|
||||
$condition[] = [ 'topic_name', 'like', '%' . $topic_name . '%' ];
|
||||
}
|
||||
$status = input('status', '');
|
||||
if ($status !== '') {
|
||||
$condition[] = [ 'status', '=', $status ];
|
||||
}
|
||||
$order = 'create_time desc';
|
||||
$field = '*';
|
||||
|
||||
$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) ];
|
||||
}
|
||||
|
||||
$topic_model = new TopicModel();
|
||||
$res = $topic_model->getTopicPageList($condition, $page, $page_size, $order, $field);
|
||||
return $res;
|
||||
} else {
|
||||
return $this->fetch("topic/lists");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加专题活动
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$topic_name = input("topic_name", '');
|
||||
$start_time = input("start_time", 0);
|
||||
$end_time = input("end_time", 0);
|
||||
$remark = input("remark", '');
|
||||
$topic_adv = input("topic_adv", '');
|
||||
$bg_color = input("bg_color", '#ffffff');
|
||||
$goods = input("goods", '{}');
|
||||
$topic_model = new TopicModel();
|
||||
$data = array (
|
||||
'site_id' => $this->site_id,
|
||||
"topic_name" => $topic_name,
|
||||
"start_time" => $start_time,
|
||||
"end_time" => $end_time,
|
||||
"remark" => $remark,
|
||||
"topic_adv" => $topic_adv,
|
||||
'bg_color' => $bg_color,
|
||||
'goods' => json_decode($goods, true),
|
||||
'create_time' => time()
|
||||
);
|
||||
$res = $topic_model->addTopic($data);
|
||||
return $res;
|
||||
} else {
|
||||
return $this->fetch("topic/add");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑专题活动
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$topic_id = input("topic_id", '');
|
||||
$topic_model = new TopicModel();
|
||||
if (request()->isJson()) {
|
||||
$topic_name = input("topic_name", '');
|
||||
$start_time = input("start_time", 0);
|
||||
$end_time = input("end_time", 0);
|
||||
$remark = input("remark", '');
|
||||
$topic_adv = input("topic_adv", '');
|
||||
$bg_color = input("bg_color", '#ffffff');
|
||||
$goods = input("goods", '{}');
|
||||
$del_id = input('del_id', '');
|
||||
$data = array (
|
||||
"topic_name" => $topic_name,
|
||||
"start_time" => $start_time,
|
||||
"end_time" => $end_time,
|
||||
"remark" => $remark,
|
||||
"topic_adv" => $topic_adv,
|
||||
"topic_id" => $topic_id,
|
||||
'bg_color' => $bg_color,
|
||||
'goods' => json_decode($goods, true),
|
||||
'modify_time' => time()
|
||||
);
|
||||
$res = $topic_model->editTopic($data, $this->site_id, $del_id);
|
||||
return $res;
|
||||
} else {
|
||||
$condition = array (
|
||||
[ "topic_id", "=", $topic_id ]
|
||||
);
|
||||
$topic_info_result = $topic_model->getTopicDetail($condition);
|
||||
if (empty($topic_info_result[ 'data' ])) $this->error('未获取到活动数据', href_url('topic://shop/topic/lists'));
|
||||
$this->assign("info", $topic_info_result[ "data" ]);
|
||||
$this->assign('sku_ids', implode(',', array_column($topic_info_result[ 'data' ][ 'goods_list' ], 'sku_id')));
|
||||
return $this->fetch("topic/edit");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看专题活动
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$topic_id = input("topic_id", '');
|
||||
$topic_model = new TopicModel();
|
||||
|
||||
$condition = array (
|
||||
[ "topic_id", "=", $topic_id ]
|
||||
);
|
||||
$topic_info_result = $topic_model->getTopicDetail($condition);
|
||||
if (empty($topic_info_result[ 'data' ])) $this->error('未获取到活动数据', href_url('topic://shop/topic/lists'));
|
||||
$this->assign("info", $topic_info_result[ "data" ]);
|
||||
$this->assign('sku_ids', implode(',', array_column($topic_info_result[ 'data' ][ 'goods_list' ], 'sku_id')));
|
||||
return $this->fetch("topic/detail");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除专题活动
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$topic_id = input("topic_id", '');
|
||||
$topic_model = new TopicModel();
|
||||
$res = $topic_model->deleteTopic($topic_id, $this->site_id);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除专题活动(批量)
|
||||
*/
|
||||
public function deleteAll(){
|
||||
if (request()->isJson()) {
|
||||
$topic_id = input("topic_id", '');
|
||||
$topic_model = new TopicModel();
|
||||
foreach ($topic_id as $k => $v){
|
||||
$res = $topic_model->deleteTopic($v, $this->site_id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
addon/topic/shop/view/public/img/zone_preview.png
Executable file
BIN
addon/topic/shop/view/public/img/zone_preview.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 144 KiB |
355
addon/topic/shop/view/topic/add.html
Executable file
355
addon/topic/shop/view/topic/add.html
Executable file
@@ -0,0 +1,355 @@
|
||||
<style>
|
||||
.layui-form-item .layui-input-inline.end-time{float: none;}
|
||||
.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;}
|
||||
.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="topic_name" lay-verify="required" autocomplete="off" class="layui-input len-long" maxlength="40">
|
||||
</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">
|
||||
<input type="text" id="start_time" name="start_time" lay-verify="required" class="layui-input len-mid" autocomplete="off">
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
<span class="layui-form-mid">-</span>
|
||||
<div class="layui-input-inline end-time">
|
||||
<input type="text" id="end_time" name="end_time" lay-verify="required|time" class="layui-input len-mid" autocomplete="off">
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">横幅图片:</label>
|
||||
<div class="layui-input-inline img-upload">
|
||||
<div class="upload-img-block icon">
|
||||
<div class="upload-img-box">
|
||||
<div class="upload-default" id="webLogoUpload">
|
||||
<div class="upload">
|
||||
<i class="iconfont iconshangchuan"></i>
|
||||
<p>点击上传</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="operation">
|
||||
<div>
|
||||
<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
|
||||
<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
|
||||
</div>
|
||||
|
||||
<div class="replace_img js-replace">点击替换</div>
|
||||
</div>
|
||||
<input type="hidden" name="topic_adv" />
|
||||
</div>
|
||||
<!-- <p id="webLogoUpload" class="no-replace">替换</p>
|
||||
<input type="hidden" name="topic_adv" />
|
||||
<i class="del">x</i> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">活动内容:</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea class="layui-textarea len-long" name="remark" maxlength="300"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>商品:</label>
|
||||
<div class="layui-input-block">
|
||||
<table class="layui-table" id="goods" lay-skin="line" lay-size="lg">
|
||||
<colgroup>
|
||||
<col width="40%">
|
||||
<col width="15%">
|
||||
<col width="15%">
|
||||
<col width="15%">
|
||||
<col width="15%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>商品名称</th>
|
||||
<th>库存</th>
|
||||
<th>价格</th>
|
||||
<th>活动价格</th>
|
||||
<th class="operation">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="goods-empty">
|
||||
<td colspan="5">
|
||||
<div>未添加商品</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="layui-btn" onclick="addGoods()">添加商品</button>
|
||||
<span class="goods_num">已选商品(<span id="goods_num" class="text-color">0</span>)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
|
||||
<a id="webLogoUploadImage"></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var selectGoodsSkuId = [];
|
||||
var saveData = null;
|
||||
var totalUploadNum = 0;
|
||||
var completeUploadNum = 0;
|
||||
var upload;
|
||||
|
||||
layui.use(['form','laydate','colorpicker'], function() {
|
||||
var form = layui.form,
|
||||
laydate = layui.laydate,
|
||||
colorpicker = layui.colorpicker,
|
||||
currentDate = new Date(),
|
||||
minDate = "",
|
||||
repeat_flag = false;//防重复标识
|
||||
|
||||
currentDate.setDate(currentDate.getDate() + 30);
|
||||
form.render();
|
||||
|
||||
upload = new Upload({
|
||||
elem: '#webLogoUpload',
|
||||
auto:false,
|
||||
bindAction:'#webLogoUploadImage',
|
||||
callback: function(res) {
|
||||
uploadComplete('topic_adv', res.data.pic_path);
|
||||
}
|
||||
});
|
||||
|
||||
function uploadComplete(field, pic_path) {
|
||||
saveData.field[field] = pic_path;
|
||||
completeUploadNum += 1;
|
||||
if(completeUploadNum == totalUploadNum){
|
||||
saveFunc();
|
||||
}
|
||||
}
|
||||
|
||||
function saveFunc(){
|
||||
if(repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
var data = saveData;
|
||||
$.ajax({
|
||||
url: ns.url("topic://shop/topic/add"),
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
success: function(res){
|
||||
repeat_flag = false;
|
||||
if(res.code == 0){
|
||||
layer.confirm('添加成功',{
|
||||
title: '操作提示',
|
||||
btn: ['返回列表', '继续添加'],
|
||||
closeBtn: 0,
|
||||
yes: function(index, layero) {
|
||||
location.hash = ns.hash("topic://shop/topic/lists");
|
||||
layer.close(index);
|
||||
},btn2: function(index, layero) {
|
||||
listenerHash(); // 刷新页面
|
||||
layer.close(index);
|
||||
}
|
||||
})
|
||||
}else{
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
*/
|
||||
colorpicker.render({
|
||||
elem: '#colorpicker', //绑定元素
|
||||
color: "#FFFFFF",
|
||||
done: function(color) {
|
||||
$("#bg_color").val(color);
|
||||
}
|
||||
});
|
||||
|
||||
//开始时间
|
||||
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" > ');
|
||||
laydate.render({
|
||||
elem: '#end_time',
|
||||
type: 'datetime',
|
||||
min: minDate
|
||||
});
|
||||
}
|
||||
|
||||
form.verify({
|
||||
topic_price: function(value, item) {
|
||||
var price = $(item).parents("tr").find(".goods-price").text();
|
||||
|
||||
if (value.trim() == "") {
|
||||
return '活动价格不能为空';
|
||||
}
|
||||
if (parseFloat(value) <= 0) {
|
||||
return '活动价格必须大于0';
|
||||
}
|
||||
if (parseFloat(value) > parseFloat(price)) {
|
||||
return '活动价格不能大于商品价格';
|
||||
}
|
||||
|
||||
var pattern = /^[0-9]+(\.[0-9]{1,2})?$/;
|
||||
if(!pattern.test(value)){
|
||||
return '请输入正确格式';
|
||||
}
|
||||
|
||||
var arrMen = value.split(".");
|
||||
var val = 0;
|
||||
if (arrMen.length == 2) {
|
||||
val = arrMen[1];
|
||||
}
|
||||
if (val.length > 2) {
|
||||
return '活动价格最多保留两位小数';
|
||||
}
|
||||
},
|
||||
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 '结束时间不能小于开始时间!';
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
form.on("submit(save)",function(data){
|
||||
data.field.start_time = ns.date_to_time(data.field.start_time);
|
||||
data.field.end_time = ns.date_to_time(data.field.end_time);
|
||||
// 删除图片
|
||||
if(!data.field.topic_adv) upload.delete();
|
||||
if ($('#goods tbody tr[data-sku-id]').length == 0) {
|
||||
layer.msg('请选择商品', {icon: 5});
|
||||
return;
|
||||
}
|
||||
var goods = {};
|
||||
$('#goods tbody tr[data-sku-id]').each(function(){
|
||||
var item = {
|
||||
goods_id : $(this).attr('data-goods-id'),
|
||||
sku_id : $(this).attr('data-sku-id'),
|
||||
topic_price : $(this).find('.topic-price').val()
|
||||
};
|
||||
if (!goods['goods_' + item.goods_id]) goods['goods_' + item.goods_id] = [];
|
||||
goods['goods_' + item.goods_id].push(item);
|
||||
});
|
||||
data.field.goods = JSON.stringify(goods);
|
||||
|
||||
saveData = data;
|
||||
var obj = $("img.img_prev[data-prev='1']");
|
||||
totalUploadNum = obj.length;
|
||||
if(totalUploadNum > 0){
|
||||
obj.each(function(){
|
||||
var actionId = $(this).attr('data-action-id');
|
||||
$(actionId).click();
|
||||
})
|
||||
}else{
|
||||
saveFunc();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* 添加商品
|
||||
*/
|
||||
function addGoods() {
|
||||
goodsSelect(function (data) {
|
||||
if (Object.keys(data).length == 0) {
|
||||
selectGoodsSkuId = [];
|
||||
$('.goods-empty').show();
|
||||
$("#goods_num").text(selectGoodsSkuId.length);
|
||||
$("#goods tbody tr:not(.goods-empty)").remove();
|
||||
return;
|
||||
}
|
||||
|
||||
var html = '';
|
||||
|
||||
for (var key in data) {
|
||||
for (var sku in data[key].selected_sku_list) {
|
||||
var item = data[key].selected_sku_list[sku];
|
||||
if(selectGoodsSkuId.indexOf(parseInt(item.sku_id)) != -1){
|
||||
continue;
|
||||
}
|
||||
html += "<tr data-sku-id=" + item.sku_id + " data-goods-id=" + item.goods_id + ">";
|
||||
html += '<td><div class="goods-title"><div class="goods-img"><img layer-src="" src="' + ns.img(item.sku_image) + '" alt=""></div><p class="multi-line-hiding goods-name">' + item.sku_name + '</p></td>';
|
||||
html += "<td>" + item.stock + "</td>";
|
||||
html += "<td class='goods-price'>" + item.price + "</td>";
|
||||
html += '<td><input type="text" class="layui-input topic_pic len-input topic-price" lay-verify="topic_price" min="0.00" value="' + item.price + '"/></td>';
|
||||
html += "<td class='operation'> <div class='table-btn '><a href='javascript:;' class='layui-btn' onclick='deleteGoods(this)'>删除商品</a></div></td>";
|
||||
html += "</tr>";
|
||||
selectGoodsSkuId.push(item.sku_id);
|
||||
}
|
||||
}
|
||||
|
||||
if(selectGoodsSkuId.length) {
|
||||
$('.goods-empty').hide();
|
||||
$("#goods tbody").append(html);
|
||||
} else {
|
||||
$('.goods-empty').show();
|
||||
}
|
||||
|
||||
$("#goods_num").text(selectGoodsSkuId.length)
|
||||
}, selectGoodsSkuId, {mode: "sku"});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*/
|
||||
function deleteGoods(data) {
|
||||
var obj = $(data).parent().parent().parent();
|
||||
$(obj).remove();
|
||||
for (var i in selectGoodsSkuId) {
|
||||
if (selectGoodsSkuId[i] == Number($(obj).attr("data-sku-id"))) {
|
||||
selectGoodsSkuId.splice(i, 1);
|
||||
}
|
||||
}
|
||||
$("#goods_num").html(selectGoodsSkuId.length);
|
||||
|
||||
if(selectGoodsSkuId.length) $('.goods-empty').hide();
|
||||
else $('.goods-empty').show();
|
||||
}
|
||||
|
||||
function back(){
|
||||
location.hash = ns.hash("topic://shop/topic/lists");
|
||||
}
|
||||
</script>
|
||||
105
addon/topic/shop/view/topic/detail.html
Executable file
105
addon/topic/shop/view/topic/detail.html
Executable file
@@ -0,0 +1,105 @@
|
||||
<link rel="stylesheet" href="STATIC_CSS/promotion_detail.css">
|
||||
|
||||
<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>{$info.topic_name}</span>
|
||||
</div>
|
||||
<div class="promotion-view-item">
|
||||
<label>开始时间:</label>
|
||||
<span>{:date('Y-m-d H:i:s',$info.start_time)}</span>
|
||||
</div>
|
||||
<div class="promotion-view-item">
|
||||
<label>结束时间:</label>
|
||||
<span>{:date('Y-m-d H:i:s',$info.end_time)}</span>
|
||||
</div>
|
||||
|
||||
</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 img-upload">
|
||||
<div class="upload-img-block icon">
|
||||
<div class="upload-img-box">
|
||||
{if condition="$info.topic_adv"}
|
||||
<img layer-src src="{:img($info.topic_adv)}" >
|
||||
{else/}
|
||||
<img layer-src src="__STATIC__/img/shape.png" />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{if !empty($info.remark)}
|
||||
<div class="promotion-view-item-line">
|
||||
<label class="promotion-view-item-custom-label">活动内容:</label>
|
||||
<div class="promotion-view-item-custom-box">{$info.remark}</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<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>
|
||||
|
||||
<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="{{ ns.img(d.sku_image) }}" alt="">
|
||||
</div>
|
||||
<p class="promotion-list-item-title-name multi-line-hiding">{{ d.sku_name }}</p>
|
||||
</div>
|
||||
</script>
|
||||
<script>
|
||||
var promotion_list = {:json_encode($info.goods_list, JSON_UNESCAPED_UNICODE)};
|
||||
layui.use('table', function() {
|
||||
|
||||
new Table({
|
||||
elem: '#promotion_list',
|
||||
cols: [
|
||||
[{
|
||||
field: 'sku_name',
|
||||
title: '商品名称',
|
||||
width: '30%',
|
||||
unresize: 'false',
|
||||
templet: '#promotion_list_item_box_html'
|
||||
}, {
|
||||
field: 'price',
|
||||
title: '商品价格',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
return '¥' + data.price;
|
||||
}
|
||||
}, {
|
||||
field: 'stock',
|
||||
title: '库存',
|
||||
unresize: 'false',
|
||||
|
||||
}, {
|
||||
title: '活动价格',
|
||||
unresize: 'false',
|
||||
templet: function(data) {
|
||||
return '¥' + data.topic_price;
|
||||
}
|
||||
}]
|
||||
],
|
||||
data: promotion_list
|
||||
});
|
||||
});
|
||||
</script>
|
||||
390
addon/topic/shop/view/topic/edit.html
Executable file
390
addon/topic/shop/view/topic/edit.html
Executable file
@@ -0,0 +1,390 @@
|
||||
<style>
|
||||
.layui-form-item .layui-input-inline.end-time{float: none;}
|
||||
.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;}
|
||||
.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="topic_name" value="{$info.topic_name}" lay-verify="required" autocomplete="off" class="layui-input len-long" maxlength="40">
|
||||
</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">
|
||||
<input type="text" id="start_time" name="start_time" value="{:date('Y-m-d H:i:s', $info.start_time)}" lay-verify="required" class="layui-input len-mid" autocomplete="off" readonly>
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
<span class="layui-form-mid">-</span>
|
||||
<div class="layui-input-inline end-time">
|
||||
<input type="text" id="end_time" name="end_time" value="{:date('Y-m-d H:i:s', $info.end_time)}" lay-verify="required|time" class="layui-input len-mid" autocomplete="off" readonly>
|
||||
<input type="hidden" value="{$info.end_time}" id="old_end_time">
|
||||
<i class=" iconrili iconfont calendar"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">横幅图片:</label>
|
||||
<div class="layui-input-inline img-upload">
|
||||
<div class="upload-img-block icon">
|
||||
<div class="upload-img-box {if !empty($info.topic_adv)}hover{/if}">
|
||||
<div class="upload-default" id="webLogoUpload">
|
||||
{if empty($info.topic_adv)}
|
||||
<div class="upload">
|
||||
<i class="iconfont iconshangchuan"></i>
|
||||
<p>点击上传</p>
|
||||
</div>
|
||||
{else/}
|
||||
<div id="preview_webLogoUpload" class="preview_img">
|
||||
<img layer-src src="{:img($info.topic_adv)}" alt="" class="img_prev">
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="operation">
|
||||
<div>
|
||||
<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
|
||||
<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
|
||||
</div>
|
||||
|
||||
<div class="replace_img js-replace">点击替换</div>
|
||||
</div>
|
||||
<input type="hidden" name="topic_adv" value="{$info.topic_adv}"/>
|
||||
</div>
|
||||
<!-- <p id="webLogoUpload" class=" {if condition="$info.topic_adv"} replace {else/} no-replace{/if}">替换</p>
|
||||
<i class="del {if !empty($info.topic_adv)}show{/if}">x</i> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">活动内容:</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea class="layui-textarea len-long" name="remark" maxlength="300">{$info.remark}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="required">*</span>商品:</label>
|
||||
<div class="layui-input-block">
|
||||
<table class="layui-table" id="goods" lay-skin="line" lay-size="lg">
|
||||
<colgroup>
|
||||
<col width="40%">
|
||||
<col width="15%">
|
||||
<col width="15%">
|
||||
<col width="15%">
|
||||
<col width="15%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>商品名称</th>
|
||||
<th>库存</th>
|
||||
<th>价格</th>
|
||||
<th>活动价格</th>
|
||||
<th class="operation">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{notempty name="$info['goods_list']"}
|
||||
{foreach name="$info['goods_list']" item="item"}
|
||||
<tr data-id="{$item.id}" data-sku-id="{$item.sku_id}" data-goods-id="{$item.goods_id}">
|
||||
<td>
|
||||
<div class="goods-title">
|
||||
<div class="goods-img">
|
||||
{if $item.sku_image}
|
||||
<img layer-src="" src="{:img($item.sku_image)}" alt="">
|
||||
{else /}
|
||||
<img layer-src="" src="__STATIC__/img/shape.png" alt="">
|
||||
{/if}
|
||||
</div>
|
||||
<p class="multi-line-hiding goods-name">{$item.sku_name}</p>
|
||||
</div>
|
||||
<td>{$item.stock}</td>
|
||||
<td class='goods-price'>{$item.price}</td>
|
||||
<td><input type="number" class="layui-input len-input topic-price" lay-verify="required|topic_price" min="0.00" value="{$item.topic_price}"/></td>
|
||||
<td class='operation'><div class='table-btn '><a href='javascript:;' class='layui-btn' onclick='deleteGoods(this)'>删除商品</a></div></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
{/notempty}
|
||||
<tr class="goods-empty" {notempty name="$info['goods_list']"}style="display:none;"{/notempty}>
|
||||
<td colspan="5">
|
||||
<div>未添加商品</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="layui-btn" onclick="addGoods()">添加商品</button> <span class="goods_num">已选商品(<span id="goods_num" class="text-color">{$info.goods_list_count}</span>)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
|
||||
<a id="webLogoUploadImage"></a>
|
||||
</div>
|
||||
<input type="hidden" name="topic_id" value="{$info.topic_id}">
|
||||
<input type="hidden" name="del_id" value="">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var selectGoodsSkuId = '{$sku_ids}'.split(',');
|
||||
var saveData = null;
|
||||
var totalUploadNum = 0;
|
||||
var completeUploadNum = 0;
|
||||
var upload;
|
||||
|
||||
layui.use(['form','laydate','colorpicker'], function() {
|
||||
var form = layui.form,
|
||||
laydate = layui.laydate,
|
||||
colorpicker = layui.colorpicker,
|
||||
startTime = {$info.start_time},
|
||||
endTime = {$info.end_time},
|
||||
minDate = "",
|
||||
repeat_flag = false;//防重复标识
|
||||
form.render();
|
||||
|
||||
upload = new Upload({
|
||||
elem: '#webLogoUpload',
|
||||
auto:false,
|
||||
bindAction:'#webLogoUploadImage',
|
||||
callback: function(res) {
|
||||
uploadComplete('topic_adv', res.data.pic_path);
|
||||
}
|
||||
});
|
||||
|
||||
function uploadComplete(field, pic_path) {
|
||||
saveData.field[field] = pic_path;
|
||||
completeUploadNum += 1;
|
||||
if(completeUploadNum == totalUploadNum){
|
||||
saveFunc();
|
||||
}
|
||||
}
|
||||
|
||||
function saveFunc(){
|
||||
var data = saveData;
|
||||
$.ajax({
|
||||
url: ns.url("topic://shop/topic/edit"),
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
success: function(res){
|
||||
repeat_flag = false;
|
||||
if(res.code == 0){
|
||||
layer.confirm('编辑成功',{
|
||||
title: '操作提示',
|
||||
btn: ['返回列表', '继续操作'],
|
||||
yes: function(index, layero) {
|
||||
location.hash = ns.hash("topic://shop/topic/lists");
|
||||
layer.close(index);
|
||||
},btn2: function(index, layero) {
|
||||
layer.close(index);
|
||||
}
|
||||
})
|
||||
}else{
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
*/
|
||||
colorpicker.render({
|
||||
elem: '#colorpicker', //绑定元素
|
||||
color: "{$info.bg_color}",
|
||||
done: function(color) {
|
||||
$("#bg_color").val(color);
|
||||
}
|
||||
});
|
||||
|
||||
var now_time = ((new Date()).getTime())/1000;
|
||||
var start_time = ((new Date($("#start_time").val())).getTime())/1000;
|
||||
var old_end_time = ((new Date($("#end_time").val())).getTime())/1000;
|
||||
// if(now_time <= start_time){
|
||||
//开始时间
|
||||
laydate.render({
|
||||
elem: '#start_time', //指定元素
|
||||
type: 'datetime',
|
||||
value: ns.time_to_date(startTime),
|
||||
done: function(value) {
|
||||
minDate = value;
|
||||
reRender();
|
||||
}
|
||||
});
|
||||
// }
|
||||
// if(now_time <= old_end_time){
|
||||
//结束时间
|
||||
laydate.render({
|
||||
elem: '#end_time', //指定元素
|
||||
type: 'datetime',
|
||||
value: ns.time_to_date(endTime)
|
||||
});
|
||||
// }
|
||||
|
||||
/**
|
||||
* 重新渲染结束时间
|
||||
* */
|
||||
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" > ');
|
||||
laydate.render({
|
||||
elem: '#end_time',
|
||||
type: 'datetime',
|
||||
min: minDate
|
||||
});
|
||||
}
|
||||
|
||||
form.verify({
|
||||
topic_price: function(value, item) {
|
||||
var price = $(item).parents("tr").find(".goods-price").text();
|
||||
if (value.trim() == "") {
|
||||
return '活动价格不能为空';
|
||||
}
|
||||
if (parseFloat(value) <= 0) {
|
||||
return '活动价格必须大于0';
|
||||
}
|
||||
if (parseFloat(value) > parseFloat(price)) {
|
||||
return '活动价格不能大于商品价格';
|
||||
}
|
||||
|
||||
var pattern = /^[0-9]+(\.[0-9]{1,2})?$/;
|
||||
if(!pattern.test(value)){
|
||||
return '请输入正确格式';
|
||||
}
|
||||
|
||||
var arrMen = value.split(".");
|
||||
var val = 0;
|
||||
if (arrMen.length == 2) {
|
||||
val = arrMen[1];
|
||||
}
|
||||
if (val.length > 2) {
|
||||
return '活动价格最多保留两位小数';
|
||||
}
|
||||
},
|
||||
time: function(value) {
|
||||
var now_time = ((new Date()).getTime())/1000;
|
||||
var start_time = ((new Date($("#start_time").val())).getTime())/1000;
|
||||
var end_time = ((new Date(value)).getTime())/1000;
|
||||
var old_end_time = $("#old_end_time").val();
|
||||
if (now_time > end_time) {
|
||||
return '结束时间不能小于当前时间!'
|
||||
}
|
||||
if (start_time > end_time) {
|
||||
return '结束时间不能小于开始时间!';
|
||||
}
|
||||
if (old_end_time > end_time) {
|
||||
return '结束时间不能小于之前设置的结束时间!';
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
form.on("submit(save)",function(data){
|
||||
data.field.start_time = ns.date_to_time(data.field.start_time);
|
||||
data.field.end_time = ns.date_to_time(data.field.end_time);
|
||||
// 删除图片
|
||||
if(!data.field.topic_adv) upload.delete();
|
||||
if ($('#goods tbody tr[data-sku-id]').length == 0) {
|
||||
layer.msg('请选择商品', {icon: 5});
|
||||
return;
|
||||
}
|
||||
var goods = {};
|
||||
$('#goods tbody tr[data-sku-id]').each(function(){
|
||||
var item = {
|
||||
id:$(this).attr('data-id'),
|
||||
goods_id : $(this).attr('data-goods-id'),
|
||||
sku_id : $(this).attr('data-sku-id'),
|
||||
topic_price : $(this).find('.topic-price').val()
|
||||
};
|
||||
if (!goods['goods_' + item.goods_id]) goods['goods_' + item.goods_id] = [];
|
||||
goods['goods_' + item.goods_id].push(item);
|
||||
})
|
||||
data.field.goods = JSON.stringify(goods);
|
||||
|
||||
saveData = data;
|
||||
var obj = $("img.img_prev[data-prev='1']");
|
||||
totalUploadNum = obj.length;
|
||||
if(totalUploadNum > 0){
|
||||
obj.each(function(){
|
||||
var actionId = $(this).attr('data-action-id');
|
||||
$(actionId).click();
|
||||
})
|
||||
}else{
|
||||
saveFunc();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* 添加商品
|
||||
*/
|
||||
function addGoods() {
|
||||
goodsSelect(function (data) {
|
||||
if (Object.keys(data).length == 0) {
|
||||
selectGoodsSkuId = [];
|
||||
$('.goods-empty').show();
|
||||
$("#goods_num").text(selectGoodsSkuId.length);
|
||||
$("#goods tbody tr:not(.goods-empty)").remove();
|
||||
return;
|
||||
}
|
||||
|
||||
var html = '';
|
||||
for (var key in data) {
|
||||
for (var sku in data[key].selected_sku_list) {
|
||||
var item = data[key].selected_sku_list[sku];
|
||||
if(selectGoodsSkuId.indexOf(parseInt(item.sku_id)) != -1){
|
||||
continue;
|
||||
}
|
||||
html += "<tr data-sku-id=" + item.sku_id + " data-goods-id=" + item.goods_id + ">";
|
||||
html += '<td><div class="goods-title"><div class="goods-img"><img layer-src="" src="' + ns.img(item.sku_image) + '" alt=""></div><p class="multi-line-hiding goods-name">' + item.sku_name + '</p></td>';
|
||||
html += "<td>" + item.stock + "</td>";
|
||||
html += "<td class='goods-price'>" + item.price + "</td>";
|
||||
html += '<td><input type="text" class="layui-input topic_pic len-input topic-price" lay-verify="topic_price" min="0.00" value="' + item.price + '"/></td>';
|
||||
html += "<td class='operation'> <div class='table-btn '><a href='javascript:;' class='layui-btn' onclick='deleteGoods(this)'>删除商品</a></div></td>";
|
||||
html += "</tr>";
|
||||
selectGoodsSkuId.push(item.sku_id);
|
||||
}
|
||||
}
|
||||
|
||||
if(selectGoodsSkuId.length) {
|
||||
$('.goods-empty').hide();
|
||||
$("#goods tbody").append(html);
|
||||
} else {
|
||||
$('.goods-empty').show();
|
||||
}
|
||||
$("#goods_num").text(selectGoodsSkuId.length)
|
||||
|
||||
}, selectGoodsSkuId, {mode: "sku"});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*/
|
||||
function deleteGoods(data) {
|
||||
var obj = $(data).parent().parent().parent();
|
||||
$(obj).remove();
|
||||
for (var i in selectGoodsSkuId) {
|
||||
if (selectGoodsSkuId[i] == Number($(obj).attr("data-sku-id"))) {
|
||||
selectGoodsSkuId.splice(i, 1);
|
||||
}
|
||||
}
|
||||
var delId = $('input[name="del_id"]').val().length>0 ? $('input[name="del_id"]').val().toString().split(',') : [];
|
||||
delId.push($(obj).attr('data-id'));
|
||||
$('input[name="del_id"]').val(delId);
|
||||
|
||||
$("#goods_num").html(selectGoodsSkuId.length)
|
||||
|
||||
if(selectGoodsSkuId.length) $('.goods-empty').hide();
|
||||
else $('.goods-empty').show();
|
||||
|
||||
}
|
||||
|
||||
function back(){
|
||||
location.hash = ns.hash("topic://shop/topic/lists");
|
||||
}
|
||||
</script>
|
||||
244
addon/topic/shop/view/topic/lists.html
Executable file
244
addon/topic/shop/view/topic/lists.html
Executable file
@@ -0,0 +1,244 @@
|
||||
<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="clickAdd()">添加专题活动</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="topic_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="topic_tab">
|
||||
<ul class="layui-tab-title">
|
||||
<li class="layui-this" data-status="">全部</li>
|
||||
<li data-status="1">未开始</li>
|
||||
<li data-status="2">进行中</li>
|
||||
<li data-status="3">已结束</li>
|
||||
</ul>
|
||||
<div class="layui-tab-content">
|
||||
<!-- 列表 -->
|
||||
<table id="topic_list" lay-filter="topic_list"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 时间 -->
|
||||
<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="toolbarAction">
|
||||
<button class="layui-btn layui-btn-primary" lay-event="delete">批量删除</button>
|
||||
</script>
|
||||
|
||||
<!-- 操作 -->
|
||||
<script type="text/html" id="operation">
|
||||
<div class="table-btn">
|
||||
<a class="layui-btn" lay-event="detail">详情</a>
|
||||
<a class="layui-btn" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn" lay-event="delete">删除</a>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
layui.use(['form', 'element','laydate'], function() {
|
||||
form = layui.form,
|
||||
element = layui.element,
|
||||
laydate = layui.laydate,
|
||||
repeat_flag = false; //防重复标识
|
||||
form.render();
|
||||
|
||||
element.on('tab(topic_tab)', function() {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
where: {
|
||||
'status': this.getAttribute('data-status')
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
table = new Table({
|
||||
elem: '#topic_list',
|
||||
url: ns.url("topic://shop/topic/lists"),
|
||||
cols: [
|
||||
[{
|
||||
type: 'checkbox',
|
||||
width: '3%',
|
||||
},{
|
||||
field: 'topic_name',
|
||||
title: '专题名称',
|
||||
unresize: 'false',
|
||||
width: '25%'
|
||||
}, {
|
||||
title: '活动时间',
|
||||
unresize: 'false',
|
||||
width: '20%',
|
||||
templet: '#time'
|
||||
}, {
|
||||
title: '状态',
|
||||
unresize: 'false',
|
||||
width: '30%',
|
||||
templet: function (data) {
|
||||
if(data.status == 1){
|
||||
return '未开始';
|
||||
}else if(data.status == 2){
|
||||
return '进行中';
|
||||
}else if(data.status == 3){
|
||||
return '已结束';
|
||||
}
|
||||
}
|
||||
}, {
|
||||
title: '操作',
|
||||
toolbar: '#operation',
|
||||
unresize: 'false',
|
||||
align:'right'
|
||||
}]
|
||||
],
|
||||
toolbar: '#toolbarAction'
|
||||
});
|
||||
|
||||
//开始时间
|
||||
laydate.render({
|
||||
elem: '#start_time', //指定元素
|
||||
type: 'datetime'
|
||||
});
|
||||
//结束时间
|
||||
laydate.render({
|
||||
elem: '#end_time', //指定元素
|
||||
type: 'datetime'
|
||||
});
|
||||
|
||||
// 监听工具栏操作
|
||||
table.toolbar(function (obj) {
|
||||
var data = obj.data;
|
||||
if(data.length <= 0) return;
|
||||
var topicIdAll = [];
|
||||
for (var i in data){
|
||||
topicIdAll.push(data[i].topic_id);
|
||||
}
|
||||
|
||||
switch (obj.event) {
|
||||
case 'delete':
|
||||
deleteTopicAll(topicIdAll)
|
||||
break;
|
||||
}
|
||||
})
|
||||
|
||||
function deleteTopicAll(data){
|
||||
layer.confirm('确定要删除该专题活动吗?', function (index) {
|
||||
if (repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
url: ns.url("topic://shop/topic/deleteAll"),
|
||||
data: {topic_id: data},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function (res) {
|
||||
layer.msg(res.message);
|
||||
repeat_flag = false;
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
layer.close();
|
||||
repeat_flag = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听工具栏操作
|
||||
*/
|
||||
table.tool(function (obj) {
|
||||
var data = obj.data;
|
||||
switch (obj.event) {
|
||||
case 'delete': //删除
|
||||
layer.confirm('确定要删除该专题活动吗?', function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
url: ns.url("topic://shop/topic/delete"),
|
||||
data: {topic_id: data.topic_id},
|
||||
dataType: 'JSON',
|
||||
type: 'POST',
|
||||
success: function (res) {
|
||||
layer.msg(res.message);
|
||||
repeat_flag = false;
|
||||
if (res.code == 0) {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 'edit': //编辑
|
||||
location.hash = ns.hash("topic://shop/topic/edit?topic_id=" + data.topic_id);
|
||||
break;
|
||||
case 'detail': //详情
|
||||
location.hash = ns.hash("topic://shop/topic/detail?topic_id=" + data.topic_id);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
layui.use('form', function () {
|
||||
var form = layui.form;
|
||||
form.render();
|
||||
|
||||
form.on();
|
||||
});
|
||||
|
||||
form.on('submit(search)', function (data) {
|
||||
table.reload({
|
||||
page: {
|
||||
curr: 1
|
||||
},
|
||||
where: data.field
|
||||
});
|
||||
});
|
||||
});
|
||||
function clickAdd() {
|
||||
location.hash = ns.hash("topic://shop/topic/add");
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user