初始上传
This commit is contained in:
316
addon/cardservice/api/controller/Card.php
Executable file
316
addon/cardservice/api/controller/Card.php
Executable file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\cardservice\api\controller;
|
||||
|
||||
use addon\cardservice\model\CardGoods;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\model\goods\Goods;
|
||||
use app\model\goods\GoodsService;
|
||||
use app\model\store\Store;
|
||||
use app\model\storegoods\StoreGoods;
|
||||
use app\model\web\Config as ConfigModel;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 卡项
|
||||
*/
|
||||
class Card extends BaseApi
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->initStoreData();
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
$sku_id = $this->params['sku_id'] ?? 0;
|
||||
$goods_id = $this->params['goods_id'] ?? 0;
|
||||
$goods = new CardGoods();
|
||||
if (empty($sku_id) && !empty($goods_id)) {
|
||||
$sku_id = $goods->getGoodsInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id')[ 'data' ][ 'sku_id' ] ?? 0;
|
||||
}
|
||||
if (empty($sku_id) && empty($goods_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
|
||||
$condition = [
|
||||
[ 'gs.sku_id', '=', $sku_id ],
|
||||
[ 'gs.site_id', '=', $this->site_id ],
|
||||
[ 'gs.is_delete', '=', 0 ],
|
||||
[ 'g.goods_class', '=', $goods->getGoodsClass()[ 'id' ] ]
|
||||
];
|
||||
$field = 'gs.goods_id,gs.sku_id,gs.qr_id,gs.goods_name,gs.sku_name,gs.sku_spec_format,gs.price,gs.market_price,gs.discount_price,gs.promotion_type,gs.start_time
|
||||
,gs.end_time,gs.stock,gs.click_num,(g.sale_num + g.virtual_sale) as sale_num,gs.collect_num,gs.sku_image,gs.sku_images
|
||||
,gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time
|
||||
,gs.goods_content,gs.goods_state,gs.is_free_shipping,gs.goods_spec_format,gs.goods_attr_format,gs.introduction,gs.unit,gs.video_url
|
||||
,gs.is_virtual,gs.goods_service_ids,gs.max_buy,gs.min_buy,gs.is_limit,gs.limit_type,gs.support_trade_type,g.goods_image,g.keywords,g.stock_show,g.sale_show,g.market_price_show,g.barrage_show,g.evaluate,g.sale_store,g.sale_channel';
|
||||
$join = [
|
||||
[ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
|
||||
];
|
||||
|
||||
// 如果是连锁运营模式
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
$join[] = [ 'store_goods_sku sgs', 'gs.goods_id = sgs.goods_id and sgs.store_id=' . $this->store_id, 'left' ];
|
||||
|
||||
$field .= ',IFNULL(sgs.status, 0) as store_goods_status';
|
||||
|
||||
$field = str_replace('gs.price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as price', $field);
|
||||
$field = str_replace('gs.discount_price', 'IFNULL(IF(g.is_unify_price = 1,gs.discount_price,sgs.price), gs.discount_price) as discount_price', $field);
|
||||
if ($this->store_data[ 'store_info' ][ 'stock_type' ] == 'store') {
|
||||
$field = str_replace('gs.stock', 'IFNULL(sgs.stock, 0) as stock', $field);
|
||||
}
|
||||
}
|
||||
$goods_sku_detail = $goods->getGoodsSkuInfo($condition, $field, 'gs', $join)[ 'data' ];
|
||||
if (empty($goods_sku_detail)) return $this->response($this->error());
|
||||
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
// 销售渠道设置为线上销售时门店商品状态为1
|
||||
if ($goods_sku_detail[ 'sale_channel' ] == 'online') {
|
||||
$goods_sku_detail[ 'store_goods_status' ] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$goods_sku_detail[ 'purchased_num' ] = 0; // 该商品已购数量
|
||||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||||
|
||||
// 商品服务
|
||||
$goods_service = new GoodsService();
|
||||
$goods_service_list = $goods_service->getServiceList([ [ 'site_id', '=', $this->site_id ], [ 'id', 'in', $res[ 'goods_sku_detail' ][ 'goods_service_ids' ] ] ], 'service_name,desc,icon');
|
||||
$res[ 'goods_sku_detail' ][ 'goods_service' ] = $goods_service_list[ 'data' ];
|
||||
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表信息
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
$goods_id_arr = $this->params['goods_id_arr'] ?? '';//goods_id数组
|
||||
$keyword = isset($this->params[ 'keyword' ]) ? trim($this->params[ 'keyword' ]) : '';//关键词
|
||||
$service_category = $this->params['service_category'] ?? 0;//分类
|
||||
$is_free_shipping = $this->params['is_free_shipping'] ?? 0;//是否免邮
|
||||
$order = $this->params['order'] ?? '';//排序(综合、销量、价格)
|
||||
$sort = $this->params['sort'] ?? '';//升序、降序
|
||||
$card_type = $this->params['card_type'] ?? '';
|
||||
|
||||
$condition = [];
|
||||
$condition[] = [ 'gs.site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'g.goods_class', '=', ( new CardGoods() )->getGoodsClass()[ 'id' ] ];
|
||||
$condition[] = [ '', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'online')") ];
|
||||
|
||||
if (!empty($goods_id_arr)) {
|
||||
$condition[] = [ 'gs.goods_id', 'in', $goods_id_arr ];
|
||||
}
|
||||
if (!empty($card_type)) {
|
||||
$condition[] = [ 'gc.card_type', '=', $card_type ];
|
||||
}
|
||||
if (!empty($service_category)) {
|
||||
$condition[] = [ 'g.service_category', 'like', '%,' . $service_category . ',%' ];
|
||||
}
|
||||
|
||||
if (!empty($keyword)) {
|
||||
$condition[] = [ 'g.goods_name|gs.sku_name|gs.keywords', 'like', '%' . $keyword . '%' ];
|
||||
}
|
||||
|
||||
if (!empty($is_free_shipping)) {
|
||||
$condition[] = [ 'gs.is_free_shipping', '=', $is_free_shipping ];
|
||||
}
|
||||
|
||||
// 非法参数进行过滤
|
||||
if ($sort != 'desc' && $sort != 'asc') {
|
||||
$sort = '';
|
||||
}
|
||||
|
||||
// 非法参数进行过滤
|
||||
if ($order != '') {
|
||||
if ($order != 'sale_num' && $order != 'discount_price') {
|
||||
$order = 'gs.sort';
|
||||
} elseif ($order == 'sale_num') {
|
||||
$order = 'sale_sort';
|
||||
} else {
|
||||
$order = 'gs.' . $order;
|
||||
}
|
||||
$order_by = $order . ' ' . $sort;
|
||||
} else {
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
|
||||
$order_by = 'g.sort ' . $sort_config[ 'type' ] . ',g.create_time desc';
|
||||
}
|
||||
|
||||
$condition[] = [ 'g.goods_state', '=', 1 ];
|
||||
$condition[] = [ 'g.is_delete', '=', 0 ];
|
||||
$condition[] = [ '', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'offline')") ];
|
||||
$alias = 'gs';
|
||||
|
||||
$field = 'gs.is_consume_discount,gs.discount_config,gs.discount_method,gs.member_price,gs.goods_id,gs.sort,gs.sku_id,gs.sku_name,gs.price,gs.market_price,gs.discount_price,gs.stock,(g.sale_num + g.virtual_sale) as sale_num,(gs.sale_num + gs.virtual_sale) as sale_sort,gs.sku_image,gs.goods_name,gs.site_id,gs.is_free_shipping,gs.introduction,gs.promotion_type,g.goods_image,g.promotion_addon,gs.is_virtual,g.goods_spec_format,g.recommend_way,gs.max_buy,gs.min_buy,gs.unit,gs.is_limit,gs.limit_type,g.label_name,g.stock_show,g.sale_show,g.market_price_show,g.barrage_show,g.sale_channel,g.sale_store,
|
||||
gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
|
||||
$join = [
|
||||
[ 'goods g', 'gs.sku_id = g.sku_id', 'inner' ],
|
||||
[ 'goods_card gc', 'gc.goods_id=gs.goods_id', 'left' ],
|
||||
];
|
||||
// 如果是连锁运营模式
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
$join[] = [ 'store_goods_sku sgs', 'sgs.status = 1 and g.sku_id = sgs.sku_id and sgs.store_id=' . $this->store_id, 'right' ];
|
||||
|
||||
$condition[] = [ 'g.sale_store', 'like', [ '%all%', '%,' . $this->store_id . ',%' ], 'or' ];
|
||||
|
||||
$field = str_replace('gs.price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as price', $field);
|
||||
$field = str_replace('gs.discount_price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as discount_price', $field);
|
||||
if ($this->store_data[ 'store_info' ][ 'stock_type' ] == 'store') {
|
||||
$field = str_replace('gs.stock', 'IFNULL(sgs.stock, 0) as stock', $field);
|
||||
}
|
||||
}
|
||||
|
||||
$goods = new Goods();
|
||||
$list = $goods->getGoodsSkuPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
|
||||
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
public function getCardListByType()
|
||||
{
|
||||
$goods = new CardGoods();
|
||||
$list = $goods->getCardType();
|
||||
$condition = [
|
||||
[ 'gs.site_id', '=', $this->site_id ],
|
||||
[ 'g.goods_class', '=', $goods->getGoodsClass()[ 'id' ] ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ],
|
||||
[ '', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'online')") ]
|
||||
];
|
||||
|
||||
$field = 'gs.is_consume_discount,gs.discount_config,gs.discount_method,gs.member_price,gs.goods_id,gs.sort,gs.sku_id,gs.sku_name,gs.price,gs.market_price,gs.discount_price,gs.stock,(g.sale_num + g.virtual_sale) as sale_num,(gs.sale_num + gs.virtual_sale) as sale_sort,gs.sku_image,gs.goods_name,gs.site_id,gs.is_free_shipping,gs.introduction,gs.promotion_type,g.goods_image,g.promotion_addon,gs.is_virtual,g.goods_spec_format,g.recommend_way,gs.max_buy,gs.min_buy,gs.unit,gs.is_limit,gs.limit_type,g.label_name,g.stock_show,g.sale_show,g.market_price_show,g.barrage_show,g.sale_channel,g.sale_store,
|
||||
gc.card_type,gc.card_type_name,gc.renew_price,gc.recharge_money,gc.common_num,gc.discount_goods_type,gc.discount,gc.validity_type,gc.validity_day,gc.validity_time';
|
||||
$join = [
|
||||
[ 'goods_sku gs', 'gs.sku_id = g.sku_id', 'inner' ],
|
||||
[ 'goods_card gc', 'gc.goods_id=gs.goods_id', 'left' ],
|
||||
];
|
||||
|
||||
// 如果是连锁运营模式
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
$join[] = [ 'store_goods_sku sgs', 'sgs.status = 1 and g.sku_id = sgs.sku_id and sgs.store_id=' . $this->store_id, 'right' ];
|
||||
|
||||
$condition[] = [ 'g.sale_store', 'like', [ '%all%', '%,' . $this->store_id . ',%' ], 'or' ];
|
||||
|
||||
$field = str_replace('gs.price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as price', $field);
|
||||
$field = str_replace('gs.discount_price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as discount_price', $field);
|
||||
if ($this->store_data[ 'store_info' ][ 'stock_type' ] == 'store') {
|
||||
$field = str_replace('gs.stock', 'IFNULL(sgs.stock, 0) as stock', $field);
|
||||
}
|
||||
}
|
||||
$card_list = $goods->getGoodsList($condition, $field, 'g.sort asc', 'g', $join);
|
||||
|
||||
foreach ($list as $k => $v) {
|
||||
$list[ $k ][ 'card_list' ] = [];
|
||||
foreach ($card_list[ 'data' ] as $key => $val) {
|
||||
if ($val[ 'card_type' ] == $v[ 'type' ]) {
|
||||
$list[ $k ][ 'card_list' ][] = $val;
|
||||
}
|
||||
}
|
||||
if (empty($list[ $k ][ 'card_list' ])) unset($list[ $k ]);
|
||||
}
|
||||
return $this->response($this->success($list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品关联的卡项套餐
|
||||
* @return array|false|string
|
||||
*/
|
||||
public function getRelationCardGoods()
|
||||
{
|
||||
$goods_id = $this->params[ 'goods_id' ] ?? '';
|
||||
$store_id = $this->params[ 'store_id' ] ?? '';
|
||||
if(empty($goods_id)){
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$condition = [
|
||||
[ 'goods_id', '=', $goods_id ]
|
||||
];
|
||||
$goods_card_res = (new CardGoods())->getGoodSCardItem($condition,'card_goods_id','id desc','','','card_goods_id');
|
||||
|
||||
if($goods_card_res['code'] < 0){
|
||||
return $this->response($this->error([]));
|
||||
}
|
||||
|
||||
$card_goods_id = array_column($goods_card_res['data'],'card_goods_id');
|
||||
$goods_condition = [
|
||||
['gci.card_goods_id','in',$card_goods_id],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ],
|
||||
];
|
||||
$join = [
|
||||
[ 'goods_card gc', 'gci.card_goods_id = gc.goods_id', 'left'],
|
||||
[ 'goods_sku gs', 'gci.card_goods_id = gs.goods_id', 'left' ],
|
||||
[ 'goods g', 'g.goods_id = gs.goods_id', 'left' ],
|
||||
[ 'goods_sku gck', 'gck.sku_id = gci.sku_id', 'left' ],
|
||||
];
|
||||
|
||||
if($store_id){
|
||||
if(addon_is_exit('store')){
|
||||
$config_model = new \addon\store\model\Config();
|
||||
$business_config = $config_model->getStoreBusinessConfig($this->site_id)['data']['value'];
|
||||
if ($business_config['store_business'] == 'store'){
|
||||
$goods_condition[] = ['', 'exp', Db::raw("g.sale_store = 'all' or FIND_IN_SET('{$store_id}', g.sale_store)")];
|
||||
//连锁门店模式
|
||||
$join[] = ['store_goods sg','sg.goods_id = gci.card_goods_id','left'];
|
||||
$goods_condition[] = [ 'sg.store_id', '=', $store_id];
|
||||
$goods_condition[] = [ 'sg.status', '=', 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$alias = 'gci';
|
||||
$field = "gc.card_type,gc.card_type_name,
|
||||
gci.num,gci.goods_id,gci.card_goods_id as goods_id,
|
||||
gs.is_consume_discount,gs.discount_config,gs.discount_method,gs.member_price,gs.sort,gs.sku_id,gs.sku_name,gs.price,gs.market_price,gs.discount_price,gs.stock,gs.sku_image,gs.goods_name,gs.site_id,gs.is_free_shipping,gs.introduction,gs.promotion_type,g.goods_stock,g.goods_image,g.promotion_addon,gs.is_virtual,g.goods_spec_format,g.recommend_way,gs.max_buy,gs.min_buy,gs.unit,gs.is_limit,gs.limit_type,g.label_name,g.stock_show,g.sale_show,g.market_price_show,g.barrage_show,g.sale_channel,g.sale_store,
|
||||
gck.sku_image as item_sku_image,gck.sku_name as item_sku_name,gck.goods_name as item_goods_name,gck.price as item_price,gck.goods_id as item_goods_id,gck.sku_id as item_sku_id";
|
||||
$all_goods_arr = (new CardGoods())->getGoodSCardItem($goods_condition,$field,'gci.id desc',$alias,$join);
|
||||
if($all_goods_arr['code'] < 0){
|
||||
return $this->response($this->error([]));
|
||||
}
|
||||
$data = [];
|
||||
foreach ($all_goods_arr['data'] as $k=>$v){
|
||||
if(!isset($data[$v['goods_id']])){
|
||||
$data[$v['goods_id']] = $v;
|
||||
$data[$v['goods_id']]['goods'] = [];
|
||||
}
|
||||
$group = $data[$v['goods_id']];
|
||||
$group['goods'][$v['item_sku_id']] = [
|
||||
'goods_id' => $v['item_goods_id'],
|
||||
'sku_id'=>$v['item_sku_id'],
|
||||
'sku_image' => $v['item_sku_image'],
|
||||
'goods_name' => $v['item_goods_name'],
|
||||
'sku_name' => $v['item_sku_name'],
|
||||
'price'=>$v['item_price'],
|
||||
'num'=>$v['num']
|
||||
];
|
||||
unset($group['item_goods_id'],$group['item_sku_image'],$group['item_sku_name'],$group['item_goods_name'],$group['item_price'],$group['num']);
|
||||
$data[$v['goods_id']] = $group;
|
||||
}
|
||||
$data = array_values($data);
|
||||
foreach ($data as $k=>$v){
|
||||
$data[$k]['goods'] = array_values($v['goods']);
|
||||
}
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] >= 0) {
|
||||
$goods = new Goods();
|
||||
$data = $goods->getGoodsListMemberPrice($data, $this->member_id);
|
||||
}
|
||||
return $this->response($this->success($data));
|
||||
}
|
||||
|
||||
}
|
||||
144
addon/cardservice/api/controller/Membercard.php
Executable file
144
addon/cardservice/api/controller/Membercard.php
Executable file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\cardservice\api\controller;
|
||||
|
||||
use addon\cardservice\model\MemberCard as MemberCardModel;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\model\verify\Verify;
|
||||
|
||||
/**
|
||||
* 会员卡项
|
||||
*/
|
||||
class Membercard extends BaseApi
|
||||
{
|
||||
|
||||
public function detail()
|
||||
{
|
||||
$this->initStoreData();
|
||||
|
||||
$card_id = $this->params['card_id'] ?? 0;
|
||||
if (empty($card_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
$model = new MemberCardModel();
|
||||
$condition = [
|
||||
[ 'mgc.site_id', '=', $this->site_id ],
|
||||
[ 'mgc.member_id', '=', $this->member_id ],
|
||||
[ 'mgc.card_id', '=', $card_id ],
|
||||
[ 'g.is_delete', '=', 0 ],
|
||||
];
|
||||
$field = 'mgc.*, g.goods_name,g.price,g.goods_image,g.introduction,g.goods_content';
|
||||
$join = [
|
||||
[ 'goods g', 'mgc.goods_id = g.goods_id', 'inner' ],
|
||||
];
|
||||
$info = $model->getCardInfo($condition, $field, 'mgc', $join)[ 'data' ];
|
||||
|
||||
$condition = [
|
||||
[ 'mgci.card_id', '=', $info[ 'card_id' ] ],
|
||||
];
|
||||
$stock_field = 'sku.stock';
|
||||
$join = [
|
||||
[ 'goods_sku sku', 'mgci.sku_id = sku.sku_id', 'inner' ],
|
||||
[ 'verify v', 'mgci.member_verify_id = v.id', 'left' ],
|
||||
];
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
$stock_field = 'sgs.stock';
|
||||
$join[] = [ 'store_goods_sku sgs', 'sku.sku_id = sgs.sku_id and sgs.store_id = '.$this->store_id, 'left'];
|
||||
}
|
||||
|
||||
$info[ 'card_item' ] = $model->getCartItemList($condition, 'mgci.*,sku.sku_name,sku.price,sku.sku_image,sku.sku_images,sku.goods_class_name,'.$stock_field.',
|
||||
v.verify_code,v.verify_type,v.verify_type_name,v.verify_content_json,v.verifier_id,v.verifier_name,v.is_verify,v.verify_time,v.expire_time,v.verify_from,v.verify_remark,v.verify_total_count,v.verify_use_num', 'mgci.card_id asc', 'mgci', $join)[ 'data' ] ?? [];
|
||||
|
||||
$verify = new Verify();
|
||||
foreach ($info[ 'card_item' ] as $k => $v) {
|
||||
if ($v[ 'member_verify_id' ] > 0) {
|
||||
$info[ 'card_item' ][ $k ][ 'verify_code_data' ] = $verify->qrcode($v[ 'verify_code' ], 'h5', 'pickup', $this->site_id, 'create')[ 'data' ] ?? [];
|
||||
$info[ 'card_item' ][ $k ][ 'barcode' ] = getBarcode($v[ 'verify_code' ], 'upload/qrcode/pickup');
|
||||
$info[ 'card_item' ][ $k ][ 'stock' ] = numberFormat($info[ 'card_item' ][ $k ][ 'stock' ]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response($this->success($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;
|
||||
$status = $this->params['status'] ?? 'all';
|
||||
|
||||
$condition = [];
|
||||
$condition[] = [ 'mgc.site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'mgc.member_id', '=', $this->member_id ];
|
||||
if ($status !== 'all') {
|
||||
$condition[] = [ 'mgc.status', '=', $status ];
|
||||
}
|
||||
$condition[] = [ 'g.is_delete', '=', 0 ];
|
||||
$alias = 'mgc';
|
||||
|
||||
$field = 'mgc.*, g.goods_name,g.price,g.goods_image,g.introduction';
|
||||
|
||||
$join = [
|
||||
[ 'goods g', 'mgc.goods_id = g.goods_id', 'inner' ],
|
||||
];
|
||||
|
||||
$model = new MemberCardModel();
|
||||
$list = $model->getCardPageList($condition, $field, 'mgc.create_time desc', $page, $page_size, $alias, $join);
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用记录
|
||||
*/
|
||||
public function records()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$card_id = $this->params['card_id'] ?? 0;
|
||||
$item_id = $this->params['item_id'] ?? 0;
|
||||
if (empty($card_id) && empty($item_id)) {
|
||||
return $this->response($this->error([], '请传入必要参数'));
|
||||
}
|
||||
|
||||
$condition = [];
|
||||
$condition[] = [ 'cr.site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'ci.member_id', '=', $this->member_id ];
|
||||
if (!empty($item_id)) {
|
||||
$condition[] = [ 'cr.card_item_id', '=', $item_id ];
|
||||
}
|
||||
if (!empty($card_id)) {
|
||||
$condition[] = [ 'cr.card_id', '=', $card_id ];
|
||||
}
|
||||
$alias = 'cr';
|
||||
$prefix = config('database.connections.mysql.prefix');
|
||||
$field = 'cr.*, sku.sku_name,sku.sku_image,sku.sku_images,sku.price,ci.num as item_num,
|
||||
IF(cr.type = \'order\', (select order_id from `' . $prefix . 'order_goods` og where og.order_goods_id = cr.relation_id), 0) as order_id';
|
||||
|
||||
$join = [
|
||||
[ 'member_goods_card_item ci', 'ci.item_id = cr.card_item_id', 'left' ],
|
||||
[ 'goods_sku sku', 'ci.sku_id = sku.sku_id', 'left' ],
|
||||
];
|
||||
|
||||
$model = new MemberCardModel();
|
||||
$list = $model->getMemberCardRecordsList($condition, $field, 'cr.create_time desc', $alias, $join);
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
}
|
||||
76
addon/cardservice/api/controller/Ordercreate.php
Executable file
76
addon/cardservice/api/controller/Ordercreate.php
Executable file
@@ -0,0 +1,76 @@
|
||||
<?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\cardservice\api\controller;
|
||||
|
||||
use addon\cardservice\model\order\MembercardOrderCreate as OrderCreateModel;
|
||||
use app\api\controller\BaseOrderCreateApi;
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
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'] ?? '',
|
||||
];
|
||||
$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'] ?? '',//订单缓存
|
||||
];
|
||||
$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 = [
|
||||
'member_card_id' => $this->params[ 'member_card_id' ] ?? 0,//卡项id
|
||||
'member_card_item' => json_decode($this->params[ 'member_card_item' ] ?? '[]', true),//商品组id
|
||||
];
|
||||
if (empty($data[ 'member_card_id' ]) || empty($data[ 'member_card_item' ])) return $this->response($this->error('', '缺少必填参数商品数据'));
|
||||
|
||||
$res = $order_create->setParam(array_merge($data, $this->getCommonParam(), $this->getDeliveryParam()))->orderPayment();
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
}
|
||||
306
addon/cardservice/api/controller/Reserve.php
Executable file
306
addon/cardservice/api/controller/Reserve.php
Executable file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
|
||||
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\cardservice\api\controller;
|
||||
|
||||
use addon\cardservice\model\Reserve as ReserveModel;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\model\system\UserGroup;
|
||||
|
||||
|
||||
class Reserve extends BaseApi
|
||||
{
|
||||
/**
|
||||
* 预约状态
|
||||
* @return false|string
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
$reserve_state = ( new ReserveModel )->reserve_state;
|
||||
return $this->response($this->success($reserve_state));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加预约
|
||||
* @return mixed
|
||||
*/
|
||||
public function addReserve()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) {
|
||||
return $this->response($token);
|
||||
}
|
||||
$goods = json_decode($this->params[ 'goods' ], true) ?? [];
|
||||
$store_id = $this->params[ 'store_id' ] ?? 0;
|
||||
$date = $this->params[ 'date' ] ?? '';
|
||||
$time = $this->params[ 'time' ] ?? '';
|
||||
$remark = $this->params[ 'remark' ] ?? '';
|
||||
|
||||
$reserve_model = new ReserveModel();
|
||||
|
||||
$res = $reserve_model->addReserve([
|
||||
'site_id' => $this->site_id,
|
||||
'app_module' => $this->app_module,
|
||||
'member_id' => $this->member_id,
|
||||
'goods' => $goods,
|
||||
'store_id' => $store_id,
|
||||
'date' => $date,
|
||||
'time' => $time,
|
||||
'remark' => $remark,
|
||||
'source' => 'member'
|
||||
]);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改预约
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function updateReserve()
|
||||
{
|
||||
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) {
|
||||
return $this->response($token);
|
||||
}
|
||||
$goods = json_decode($this->params[ 'goods' ], true) ?? [];
|
||||
$store_id = $this->params[ 'store_id' ] ?? 0;
|
||||
$date = $this->params[ 'date' ] ?? '';
|
||||
$time = $this->params[ 'time' ] ?? '';
|
||||
$remark = $this->params[ 'remark' ] ?? '';
|
||||
$reserve_id = $this->params[ 'reserve_id' ] ?? 0;
|
||||
|
||||
$reserve_model = new ReserveModel();
|
||||
|
||||
$res = $reserve_model->editReserve([
|
||||
'site_id' => $this->site_id,
|
||||
'app_module' => $this->app_module,
|
||||
'member_id' => $this->member_id,
|
||||
'goods' => $goods,
|
||||
'store_id' => $store_id,
|
||||
'date' => $date,
|
||||
'time' => $time,
|
||||
'remark' => $remark,
|
||||
'reserve_id' => $reserve_id,
|
||||
]);
|
||||
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$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;
|
||||
$search_text = $this->params['search_text'] ?? '';
|
||||
$reserve_state = $this->params['reserve_state'] ?? 'all';
|
||||
|
||||
$condition = [
|
||||
[ 'noy.site_id', '=', $this->site_id ],
|
||||
[ 'noy.member_id', '=', $this->member_id ],
|
||||
];
|
||||
if ($reserve_state != 'all') {
|
||||
$condition[] = [ 'noy.reserve_state', '=', $reserve_state ];
|
||||
}
|
||||
if (!empty($search_text)) {
|
||||
$condition[] = [ 'noy.reserve_item', 'like', '%' . $search_text . '%' ];
|
||||
}
|
||||
|
||||
$field = 'noy.store_id, noy.member_id, noy.remark, noy.reserve_id, noy.reserve_name, noy.reserve_state_name, noy.reserve_state, noy.reserve_time, noy.reserve_item, noy.create_time, noy.source, nm.headimg, nm.nickname, nm.mobile, os.store_name';
|
||||
$reserve_model = new ReserveModel();
|
||||
$list = $reserve_model->getReservePageList($condition, $page, $page_size, 'noy.create_time desc', $field);
|
||||
foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
|
||||
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'item' ] = $reserve_model->getReserveItemList([
|
||||
[
|
||||
'oyi.reserve_id', '=', $v[ 'reserve_id' ]
|
||||
]
|
||||
], 'g.goods_name,sku.service_length,g.goods_id,g.sku_id,g.price,ys.username,oyi.reserve_user_id,sku.sku_image,sku.sku_images', 'reserve_item_id desc', 'oyi',
|
||||
[
|
||||
[ 'goods g', 'g.sku_id = oyi.reserve_goods_sku_id', 'right' ],
|
||||
[ 'goods_sku sku', 'sku.sku_id = oyi.reserve_goods_sku_id', 'right' ],
|
||||
[ 'user ys', 'oyi.reserve_user_id = ys.uid', 'left' ]
|
||||
])[ 'data' ];
|
||||
}
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约设置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$model = new ReserveModel();
|
||||
$store_id = $this->params['store_id'] ?? 0;
|
||||
$config = $model->getReserveConfig($this->site_id, $store_id);
|
||||
return $this->response($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
* @return array
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) {
|
||||
return $this->response($token);
|
||||
}
|
||||
$reserve_id = $this->params[ 'reserve_id' ] ?? 0;
|
||||
$reserve_model = new ReserveModel();
|
||||
$res = $reserve_model->cancelReserve($reserve_id, $this->site_id, $this->member_id);
|
||||
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除预约
|
||||
* @return array
|
||||
*/
|
||||
public function deleteReserve()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) {
|
||||
return $this->response($token);
|
||||
}
|
||||
$reserve_id = $this->params[ 'reserve_id' ] ?? 0;
|
||||
$reserve_model = new ReserveModel();
|
||||
$res = $reserve_model->deleteReserve($reserve_id, $this->site_id, $this->member_id);
|
||||
return $this->response($res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约详情
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) {
|
||||
return $this->response($token);
|
||||
}
|
||||
$reserve_id = $this->params[ 'reserve_id' ] ?? 0;
|
||||
|
||||
$model = new ReserveModel();
|
||||
|
||||
$info = $model->getReserveInfo([
|
||||
[ 'oy.reserve_id', '=', $reserve_id ],
|
||||
[ 'oy.site_id', '=', $this->site_id ],
|
||||
[ 'oy.member_id', '=', $this->member_id ],
|
||||
], 'oy.*, nm.headimg, nm.nickname, nm.mobile,os.store_name, os.longitude,os.latitude,os.province_id,os.city_id,os.district_id,os.community_id,os.address,os.full_address', 'oy', [
|
||||
[ 'member nm', 'oy.member_id = nm.member_id', 'left' ],
|
||||
[ 'store os', 'oy.store_id = os.store_id', 'left' ]
|
||||
])[ 'data' ];
|
||||
|
||||
if (empty($info)) {
|
||||
return $this->response($this->error('', '未获取到预约信息'));
|
||||
}
|
||||
|
||||
$info[ 'item' ] = $model->getReserveItemList([
|
||||
[
|
||||
'oyi.reserve_id', '=', $reserve_id
|
||||
]
|
||||
], 'g.goods_name,sku.service_length,g.goods_id,g.sku_id,g.price,ys.username,oyi.reserve_user_id,sku.sku_image', 'reserve_item_id desc', 'oyi',
|
||||
[
|
||||
[ 'goods g', 'g.sku_id = oyi.reserve_goods_sku_id', 'right' ],
|
||||
[ 'goods_sku sku', 'sku.sku_id = oyi.reserve_goods_sku_id', 'right' ],
|
||||
[ ' user ys', 'oyi.reserve_user_id = ys.uid', 'left' ]
|
||||
])[ 'data' ];
|
||||
|
||||
return $this->response($this->success($info));
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工管理
|
||||
* @return mixed
|
||||
*/
|
||||
public function servicer()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
$page_index = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
$search_text = $this->params['search_text'] ?? '';
|
||||
$store_id = $this->params['store_id'] ?? '';
|
||||
$condition = [
|
||||
[ 'u.site_id', '=', $this->site_id ],
|
||||
];
|
||||
$condition[] = [ 'ug.store_id', '=', $store_id ];
|
||||
|
||||
if (!empty($search_text)) {
|
||||
$condition[] = [ 'u.username', 'like', "%{$search_text}%" ];
|
||||
}
|
||||
|
||||
$user_model = new UserGroup();
|
||||
$result = $user_model->getUserPageList($condition, $page_index, $page_size, 'u.uid desc', 'u.username,u.status,u.uid', 'ug', [
|
||||
[ 'user u', 'ug.uid=u.uid', 'left' ]
|
||||
]);
|
||||
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有员工
|
||||
* @return mixed
|
||||
*/
|
||||
public function servicerList()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
$search_text = $this->params['search_text'] ?? '';
|
||||
$store_id = $this->params['store_id'] ?? '';
|
||||
$condition = [
|
||||
[ 'u.site_id', '=', $this->site_id ],
|
||||
];
|
||||
$condition[] = [ 'ug.store_id', '=', $store_id ];
|
||||
|
||||
if (!empty($search_text)) {
|
||||
$condition[] = [ 'u.username', 'like', "%{$search_text}%" ];
|
||||
}
|
||||
|
||||
$user_model = new UserGroup();
|
||||
$result = $user_model->getUserList($condition, 'u.username,u.status,u.uid,u.group_name', 'u.uid desc', 'ug', [
|
||||
[ 'user u', 'ug.uid=u.uid', 'left' ]
|
||||
]);
|
||||
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约时间设置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTimeConfig()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
$model = new ReserveModel();
|
||||
$store_id = $this->params['store_id'] ?? '';
|
||||
$config = $model->getReserveConfig($this->site_id, $store_id);
|
||||
$time = strtotime(date('Y-m-d'));
|
||||
if ($config[ 'data' ][ 'value' ][ 'interval' ] == 30) $config[ 'data' ][ 'value' ][ 'interval' ] = "0.5";
|
||||
if ($config[ 'data' ][ 'value' ][ 'interval' ] == 60) $config[ 'data' ][ 'value' ][ 'interval' ] = "1";
|
||||
if ($config[ 'data' ][ 'value' ][ 'interval' ] == 90) $config[ 'data' ][ 'value' ][ 'interval' ] = "1.5";
|
||||
if ($config[ 'data' ][ 'value' ][ 'interval' ] == 120) $config[ 'data' ][ 'value' ][ 'interval' ] = "2";
|
||||
$config[ 'data' ][ 'value' ][ 'start_time' ] = time_to_date($time + $config[ 'data' ][ 'value' ][ 'start' ], "H:i");
|
||||
$config[ 'data' ][ 'value' ][ 'end_time' ] = time_to_date($time + $config[ 'data' ][ 'value' ][ 'end' ], "H:i");
|
||||
return $this->response($config);
|
||||
}
|
||||
}
|
||||
172
addon/cardservice/api/controller/Service.php
Executable file
172
addon/cardservice/api/controller/Service.php
Executable file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\cardservice\api\controller;
|
||||
|
||||
use app\api\controller\BaseApi;
|
||||
use app\model\goods\Goods;
|
||||
use app\model\goods\GoodsService;
|
||||
use app\model\web\Config as ConfigModel;
|
||||
use addon\cardservice\model\ServiceGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 服务
|
||||
*/
|
||||
class Service extends BaseApi
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->initStoreData();
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
$sku_id = $this->params['sku_id'] ?? 0;
|
||||
$goods_id = $this->params['goods_id'] ?? 0;
|
||||
$goods = new Goods();
|
||||
if (empty($sku_id) && !empty($goods_id)) {
|
||||
$sku_id = $goods->getGoodsInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id')[ 'data' ][ 'sku_id' ] ?? 0;
|
||||
}
|
||||
if (empty($sku_id) && empty($goods_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
|
||||
$condition = [
|
||||
[ 'gs.sku_id', '=', $sku_id ],
|
||||
[ 'gs.site_id', '=', $this->site_id ]
|
||||
];
|
||||
$field = 'gs.goods_id,gs.sku_id,gs.qr_id,gs.goods_name,gs.sku_name,gs.sku_spec_format,gs.price,gs.market_price,gs.discount_price,gs.promotion_type,gs.start_time
|
||||
,gs.end_time,gs.stock,gs.click_num,(g.sale_num + g.virtual_sale) as sale_num,gs.collect_num,gs.sku_image,gs.sku_images
|
||||
,gs.goods_content,gs.goods_state,gs.is_free_shipping,gs.goods_spec_format,gs.goods_attr_format,gs.introduction,gs.unit,gs.video_url
|
||||
,gs.is_virtual,gs.goods_service_ids,gs.max_buy,gs.min_buy,gs.is_limit,gs.limit_type,gs.support_trade_type,g.goods_image,g.keywords,g.stock_show,g.sale_show,g.market_price_show,g.barrage_show,g.evaluate,g.goods_class,g.sale_store,g.sale_channel';
|
||||
$join = [
|
||||
[ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
|
||||
];
|
||||
|
||||
// 如果是连锁运营模式
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
$join[] = [ 'store_goods_sku sgs', 'gs.sku_id = sgs.sku_id and sgs.store_id=' . $this->store_id, 'left' ];
|
||||
|
||||
$field .= ',IFNULL(sgs.status, 0) as store_goods_status';
|
||||
|
||||
$field = str_replace('gs.price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as price', $field);
|
||||
$field = str_replace('gs.discount_price', 'IFNULL(IF(g.is_unify_price = 1,gs.discount_price,sgs.price), gs.discount_price) as discount_price', $field);
|
||||
if ($this->store_data[ 'store_info' ][ 'stock_type' ] == 'store') {
|
||||
$field = str_replace('gs.stock', 'IFNULL(sgs.stock, 0) as stock', $field);
|
||||
}
|
||||
}
|
||||
$goods_sku_detail = $goods->getGoodsSkuInfo($condition, $field, 'gs', $join)[ 'data' ];
|
||||
|
||||
if (empty($goods_sku_detail) || $goods_sku_detail[ 'goods_class' ] != ( new ServiceGoods() )->getGoodsClass()[ 'id' ]) return $this->response($this->error());
|
||||
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
// 销售渠道设置为线上销售时门店商品状态为1
|
||||
if ($goods_sku_detail[ 'sale_channel' ] == 'online') {
|
||||
$goods_sku_detail[ 'store_goods_status' ] = 1;
|
||||
}
|
||||
}
|
||||
$goods_sku_detail[ 'purchased_num' ] = 0; // 该商品已购数量
|
||||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||||
|
||||
// 商品服务
|
||||
$goods_service = new GoodsService();
|
||||
$goods_service_list = $goods_service->getServiceList([ [ 'site_id', '=', $this->site_id ], [ 'id', 'in', $res[ 'goods_sku_detail' ][ 'goods_service_ids' ] ] ], 'service_name,desc,icon');
|
||||
$res[ 'goods_sku_detail' ][ 'goods_service' ] = $goods_service_list[ 'data' ];
|
||||
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表信息
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
$goods_id_arr = $this->params['goods_id_arr'] ?? '';//goods_id数组
|
||||
$keyword = isset($this->params[ 'keyword' ]) ? trim($this->params[ 'keyword' ]) : '';//关键词
|
||||
$service_category = $this->params['service_category'] ?? 0;//分类
|
||||
$is_free_shipping = $this->params['is_free_shipping'] ?? 0;//是否免邮
|
||||
$order = $this->params['order'] ?? "";//排序(综合、销量、价格)
|
||||
$sort = $this->params['sort'] ?? "";//升序、降序
|
||||
|
||||
$condition = [];
|
||||
$condition[] = [ 'gs.site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'g.goods_class', '=', ( new ServiceGoods() )->getGoodsClass()[ 'id' ] ];
|
||||
$condition[] = [ '', 'exp', Db::raw("(g.sale_channel = 'all' OR g.sale_channel = 'online')") ];
|
||||
|
||||
if (!empty($goods_id_arr)) {
|
||||
$condition[] = [ 'gs.goods_id', 'in', $goods_id_arr ];
|
||||
}
|
||||
if (!empty($service_category)) {
|
||||
$condition[] = [ 'g.service_category', 'like', '%,' . $service_category . ',%' ];
|
||||
}
|
||||
|
||||
if (!empty($keyword)) {
|
||||
$condition[] = [ 'g.goods_name|gs.sku_name|gs.keywords', 'like', '%' . $keyword . '%' ];
|
||||
}
|
||||
|
||||
if (!empty($is_free_shipping)) {
|
||||
$condition[] = [ 'gs.is_free_shipping', '=', $is_free_shipping ];
|
||||
}
|
||||
|
||||
// 非法参数进行过滤
|
||||
if ($sort != "desc" && $sort != "asc") {
|
||||
$sort = "";
|
||||
}
|
||||
|
||||
// 非法参数进行过滤
|
||||
if ($order != '') {
|
||||
if ($order != "sale_num" && $order != "discount_price") {
|
||||
$order = 'gs.sort';
|
||||
} elseif ($order == "sale_num") {
|
||||
$order = 'sale_sort';
|
||||
} else {
|
||||
$order = 'gs.' . $order;
|
||||
}
|
||||
$order_by = $order . ' ' . $sort;
|
||||
} else {
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
|
||||
|
||||
$order_by = 'g.sort ' . $sort_config[ 'type' ] . ',g.create_time desc';
|
||||
}
|
||||
|
||||
$condition[] = [ 'g.goods_state', '=', 1 ];
|
||||
$condition[] = [ 'g.is_delete', '=', 0 ];
|
||||
$alias = 'gs';
|
||||
|
||||
$field = 'gs.is_consume_discount,gs.discount_config,gs.discount_method,gs.member_price,gs.goods_id,gs.sort,gs.sku_id,gs.sku_name,gs.price,gs.market_price,gs.discount_price,gs.stock,(g.sale_num + g.virtual_sale) as sale_num,(gs.sale_num + gs.virtual_sale) as sale_sort,gs.sku_image,gs.goods_name,gs.site_id,gs.is_free_shipping,gs.introduction,gs.promotion_type,g.goods_image,g.promotion_addon,gs.is_virtual,g.goods_spec_format,g.recommend_way,gs.max_buy,gs.min_buy,gs.unit,gs.is_limit,gs.limit_type,g.label_name,g.stock_show,g.sale_show,g.market_price_show,g.barrage_show,g.sale_channel,g.sale_store';
|
||||
$join = [
|
||||
[ 'goods g', 'gs.sku_id = g.sku_id', 'inner' ]
|
||||
];
|
||||
|
||||
// 如果是连锁运营模式
|
||||
if ($this->store_data[ 'config' ][ 'store_business' ] == 'store') {
|
||||
$join[] = [ 'store_goods_sku sgs', 'sgs.status = 1 and g.sku_id = sgs.sku_id and sgs.store_id=' . $this->store_id, 'right' ];
|
||||
|
||||
$condition[] = [ 'g.sale_store', 'like', [ '%all%', '%,' . $this->store_id . ',%' ], 'or' ];
|
||||
|
||||
$field = str_replace('gs.price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as price', $field);
|
||||
$field = str_replace('gs.discount_price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as discount_price', $field);
|
||||
if ($this->store_data[ 'store_info' ][ 'stock_type' ] == 'store') {
|
||||
$field = str_replace('gs.stock', 'IFNULL(sgs.stock, 0) as stock', $field);
|
||||
}
|
||||
}
|
||||
|
||||
$goods = new Goods();
|
||||
$list = $goods->getGoodsSkuPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
|
||||
|
||||
return $this->response($list);
|
||||
}
|
||||
}
|
||||
24
addon/cardservice/api/controller/Servicescategory.php
Executable file
24
addon/cardservice/api/controller/Servicescategory.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace addon\cardservice\api\controller;
|
||||
|
||||
use app\model\goods\ServiceCategory as ServiceCategoryModel;
|
||||
use app\api\controller\BaseApi;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
class Servicescategory extends BaseApi
|
||||
{
|
||||
|
||||
public function lists()
|
||||
{
|
||||
$goods_category_model = new ServiceCategoryModel();
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'is_show', '=', 0 ],//是否显示(0显示 -1不显示)
|
||||
];
|
||||
$data = $goods_category_model->getCategoryList($condition);
|
||||
return $this->response($data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user