初始上传
This commit is contained in:
209
addon/pointexchange/api/controller/Goods.php
Executable file
209
addon/pointexchange/api/controller/Goods.php
Executable file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
83
addon/pointexchange/api/controller/Order.php
Executable file
83
addon/pointexchange/api/controller/Order.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
112
addon/pointexchange/api/controller/Ordercreate.php
Executable file
112
addon/pointexchange/api/controller/Ordercreate.php
Executable file
@@ -0,0 +1,112 @@
|
||||
<?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\pointexchange\api\controller;
|
||||
|
||||
use app\api\controller\BaseApi;
|
||||
use addon\pointexchange\model\OrderCreate as OrderCreateModel;
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
*
|
||||
*/
|
||||
class Ordercreate extends BaseApi
|
||||
{
|
||||
/**
|
||||
* 创建订单
|
||||
*/
|
||||
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' ] ?? '',
|
||||
'member_id' => $this->member_id,
|
||||
'site_id' => $this->site_id,
|
||||
'order_from' => $this->params[ 'app_type' ],
|
||||
'order_from_name' => $this->params[ 'app_type_name' ],
|
||||
|
||||
'delivery' => isset($this->params[ 'delivery' ]) && !empty($this->params[ 'delivery' ]) ? json_decode($this->params[ 'delivery' ], true) : [],
|
||||
'member_address' => isset($this->params[ 'member_address' ]) && !empty($this->params[ 'member_address' ]) ? json_decode($this->params[ 'member_address' ], true) : [],
|
||||
'latitude' => $this->params[ 'latitude' ] ?? '',
|
||||
'longitude' => $this->params[ 'longitude' ] ?? '',
|
||||
// 'buyer_ask_delivery_time' => !empty($this->params[ 'buyer_ask_delivery_time' ]) ? $this->params[ 'buyer_ask_delivery_time' ] : '',
|
||||
|
||||
'buyer_message' => $this->params[ 'buyer_message' ],
|
||||
];
|
||||
|
||||
$res = $order_create->setParam($data)->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' ] ?? '',
|
||||
'member_id' => $this->member_id,
|
||||
'site_id' => $this->site_id,
|
||||
'order_from' => $this->params[ 'app_type' ],
|
||||
'order_from_name' => $this->params[ 'app_type_name' ],
|
||||
|
||||
'delivery' => isset($this->params[ 'delivery' ]) && !empty($this->params[ 'delivery' ]) ? json_decode($this->params[ 'delivery' ], true) : [],
|
||||
'member_address' => isset($this->params[ 'member_address' ]) && !empty($this->params[ 'member_address' ]) ? json_decode($this->params[ 'member_address' ], true) : [],
|
||||
'latitude' => $this->params[ 'latitude' ] ?? '',
|
||||
'longitude' => $this->params[ 'longitude' ] ?? '',
|
||||
// 'buyer_ask_delivery_time' => !empty($this->params[ 'buyer_ask_delivery_time' ]) ? $this->params[ 'buyer_ask_delivery_time' ] : '',
|
||||
];
|
||||
$res = $order_create->setParam($data)->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[ 'id' ] ?? '',//兑换id
|
||||
'num' => $this->params[ 'num' ] ?? 1,//兑换数量(买几套)
|
||||
'sku_id' => $this->params[ 'sku_id' ] ?? 0,
|
||||
'site_id' => $this->site_id,//站点id
|
||||
'member_id' => $this->member_id,
|
||||
'order_from' => $this->params[ 'app_type' ],
|
||||
'order_from_name' => $this->params[ 'app_type_name' ],
|
||||
'latitude' => $this->params[ 'latitude' ] ?? '',
|
||||
'longitude' => $this->params[ 'longitude' ] ?? '',
|
||||
|
||||
];
|
||||
if (empty($data[ 'id' ])) {
|
||||
return $this->response($this->error('', '缺少必填参数商品数据'));
|
||||
}
|
||||
if($data['num'] < 1){
|
||||
return $this->response($this->error('', '兑换数量不能小于1'));
|
||||
}
|
||||
$res = $order_create->setParam($data)->payment();
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user