chore(src): 所有代码上传

This commit is contained in:
2025-12-02 15:36:42 +08:00
parent ce8e59902c
commit eb79ad260c
669 changed files with 86838 additions and 87639 deletions

View File

@@ -1,209 +1,201 @@
<?php
/**
*/
namespace addon\pointexchange\api\controller;
use app\api\controller\BaseApi;
use addon\pointexchange\model\Exchange as ExchangeModel;
use app\model\goods\GoodsService;
use app\model\web\Config as ConfigModel;
use app\model\goods\GoodsCategory as GoodsCategoryModel;
/**
* 积分兑换
*/
class Goods extends BaseApi
{
/**
* 详情信息
*/
public function detail()
{
$id = $this->params['id'] ?? 0;
if (empty($id)) {
return $this->response($this->error('', 'REQUEST_ID'));
}
$exchange_model = new ExchangeModel();
$exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id')[ 'data' ];
$condition = [
[ 'peg.id', '=', $id ],
[ 'peg.site_id', '=', $this->site_id ],
[ 'peg.state', '=', 1 ],
];
if (empty($exchange_info)) return $this->response($this->error('', '商品未找到'));
$info = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
if (empty($info)) return $this->response($this->error($info));
if ($exchange_info[ 'type' ] == 1) {
//判断商品规格项
$goods_spec_format = $exchange_model->getGoodsSpecFormat($info[ 'exchange_id' ], $this->site_id, $info[ 'goods_spec_format' ]);
$info[ 'goods_spec_format' ] = json_encode($goods_spec_format);
$goods_service = new GoodsService();
$info[ 'goods_service' ] = $goods_service->getServiceList([ [ 'site_id', '=', $this->site_id ], [ 'id', 'in', $info[ 'goods_service_ids' ] ] ], 'service_name,desc,icon')[ 'data' ];
}
return $this->response($this->success($info));
}
/**
* 查询商品SKU集合
* @return false|string
*/
public function goodsSku()
{
$goods_id = $this->params['goods_id'] ?? 0;
$exchange_id = $this->params['exchange_id'] ?? 0;
$type = $this->params['type'] ?? 0;
if (empty($goods_id)) {
return $this->response($this->error('', 'REQUEST_ID'));
}
if (empty($exchange_id)) {
return $this->response($this->error('', 'REQUEST_ID'));
}
$exchange_model = new ExchangeModel();
$condition = [
[ 'peg.id', '=', $exchange_id ],
[ 'peg.site_id', '=', $this->site_id ],
[ 'peg.state', '=', 1 ],
];
$list = $exchange_model->getExchangeSkuList($condition, $type);
if (!empty($list[ 'data' ])) {
foreach ($list[ 'data' ] as $k => $v) {
if (!empty($v[ 'goods_spec_format' ])) {
$goods_spec_format = $exchange_model->getGoodsSpecFormat($v[ 'exchange_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()
{
$page = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$type = $this->params['type'] ?? 1;//兑换类型1商品2优惠券3红包
//商品类型条件查询
$keyword = $this->params['keyword'] ?? ''; //关键词
$order = $this->params['order'] ?? '';//排序(综合、上新时间、价格)
$sort = $this->params['sort'] ?? '';//升序、降序
$min_point = $this->params['min_point'] ?? 0;//积分区间,小
$max_point = $this->params['max_point'] ?? 0;//积分区间,大
$category_id = $this->params['category_id'] ?? 0;//分类
$condition = [
[ 'peg.state', '=', 1 ],
[ 'peg.type', '=', $type ],
[ 'peg.site_id', '=', $this->site_id ]
];
if (!empty($keyword)) {
$condition[] = [ 'g.goods_name|peg.name', 'like', '%' . $keyword . '%' ];
}
// 非法参数进行过滤
if ($sort != 'desc' && $sort != 'asc') {
$sort = '';
}
// 非法参数进行过滤
if ($order != '') {
if ($order != 'create_time' && $order != 'point') {
$order = 'peg.sort';
} elseif ($order == 'create_time') {
$order = 'peg.create_time';
} else {
$order = 'peg.' . $order;
}
$order_by = $order . ' ' . $sort;
} else {
$config_model = new ConfigModel();
$sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
$order_by = 'peg.sort ' . $sort_config[ 'type' ] . ',peg.create_time desc';
}
if ($min_point != '' && $max_point != '') {
$condition[] = [ 'peg.point', 'between', [ $min_point, $max_point ] ];
} elseif ($min_point != '') {
$condition[] = [ 'peg.point', '>=', $min_point ];
} elseif ($max_point != '') {
$condition[] = [ 'peg.point', '<=', $max_point ];
}
if (!empty($category_id)) {
$goods_category_model = new GoodsCategoryModel();
// 查询当前
$category_list = $goods_category_model->getCategoryList([ [ 'category_id', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
// 查询子级
$category_child_list = $goods_category_model->getCategoryList([ [ 'pid', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
$temp_category_list = [];
if (!empty($category_list)) {
$temp_category_list = $category_list;
} elseif (!empty($category_child_list)) {
$temp_category_list = $category_child_list;
}
if (!empty($temp_category_list)) {
$category_id_arr = [];
foreach ($temp_category_list as $k => $v) {
// 三级分类,并且都能查询到
if ($v[ 'level' ] == 3 && !empty($category_list) && !empty($category_child_list)) {
$category_id_arr[] = $v['pid'];
} else {
$category_id_arr[] = $v['category_id'];
}
}
$category_id_arr = array_unique($category_id_arr);
$temp_condition = [];
foreach ($category_id_arr as $ck => $cv) {
$temp_condition[] = '%,' . $cv . ',%';
}
$category_condition = $temp_condition;
$condition[] = [ 'g.category_id', 'like', $category_condition, 'or' ];
}
}
$field = 'peg.*';
$alias = 'peg';
$join = [];
if ($type == 1) {
$condition[] = [ 'g.is_delete', '=', 0 ];
$condition[] = [ 'g.goods_state', '=', 1 ];
$join = [
[ 'goods g', 'peg.type_id = g.goods_id', 'inner' ]
];
$field .= ',g.goods_name as name,g.goods_image as image, g.goods_stock as stock, g.stock_show,g.sale_show,(g.sale_num + g.virtual_sale) as sale_num';
} elseif ($type == 2) {
$field .= ',pct.type as coupon_type,pct.goods_type,pct.at_least,pct.money,pct.discount';
$join = [
[ 'promotion_coupon_type pct', 'peg.type_id = pct.coupon_type_id', 'inner' ]
];
}
$exchange_model = new ExchangeModel();
$list = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
return $this->response($list);
}
<?php
namespace addon\pointexchange\api\controller;
use app\api\controller\BaseApi;
use addon\pointexchange\model\Exchange as ExchangeModel;
use app\model\goods\GoodsService;
use app\model\web\Config as ConfigModel;
use app\model\goods\GoodsCategory as GoodsCategoryModel;
/**
* 积分兑换
*/
class Goods extends BaseApi
{
/**
* 详情信息
*/
public function detail()
{
$id = $this->params['id'] ?? 0;
if (empty($id)) {
return $this->response($this->error('', 'REQUEST_ID'));
}
$exchange_model = new ExchangeModel();
$exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id')[ 'data' ];
$condition = [
[ 'peg.id', '=', $id ],
[ 'peg.site_id', '=', $this->site_id ],
[ 'peg.state', '=', 1 ],
];
if (empty($exchange_info)) return $this->response($this->error('', '商品未找到'));
$info = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
if (empty($info)) return $this->response($this->error($info));
if ($exchange_info[ 'type' ] == 1) {
//判断商品规格项
$goods_spec_format = $exchange_model->getGoodsSpecFormat($info[ 'exchange_id' ], $this->site_id, $info[ 'goods_spec_format' ]);
$info[ 'goods_spec_format' ] = json_encode($goods_spec_format);
$goods_service = new GoodsService();
$info[ 'goods_service' ] = $goods_service->getServiceList([ [ 'site_id', '=', $this->site_id ], [ 'id', 'in', $info[ 'goods_service_ids' ] ] ], 'service_name,desc,icon')[ 'data' ];
}
return $this->response($this->success($info));
}
/**
* 查询商品SKU集合
* @return false|string
*/
public function goodsSku()
{
$goods_id = $this->params['goods_id'] ?? 0;
$exchange_id = $this->params['exchange_id'] ?? 0;
$type = $this->params['type'] ?? 0;
if (empty($goods_id)) {
return $this->response($this->error('', 'REQUEST_ID'));
}
if (empty($exchange_id)) {
return $this->response($this->error('', 'REQUEST_ID'));
}
$exchange_model = new ExchangeModel();
$condition = [
[ 'peg.id', '=', $exchange_id ],
[ 'peg.site_id', '=', $this->site_id ],
[ 'peg.state', '=', 1 ],
];
$list = $exchange_model->getExchangeSkuList($condition, $type);
if (!empty($list[ 'data' ])) {
foreach ($list[ 'data' ] as $k => $v) {
if (!empty($v[ 'goods_spec_format' ])) {
$goods_spec_format = $exchange_model->getGoodsSpecFormat($v[ 'exchange_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()
{
$page = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$type = $this->params['type'] ?? 1;//兑换类型1商品2优惠券3红包
//商品类型条件查询
$keyword = $this->params['keyword'] ?? ''; //关键词
$order = $this->params['order'] ?? '';//排序(综合、上新时间、价格)
$sort = $this->params['sort'] ?? '';//升序、降序
$min_point = $this->params['min_point'] ?? 0;//积分区间,小
$max_point = $this->params['max_point'] ?? 0;//积分区间,大
$category_id = $this->params['category_id'] ?? 0;//分类
$condition = [
[ 'peg.state', '=', 1 ],
[ 'peg.type', '=', $type ],
[ 'peg.site_id', '=', $this->site_id ]
];
if (!empty($keyword)) {
$condition[] = [ 'g.goods_name|peg.name', 'like', '%' . $keyword . '%' ];
}
// 非法参数进行过滤
if ($sort != 'desc' && $sort != 'asc') {
$sort = '';
}
// 非法参数进行过滤
if ($order != '') {
if ($order != 'create_time' && $order != 'point') {
$order = 'peg.sort';
} elseif ($order == 'create_time') {
$order = 'peg.create_time';
} else {
$order = 'peg.' . $order;
}
$order_by = $order . ' ' . $sort;
} else {
$config_model = new ConfigModel();
$sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
$order_by = 'peg.sort ' . $sort_config[ 'type' ] . ',peg.create_time desc';
}
if ($min_point != '' && $max_point != '') {
$condition[] = [ 'peg.point', 'between', [ $min_point, $max_point ] ];
} elseif ($min_point != '') {
$condition[] = [ 'peg.point', '>=', $min_point ];
} elseif ($max_point != '') {
$condition[] = [ 'peg.point', '<=', $max_point ];
}
if (!empty($category_id)) {
$goods_category_model = new GoodsCategoryModel();
// 查询当前
$category_list = $goods_category_model->getCategoryList([ [ 'category_id', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
// 查询子级
$category_child_list = $goods_category_model->getCategoryList([ [ 'pid', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
$temp_category_list = [];
if (!empty($category_list)) {
$temp_category_list = $category_list;
} elseif (!empty($category_child_list)) {
$temp_category_list = $category_child_list;
}
if (!empty($temp_category_list)) {
$category_id_arr = [];
foreach ($temp_category_list as $k => $v) {
// 三级分类,并且都能查询到
if ($v[ 'level' ] == 3 && !empty($category_list) && !empty($category_child_list)) {
$category_id_arr[] = $v['pid'];
} else {
$category_id_arr[] = $v['category_id'];
}
}
$category_id_arr = array_unique($category_id_arr);
$temp_condition = [];
foreach ($category_id_arr as $ck => $cv) {
$temp_condition[] = '%,' . $cv . ',%';
}
$category_condition = $temp_condition;
$condition[] = [ 'g.category_id', 'like', $category_condition, 'or' ];
}
}
$field = 'peg.*';
$alias = 'peg';
$join = [];
if ($type == 1) {
$condition[] = [ 'g.is_delete', '=', 0 ];
$condition[] = [ 'g.goods_state', '=', 1 ];
$join = [
[ 'goods g', 'peg.type_id = g.goods_id', 'inner' ]
];
$field .= ',g.goods_name as name,g.goods_image as image, g.goods_stock as stock, g.stock_show,g.sale_show,(g.sale_num + g.virtual_sale) as sale_num';
} elseif ($type == 2) {
$field .= ',pct.type as coupon_type,pct.goods_type,pct.at_least,pct.money,pct.discount';
$join = [
[ 'promotion_coupon_type pct', 'peg.type_id = pct.coupon_type_id', 'inner' ]
];
}
$exchange_model = new ExchangeModel();
$list = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
return $this->response($list);
}
}

View File

@@ -1,83 +1,74 @@
<?php
/**
*/
namespace addon\pointexchange\api\controller;
use app\api\controller\BaseApi;
use addon\pointexchange\model\Order as OrderModel;
/**
* 积分兑换订单
*/
class Order extends BaseApi
{
/**
* 基础信息
*/
public function info()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$order_id = $this->params['order_id'] ?? 0;
if (empty($order_id)) {
return $this->response($this->error('', 'REQUEST_ORDER_ID'));
}
$condition = [
[ 'order_id', '=', $order_id ],
[ 'member_id', '=', $this->member_id ],
[ 'site_id', '=', $this->site_id ],
];
$field = '*';
$exchange_model = new OrderModel();
$info = $exchange_model->getOrderInfo($condition, $field);
return $this->response($info);
}
public function page()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$page = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$order_status = $this->params['order_status'] ?? 'all';
$condition = [
[ 'member_id', '=', $this->member_id ],
[ 'site_id', '=', $this->site_id ],
];
if ($order_status != 'all') $condition[] = ['order_status', '=', $order_status];
$order = 'create_time desc';
$field = '*';
$exchange_model = new OrderModel();
$list = $exchange_model->getExchangePageList($condition, $page, $page_size, $order, $field);
return $this->response($list);
}
/**
* 关闭订单
* @return false|string
*/
public function close(){
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$order_id = $this->params['order_id'] ?? 0;
$exchange_model = new OrderModel();
$result = $exchange_model->closeOrder($order_id);
return $this->response($result);
}
<?php
namespace addon\pointexchange\api\controller;
use app\api\controller\BaseApi;
use addon\pointexchange\model\Order as OrderModel;
/**
* 积分兑换订单
*/
class Order extends BaseApi
{
/**
* 基础信息
*/
public function info()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$order_id = $this->params['order_id'] ?? 0;
if (empty($order_id)) {
return $this->response($this->error('', 'REQUEST_ORDER_ID'));
}
$condition = [
[ 'order_id', '=', $order_id ],
[ 'member_id', '=', $this->member_id ],
[ 'site_id', '=', $this->site_id ],
];
$field = '*';
$exchange_model = new OrderModel();
$info = $exchange_model->getOrderInfo($condition, $field);
return $this->response($info);
}
public function page()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$page = $this->params['page'] ?? 1;
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$order_status = $this->params['order_status'] ?? 'all';
$condition = [
[ 'member_id', '=', $this->member_id ],
[ 'site_id', '=', $this->site_id ],
];
if ($order_status != 'all') $condition[] = ['order_status', '=', $order_status];
$order = 'create_time desc';
$field = '*';
$exchange_model = new OrderModel();
$list = $exchange_model->getExchangePageList($condition, $page, $page_size, $order, $field);
return $this->response($list);
}
/**
* 关闭订单
* @return false|string
*/
public function close(){
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$order_id = $this->params['order_id'] ?? 0;
$exchange_model = new OrderModel();
$result = $exchange_model->closeOrder($order_id);
return $this->response($result);
}
}

View File

@@ -1,20 +1,12 @@
<?php
/**
*/
return [
'name' => 'pointexchange',
'title' => '积分商城',
'description' => '积分购买商品,形成积分营销闭环',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '1.0',
'version_no' => '100000',
'content' => '',
<?php
return [
'name' => 'pointexchange',
'title' => '积分商城',
'description' => '积分购买商品,形成积分营销闭环',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '1.0',
'version_no' => '100000',
'content' => '',
];

View File

@@ -1,26 +1,17 @@
<?php
/**
*/
namespace addon\pointexchange\event;
/**
* 优惠券来源类型
*/
class CouponGetType
{
/**
* 执行安装
*/
public function handle()
{
return [ 7 => '积分兑换'];
}
<?php
namespace addon\pointexchange\event;
/**
* 优惠券来源类型
*/
class CouponGetType
{
/**
* 执行安装
*/
public function handle()
{
return [ 7 => '积分兑换'];
}
}

View File

@@ -1,28 +1,20 @@
<?php
/**
*/
namespace addon\pointexchange\event;
use addon\pointexchange\model\Order;
/**
* 积分兑换订单关闭
*/
class CronExchangeOrderClose
{
// 行为扩展的执行入口必须是run
public function handle($data)
{
$order = new Order();
$order->closeOrder($data['relate_id']);
}
<?php
namespace addon\pointexchange\event;
use addon\pointexchange\model\Order;
/**
* 积分兑换订单关闭
*/
class CronExchangeOrderClose
{
// 行为扩展的执行入口必须是run
public function handle($data)
{
$order = new Order();
$order->closeOrder($data['relate_id']);
}
}

View File

@@ -1,26 +1,18 @@
<?php
/**
*/
namespace addon\pointexchange\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
<?php
namespace addon\pointexchange\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -1,46 +1,37 @@
<?php
/**
*/
namespace addon\pointexchange\event;
/**
* 会员账户变化来源类型
*/
class MemberAccountFromType
{
public function handle($data)
{
$from_type = [
'point' => [
'pointexchange' => [
'type_name' => '积分兑换',
'type_url' => ''
]
],
// 'point' => [
// 'pointexchangerefund' => [
// 'type_name' => '积分兑换退还',
// 'type_url' => ''
// ],
//
// ]
];
if($data == ''){
return $from_type;
}else{
return $from_type[$data] ?? [];
}
}
<?php
namespace addon\pointexchange\event;
/**
* 会员账户变化来源类型
*/
class MemberAccountFromType
{
public function handle($data)
{
$from_type = [
'point' => [
'pointexchange' => [
'type_name' => '积分兑换',
'type_url' => ''
]
],
// 'point' => [
// 'pointexchangerefund' => [
// 'type_name' => '积分兑换退还',
// 'type_url' => ''
// ],
//
// ]
];
if($data == ''){
return $from_type;
}else{
return $from_type[$data] ?? [];
}
}
}

View File

@@ -1,41 +1,33 @@
<?php
/**
*/
namespace addon\pointexchange\event;
use addon\pointexchange\model\Order;
/**
* 订单关闭
*/
class OrderClose
{
/**
* 订单关闭
* @param $param
* @return array|int|mixed|void
*/
public function handle($param)
{
$order_model = new Order();
$order_info_result = $order_model->getOrderInfo([ [ 'relate_order_id', '=', $param[ 'order_id' ] ] ]);
if ($order_info_result[ 'code' ] < 0 || empty($order_info_result[ 'data' ])) {
return $order_info_result;
}
if (empty($order_info_result[ 'data' ])) {
$order_info_result[ 'data' ][ 'order_id' ] = $param[ 'order_id' ];
}
$res = $order_model->closeOrder($order_info_result[ 'data' ][ 'order_id' ]);
return $res;
}
<?php
namespace addon\pointexchange\event;
use addon\pointexchange\model\Order;
/**
* 订单关闭
*/
class OrderClose
{
/**
* 订单关闭
* @param $param
* @return array|int|mixed|void
*/
public function handle($param)
{
$order_model = new Order();
$order_info_result = $order_model->getOrderInfo([ [ 'relate_order_id', '=', $param[ 'order_id' ] ] ]);
if ($order_info_result[ 'code' ] < 0 || empty($order_info_result[ 'data' ])) {
return $order_info_result;
}
if (empty($order_info_result[ 'data' ])) {
$order_info_result[ 'data' ][ 'order_id' ] = $param[ 'order_id' ];
}
$res = $order_model->closeOrder($order_info_result[ 'data' ][ 'order_id' ]);
return $res;
}
}

View File

@@ -1,29 +1,20 @@
<?php
/**
*/
namespace addon\pointexchange\event;
/**
* 订单营销活动类型
*/
class OrderPromotionType
{
/**
* 订单营销活动类型
* @return array
*/
public function handle()
{
return ["name" => "积分兑换", "type" => "pointexchange"];
}
<?php
namespace addon\pointexchange\event;
/**
* 订单营销活动类型
*/
class OrderPromotionType
{
/**
* 订单营销活动类型
* @return array
*/
public function handle()
{
return ["name" => "积分兑换", "type" => "pointexchange"];
}
}

View File

@@ -1,29 +1,20 @@
<?php
/**
*/
namespace addon\pointexchange\event;
use addon\pointexchange\model\Order;
/**
* 积分兑换订单异步回调执行
*/
class PointexchangeOrderPayNotify
{
// 行为扩展的执行入口必须是run
public function handle($data)
{
$order = new Order();
$order->orderPay($data);
}
<?php
namespace addon\pointexchange\event;
use addon\pointexchange\model\Order;
/**
* 积分兑换订单异步回调执行
*/
class PointexchangeOrderPayNotify
{
// 行为扩展的执行入口必须是run
public function handle($data)
{
$order = new Order();
$order->orderPay($data);
}
}

View File

@@ -1,52 +1,44 @@
<?php
/**
*/
namespace addon\pointexchange\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'admin' => [
],
'shop' => [
[
//插件名称
'name' => 'pointexchange',
//展示分类根据平台端设置admin平台营销shop店铺营销member:会员营销, tool:应用工具)
'show_type' => 'shop',
//展示主题
'title' => '积分商城',
//展示介绍
'description' => '客户积分兑换更多好物',
//展示图标
'icon' => 'addon/pointexchange/icon.png',
//跳转链接
'url' => 'pointexchange://shop/exchange/lists',
],
],
];
return $data;
}
<?php
namespace addon\pointexchange\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'admin' => [
],
'shop' => [
[
//插件名称
'name' => 'pointexchange',
//展示分类根据平台端设置admin平台营销shop店铺营销member:会员营销, tool:应用工具)
'show_type' => 'shop',
//展示主题
'title' => '积分商城',
//展示介绍
'description' => '客户积分兑换更多好物',
//展示图标
'icon' => 'addon/pointexchange/icon.png',
//跳转链接
'url' => 'pointexchange://shop/exchange/lists',
],
],
];
return $data;
}
}

View File

@@ -1,26 +1,18 @@
<?php
/**
*/
namespace addon\pointexchange\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return error("系统插件不能删除");
}
<?php
namespace addon\pointexchange\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return error("系统插件不能删除");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,155 +1,146 @@
<?php
/**
*/
namespace addon\pointexchange\model\share;
use addon\pointexchange\model\Exchange as ExchangeModel;
use app\model\share\WchatShareBase as BaseModel;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WchatShare extends BaseModel
{
protected $config = [
[
'title' => '积分商城',
'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_LIST',
'path' => [ '/pages_promotion/point/list' ],
'method_prefix' => 'goodsList',
],
[
'title' => '积分商品',
'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_DETAIL',
'path' => [ '/pages_promotion/point/detail' ],
'method_prefix' => 'goodsDetail',
],
];
protected $sort = 6;
/**
* 积分商城列表
* @param $param
* @return array
*/
protected function goodsListShareData($param)
{
//跳转路径
$link = $this->getShareLink($param);
$config_data = $this->goodsListShareConfig($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 goodsListShareConfig($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' => "积分兑换更优惠哦",
'imgUrl' => ''
];
}
if (empty($data[ 'value' ][ 'imgUrl' ])) {
$data[ 'value' ][ 'imgUrl' ] = img('addon/pointexchange/icon.png');
}
return [
'value' => $data[ 'value' ],
];
}
/**
* 积分商城详情
* @param $param
* @return array
*/
protected function goodsDetailShareData($param)
{
$site_id = $param[ 'site_id' ] ?? 0;
parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
if (isset($query[ 'id' ])) {
$id = $query[ 'id' ];
$exchange_model = new ExchangeModel();
$exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id');
$exchange_info = $exchange_info[ 'data' ];
$condition = [
[ 'peg.id', '=', $id ],
[ 'peg.site_id', '=', $site_id ],
[ 'peg.state', '=', 1 ],
];
$exchange_detail = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
if (!empty($exchange_detail)) {
$image_url = '';
$title = '';
switch ( $exchange_detail[ 'type' ] ) {
case 1://商品
$title = $exchange_detail[ 'sku_name' ];
$image_url = $exchange_detail[ 'sku_image' ];
break;
case 2://优惠券
case 3://红包
$title = $exchange_detail[ 'name' ];
$image_url = $exchange_detail[ 'image' ];
break;
}
if ($image_url) {
$image_url = img($image_url);
} else {
$image_url = $this->getDefaultShareIcon();
}
$exchange_condition = [];
if ($exchange_detail[ 'point' ] > 0) $exchange_condition[] = "{$exchange_detail['point']}积分";
if ($exchange_detail[ 'exchange_price' ] > 0) $exchange_condition[] = "{$exchange_detail['exchange_price']}";
$desc = "仅需" . join("+", $exchange_condition) . "即可兑换";
$link = $this->getShareLink($param);
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => $image_url,
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
}
}
}
<?php
namespace addon\pointexchange\model\share;
use addon\pointexchange\model\Exchange as ExchangeModel;
use app\model\share\WchatShareBase as BaseModel;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WchatShare extends BaseModel
{
protected $config = [
[
'title' => '积分商城',
'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_LIST',
'path' => [ '/pages_promotion/point/list' ],
'method_prefix' => 'goodsList',
],
[
'title' => '积分商品',
'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_DETAIL',
'path' => [ '/pages_promotion/point/detail' ],
'method_prefix' => 'goodsDetail',
],
];
protected $sort = 6;
/**
* 积分商城列表
* @param $param
* @return array
*/
protected function goodsListShareData($param)
{
//跳转路径
$link = $this->getShareLink($param);
$config_data = $this->goodsListShareConfig($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 goodsListShareConfig($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' => "积分兑换更优惠哦",
'imgUrl' => ''
];
}
if (empty($data[ 'value' ][ 'imgUrl' ])) {
$data[ 'value' ][ 'imgUrl' ] = img('addon/pointexchange/icon.png');
}
return [
'value' => $data[ 'value' ],
];
}
/**
* 积分商城详情
* @param $param
* @return array
*/
protected function goodsDetailShareData($param)
{
$site_id = $param[ 'site_id' ] ?? 0;
parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
if (isset($query[ 'id' ])) {
$id = $query[ 'id' ];
$exchange_model = new ExchangeModel();
$exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id');
$exchange_info = $exchange_info[ 'data' ];
$condition = [
[ 'peg.id', '=', $id ],
[ 'peg.site_id', '=', $site_id ],
[ 'peg.state', '=', 1 ],
];
$exchange_detail = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
if (!empty($exchange_detail)) {
$image_url = '';
$title = '';
switch ( $exchange_detail[ 'type' ] ) {
case 1://商品
$title = $exchange_detail[ 'sku_name' ];
$image_url = $exchange_detail[ 'sku_image' ];
break;
case 2://优惠券
case 3://红包
$title = $exchange_detail[ 'name' ];
$image_url = $exchange_detail[ 'image' ];
break;
}
if ($image_url) {
$image_url = img($image_url);
} else {
$image_url = $this->getDefaultShareIcon();
}
$exchange_condition = [];
if ($exchange_detail[ 'point' ] > 0) $exchange_condition[] = "{$exchange_detail['point']}积分";
if ($exchange_detail[ 'exchange_price' ] > 0) $exchange_condition[] = "{$exchange_detail['exchange_price']}";
$desc = "仅需" . join("+", $exchange_condition) . "即可兑换";
$link = $this->getShareLink($param);
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => $image_url,
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
}
}
}

View File

@@ -1,302 +1,294 @@
<?php
/**
*/
namespace addon\pointexchange\shop\controller;
use addon\coupon\model\CouponType as CouponTypeModel;
use addon\pointexchange\model\Exchange as ExchangeModel;
use app\shop\controller\BaseShop;
use app\model\express\ExpressTemplate as ExpressTemplateModel;
/**
* 积分兑换
* @author Administrator
*
*/
class Exchange extends BaseShop
{
/**
* 积分兑换列表
*/
public function lists()
{
if (request()->isJson()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$search_text = input('search_text', '');
$type = input('type', '');
$state = input('state', '');
$sort = input('sort', 'asc');
$condition[] = [ 'peg.site_id', '=', $this->site_id ];
if ($search_text) {
$condition[] = [ 'peg.name', 'like', '%' . $search_text . '%' ];
}
if ($type) {
$condition[] = [ 'peg.type', '=', $type ];
}
if ($state != '') {
$condition[] = [ 'peg.state', '=', $state ];
}
$field = 'peg.*';
$alias = 'peg';
$join = [];
//排序
$order = input('order', 'create_time');
$sort = input('sort', 'desc');
if ($order == 'sort') {
$order_by = 'peg.' . $order . ' ' . $sort;
} else {
$order_by = 'peg.' . $order . ' ' . $sort . ',peg.sort desc';
}
$exchange_model = new ExchangeModel();
//兑换名称 兑换图片 兑换库存 兑换价格
$lists = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
return $lists;
}
return $this->fetch("exchange/lists");
}
/**
* 添加积分兑换
*/
public function add()
{
if (request()->isJson()) {
$type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
$data = [
'site_id' => $this->site_id,
'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
'point' => input('point', ''),//积分
'state' => input('state', ''),
'is_free_shipping' => input('is_free_shipping', ''),
'delivery_type' => input('delivery_type', ''),
'delivery_price' => input('delivery_price', ''),
'shipping_template' => input('shipping_template', ''),
];
if ($type == 1) {
$data[ 'goods_data' ] = input('goods_data', '');
$data[ 'rule' ] = input('content', '');
$data[ 'type_name' ] = '商品';
} elseif ($type == 2) {
$data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '优惠券';
$data[ 'stock' ] = input('stock', '');
} elseif ($type == 3) {
$data[ 'name' ] = input('name', '');
$data[ 'image' ] = input('image', '');
$data[ 'stock' ] = input('stock', '');
$data[ 'balance' ] = input('balance', '0');
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '红包';
} else {
return error(-1, '');
}
$exchange_model = new ExchangeModel();
$res = $exchange_model->addExchange($data);
return $res;
} else {
//获取运费模板
$express_template_model = new ExpressTemplateModel();
$express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
$express_template_list = $express_template_list[ 'data' ];
$this->assign("express_template_list", $express_template_list);
return $this->fetch("exchange/add");
}
}
/**
* 编辑积分兑换
*/
public function edit()
{
$id = input("id", 0);
$exchange_model = new ExchangeModel();
if (request()->isJson()) {
$type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
$data = [
'site_id' => $this->site_id,
'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
'point' => input('point', ''),//积分
'state' => input('state', ''),
'id' => $id,
'is_free_shipping' => input('is_free_shipping', ''),
'delivery_type' => input('delivery_type', ''),
'delivery_price' => input('delivery_price', ''),
'shipping_template' => input('shipping_template', ''),
];
if ($type == 1) {
$data[ 'goods_data' ] = input('goods_data', '');
$data[ 'rule' ] = input('content', '');
$data[ 'type_name' ] = '商品';
} elseif ($type == 2) {
$data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '优惠券';
$data[ 'stock' ] = input('stock', '');
} elseif ($type == 3) {
$data[ 'name' ] = input('name', '');
$data[ 'image' ] = input('image', '');
$data[ 'stock' ] = input('stock', '');
$data[ 'balance' ] = input('balance', '0');
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '红包';
} else {
return error(-1, '');
}
$res = $exchange_model->editExchange($data);
return $res;
} else {
$exchange_info = $exchange_model->getExchangeGoodsDetail($id, $this->site_id);
if (empty($exchange_info[ 'data' ][ 'id' ])) {
$this->error('对应的积分兑换活动商品/优惠券已经不存在了!');
}
$this->assign("exchange_info", $exchange_info[ 'data' ]);
//获取运费模板
$express_template_model = new ExpressTemplateModel();
$express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
$express_template_list = $express_template_list[ 'data' ];
$this->assign("express_template_list", $express_template_list);
return $this->fetch("exchange/edit");
}
}
/**
*关闭积分兑换
*/
public function delete()
{
$id = input("id", 0);
$exchange_model = new ExchangeModel();
$res = $exchange_model->deleteExchange($id);
return $res;
}
/**
* 修改排序
*/
public function modifySort()
{
$sort = input('sort', 0);
$id = input('id', 0);
$exchange_model = new ExchangeModel();
return $exchange_model->modifyExchangeSort($sort, $id);
}
/**
* 获取商品列表
* @return array
*/
public function getSkuList()
{
if (request()->isJson()) {
$exchange_model = new ExchangeModel();
$exchange_id = input('exchange_id', '');
$field = 'pe.*,sku.sku_name,sku.price as market_price,sku.sku_image,sku.stock';
$alias = 'pe';
$join = [
[
'promotion_exchange_goods peg',
'peg.id = pe.exchange_goods_id',
'inner'
],
[
'goods_sku sku',
'sku.sku_id = pe.type_id',
'inner'
]
];
$condition = [
[ 'peg.id', '=', $exchange_id ],
[ 'sku.is_delete', '=', 0 ],
[ 'sku.goods_state', '=', 1 ],
[ 'peg.state', '=', 1 ],
];
$goods_list = $exchange_model->getExchangeList($condition, $field, '', null, $alias, $join);
foreach ($goods_list[ 'data' ] as $k => $v) {
$goods_list[ 'data' ][ $k ][ 'stock' ] = numberFormat($goods_list[ 'data' ][ $k ][ 'stock' ]);
}
return $goods_list;
}
}
/**
* 获取优惠券列表
*/
public function getCouponList()
{
$coupon_type_model = new CouponTypeModel();
if (request()->isJson()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$status = input('status', '');
$condition = [];
if ($status !== "") {
$condition[] = [ 'status', '=', $status ];
}
$condition[] = [ 'site_id', '=', $this->site_id ];
$order = 'sort asc';
$field = '*';
$res = $coupon_type_model->getCouponTypePageList($condition, $page, $page_size, $order, $field);
$exchange_model = new ExchangeModel();
//兑换名称 兑换图片 兑换库存 兑换价格
$exchange_list = $exchange_model->getExchangeList([ [ 'type', '=', 2 ] ], 'type_id')[ 'data' ] ?? [];
if ($exchange_list) {
$exchange_list = array_column($exchange_list, 'type_id');
}
if ($res[ 'data' ][ 'list' ]) {
foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
if (in_array($val[ 'coupon_type_id' ], $exchange_list)) {
$res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 1;
} else {
$res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 0;
}
}
}
return $res;
}
}
/**
*关闭积分兑换
*/
public function deleteAll()
{
if (request()->isJson()) {
$id = input("exchange_id", '');
$exchange_model = new ExchangeModel();
foreach ($id as $k => $v){
$res = $exchange_model->deleteExchange($v);
}
return $res;
}
}
<?php
namespace addon\pointexchange\shop\controller;
use addon\coupon\model\CouponType as CouponTypeModel;
use addon\pointexchange\model\Exchange as ExchangeModel;
use app\shop\controller\BaseShop;
use app\model\express\ExpressTemplate as ExpressTemplateModel;
/**
* 积分兑换
* @author Administrator
*
*/
class Exchange extends BaseShop
{
/**
* 积分兑换列表
*/
public function lists()
{
if (request()->isJson()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$search_text = input('search_text', '');
$type = input('type', '');
$state = input('state', '');
$sort = input('sort', 'asc');
$condition[] = [ 'peg.site_id', '=', $this->site_id ];
if ($search_text) {
$condition[] = [ 'peg.name', 'like', '%' . $search_text . '%' ];
}
if ($type) {
$condition[] = [ 'peg.type', '=', $type ];
}
if ($state != '') {
$condition[] = [ 'peg.state', '=', $state ];
}
$field = 'peg.*';
$alias = 'peg';
$join = [];
//排序
$order = input('order', 'create_time');
$sort = input('sort', 'desc');
if ($order == 'sort') {
$order_by = 'peg.' . $order . ' ' . $sort;
} else {
$order_by = 'peg.' . $order . ' ' . $sort . ',peg.sort desc';
}
$exchange_model = new ExchangeModel();
//兑换名称 兑换图片 兑换库存 兑换价格
$lists = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
return $lists;
}
return $this->fetch("exchange/lists");
}
/**
* 添加积分兑换
*/
public function add()
{
if (request()->isJson()) {
$type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
$data = [
'site_id' => $this->site_id,
'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
'point' => input('point', ''),//积分
'state' => input('state', ''),
'is_free_shipping' => input('is_free_shipping', ''),
'delivery_type' => input('delivery_type', ''),
'delivery_price' => input('delivery_price', ''),
'shipping_template' => input('shipping_template', ''),
];
if ($type == 1) {
$data[ 'goods_data' ] = input('goods_data', '');
$data[ 'rule' ] = input('content', '');
$data[ 'type_name' ] = '商品';
} elseif ($type == 2) {
$data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '优惠券';
$data[ 'stock' ] = input('stock', '');
} elseif ($type == 3) {
$data[ 'name' ] = input('name', '');
$data[ 'image' ] = input('image', '');
$data[ 'stock' ] = input('stock', '');
$data[ 'balance' ] = input('balance', '0');
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '红包';
} else {
return error(-1, '');
}
$exchange_model = new ExchangeModel();
$res = $exchange_model->addExchange($data);
return $res;
} else {
//获取运费模板
$express_template_model = new ExpressTemplateModel();
$express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
$express_template_list = $express_template_list[ 'data' ];
$this->assign("express_template_list", $express_template_list);
return $this->fetch("exchange/add");
}
}
/**
* 编辑积分兑换
*/
public function edit()
{
$id = input("id", 0);
$exchange_model = new ExchangeModel();
if (request()->isJson()) {
$type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
$data = [
'site_id' => $this->site_id,
'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
'point' => input('point', ''),//积分
'state' => input('state', ''),
'id' => $id,
'is_free_shipping' => input('is_free_shipping', ''),
'delivery_type' => input('delivery_type', ''),
'delivery_price' => input('delivery_price', ''),
'shipping_template' => input('shipping_template', ''),
];
if ($type == 1) {
$data[ 'goods_data' ] = input('goods_data', '');
$data[ 'rule' ] = input('content', '');
$data[ 'type_name' ] = '商品';
} elseif ($type == 2) {
$data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '优惠券';
$data[ 'stock' ] = input('stock', '');
} elseif ($type == 3) {
$data[ 'name' ] = input('name', '');
$data[ 'image' ] = input('image', '');
$data[ 'stock' ] = input('stock', '');
$data[ 'balance' ] = input('balance', '0');
$data[ 'content' ] = input('content', '');
$data[ 'type_name' ] = '红包';
} else {
return error(-1, '');
}
$res = $exchange_model->editExchange($data);
return $res;
} else {
$exchange_info = $exchange_model->getExchangeGoodsDetail($id, $this->site_id);
if (empty($exchange_info[ 'data' ][ 'id' ])) {
$this->error('对应的积分兑换活动商品/优惠券已经不存在了!');
}
$this->assign("exchange_info", $exchange_info[ 'data' ]);
//获取运费模板
$express_template_model = new ExpressTemplateModel();
$express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
$express_template_list = $express_template_list[ 'data' ];
$this->assign("express_template_list", $express_template_list);
return $this->fetch("exchange/edit");
}
}
/**
*关闭积分兑换
*/
public function delete()
{
$id = input("id", 0);
$exchange_model = new ExchangeModel();
$res = $exchange_model->deleteExchange($id);
return $res;
}
/**
* 修改排序
*/
public function modifySort()
{
$sort = input('sort', 0);
$id = input('id', 0);
$exchange_model = new ExchangeModel();
return $exchange_model->modifyExchangeSort($sort, $id);
}
/**
* 获取商品列表
* @return array
*/
public function getSkuList()
{
if (request()->isJson()) {
$exchange_model = new ExchangeModel();
$exchange_id = input('exchange_id', '');
$field = 'pe.*,sku.sku_name,sku.price as market_price,sku.sku_image,sku.stock';
$alias = 'pe';
$join = [
[
'promotion_exchange_goods peg',
'peg.id = pe.exchange_goods_id',
'inner'
],
[
'goods_sku sku',
'sku.sku_id = pe.type_id',
'inner'
]
];
$condition = [
[ 'peg.id', '=', $exchange_id ],
[ 'sku.is_delete', '=', 0 ],
[ 'sku.goods_state', '=', 1 ],
[ 'peg.state', '=', 1 ],
];
$goods_list = $exchange_model->getExchangeList($condition, $field, '', null, $alias, $join);
foreach ($goods_list[ 'data' ] as $k => $v) {
$goods_list[ 'data' ][ $k ][ 'stock' ] = numberFormat($goods_list[ 'data' ][ $k ][ 'stock' ]);
}
return $goods_list;
}
}
/**
* 获取优惠券列表
*/
public function getCouponList()
{
$coupon_type_model = new CouponTypeModel();
if (request()->isJson()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$status = input('status', '');
$condition = [];
if ($status !== "") {
$condition[] = [ 'status', '=', $status ];
}
$condition[] = [ 'site_id', '=', $this->site_id ];
$order = 'sort asc';
$field = '*';
$res = $coupon_type_model->getCouponTypePageList($condition, $page, $page_size, $order, $field);
$exchange_model = new ExchangeModel();
//兑换名称 兑换图片 兑换库存 兑换价格
$exchange_list = $exchange_model->getExchangeList([ [ 'type', '=', 2 ] ], 'type_id')[ 'data' ] ?? [];
if ($exchange_list) {
$exchange_list = array_column($exchange_list, 'type_id');
}
if ($res[ 'data' ][ 'list' ]) {
foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
if (in_array($val[ 'coupon_type_id' ], $exchange_list)) {
$res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 1;
} else {
$res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 0;
}
}
}
return $res;
}
}
/**
*关闭积分兑换
*/
public function deleteAll()
{
if (request()->isJson()) {
$id = input("exchange_id", '');
$exchange_model = new ExchangeModel();
foreach ($id as $k => $v){
$res = $exchange_model->deleteExchange($v);
}
return $res;
}
}
}

View File

@@ -1,113 +1,105 @@
<?php
/**
*/
namespace addon\Pointexchange\shop\controller;
use addon\pointexchange\model\Order as ExchangeOrderModel;
use app\shop\controller\BaseShop;
use think\App;
/**
* 兑换发放订单
*/
class Pointexchange extends BaseShop
{
public function __construct(App $app = null)
{
$this->replace = [
'POINTEXCHANGE_CSS' => __ROOT__ . '/addon/pointexchange/shop/view/public/css',
'POINTEXCHANGE_JS' => __ROOT__ . '/addon/pointexchange/shop/view/public/js',
'POINTEXCHANGE_IMG' => __ROOT__ . '/addon/pointexchange/shop/view/public/img',
];
parent::__construct($app);
}
/**
* 兑换订单列表
* @return mixed
*/
public function lists()
{
$exchange_id = input('exchange_id', '');
if (request()->isJson()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$search_text = input('search_text', '');
$condition = [
['eo.site_id','=',$this->site_id]
];
if ($search_text) {
$condition[] = [ 'eo.exchange_name', 'like', '%' . $search_text . '%' ];
}
$name = input('name', '');
if (!empty($name)) {
$condition[] = [ 'm.nickname', 'like', '%' . $name . '%' ];
}
$mobile = input('mobile', '');
if (!empty($mobile)) {
$condition[] = [ 'eo.mobile', 'like', '%' . $mobile . '%' ];
}
$type = input('type', '');
if ($type) {
$condition[] = [ 'eo.type', '=', $type ];
}
if ($exchange_id) {
$condition[] = [ 'eo.exchange_goods_id', '=', $exchange_id ];
}
$start_time = input('start_time', '');
$end_time = input('end_time', '');
if ($start_time && !$end_time) {
$condition[] = [ 'eo.pay_time', '>=', date_to_time($start_time) ];
} elseif (!$start_time && $end_time) {
$condition[] = [ 'eo.pay_time', '<=', date_to_time($end_time) ];
} elseif ($start_time && $end_time) {
$condition[] = [ 'eo.pay_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
}
$order = 'eo.create_time desc';
$field = 'eo.*,m.nickname';
$exchange_order_model = new ExchangeOrderModel();
$list = $exchange_order_model->getExchangePageList($condition, $page, $page_size, $order, $field, 'eo', [
[ 'member m', 'm.member_id=eo.member_id', 'left' ]
]);
// file_put_contents(__DIR__ . '/debug.txt', var_export($condition,true));
return $list;
} else {
$this->assign('exchange_id', $exchange_id);
return $this->fetch("exchange_order/lists");
}
}
/**订单详情
* @return mixed
*/
public function detail()
{
$order_id = input('order_id', 0);
$order_model = new ExchangeOrderModel();
$order_info = $order_model->getOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'order_id', '=', $order_id ] ]);
$order_info = $order_info[ "data" ];
if (empty($order_info)) $this->error('未获取到订单数据', href_url('pointexchange://shop/pointexchange/lists'));
$this->assign("order_info", $order_info);
return $this->fetch('exchange_order/detail');
}
<?php
namespace addon\Pointexchange\shop\controller;
use addon\pointexchange\model\Order as ExchangeOrderModel;
use app\shop\controller\BaseShop;
use think\App;
/**
* 兑换发放订单
*/
class Pointexchange extends BaseShop
{
public function __construct(App $app = null)
{
$this->replace = [
'POINTEXCHANGE_CSS' => __ROOT__ . '/addon/pointexchange/shop/view/public/css',
'POINTEXCHANGE_JS' => __ROOT__ . '/addon/pointexchange/shop/view/public/js',
'POINTEXCHANGE_IMG' => __ROOT__ . '/addon/pointexchange/shop/view/public/img',
];
parent::__construct($app);
}
/**
* 兑换订单列表
* @return mixed
*/
public function lists()
{
$exchange_id = input('exchange_id', '');
if (request()->isJson()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$search_text = input('search_text', '');
$condition = [
['eo.site_id','=',$this->site_id]
];
if ($search_text) {
$condition[] = [ 'eo.exchange_name', 'like', '%' . $search_text . '%' ];
}
$name = input('name', '');
if (!empty($name)) {
$condition[] = [ 'm.nickname', 'like', '%' . $name . '%' ];
}
$mobile = input('mobile', '');
if (!empty($mobile)) {
$condition[] = [ 'eo.mobile', 'like', '%' . $mobile . '%' ];
}
$type = input('type', '');
if ($type) {
$condition[] = [ 'eo.type', '=', $type ];
}
if ($exchange_id) {
$condition[] = [ 'eo.exchange_goods_id', '=', $exchange_id ];
}
$start_time = input('start_time', '');
$end_time = input('end_time', '');
if ($start_time && !$end_time) {
$condition[] = [ 'eo.pay_time', '>=', date_to_time($start_time) ];
} elseif (!$start_time && $end_time) {
$condition[] = [ 'eo.pay_time', '<=', date_to_time($end_time) ];
} elseif ($start_time && $end_time) {
$condition[] = [ 'eo.pay_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
}
$order = 'eo.create_time desc';
$field = 'eo.*,m.nickname';
$exchange_order_model = new ExchangeOrderModel();
$list = $exchange_order_model->getExchangePageList($condition, $page, $page_size, $order, $field, 'eo', [
[ 'member m', 'm.member_id=eo.member_id', 'left' ]
]);
// file_put_contents(__DIR__ . '/debug.txt', var_export($condition,true));
return $list;
} else {
$this->assign('exchange_id', $exchange_id);
return $this->fetch("exchange_order/lists");
}
}
/**订单详情
* @return mixed
*/
public function detail()
{
$order_id = input('order_id', 0);
$order_model = new ExchangeOrderModel();
$order_info = $order_model->getOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'order_id', '=', $order_id ] ]);
$order_info = $order_info[ "data" ];
if (empty($order_info)) $this->error('未获取到订单数据', href_url('pointexchange://shop/pointexchange/lists'));
$this->assign("order_info", $order_info);
return $this->fetch('exchange_order/detail');
}
}