初始上传
This commit is contained in:
302
addon/pointexchange/shop/controller/Exchange.php
Executable file
302
addon/pointexchange/shop/controller/Exchange.php
Executable file
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
108
addon/pointexchange/shop/controller/Pointexchange.php
Executable file
108
addon/pointexchange/shop/controller/Pointexchange.php
Executable file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
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 = [];
|
||||
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();
|
||||
return $exchange_order_model->getExchangePageList($condition, $page, $page_size, $order, $field, 'eo', [
|
||||
[ 'member m', 'm.member_id=eo.member_id', 'left' ]
|
||||
]);
|
||||
} 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');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user