admin/addon/groupbuy/api/controller/Goods.php

179 lines
6.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 成都云之牛科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.cdcloudshop.com
* =========================================================
*/
namespace addon\groupbuy\api\controller;
use addon\groupbuy\model\Groupbuy as GroupbuyModel;
use app\api\controller\BaseApi;
use addon\groupbuy\model\Poster;
use app\model\goods\GoodsService;
use app\model\web\Config as ConfigModel;
/**
* 团购商品
*/
class Goods extends BaseApi
{
/**
* 【废弃】基础信息
*/
public function info()
{
$groupbuy_id = isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : 0;
$sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
if (empty($groupbuy_id)) {
return $this->response($this->error('', 'REQUEST_GROUPBUY_ID'));
}
if (empty($sku_id)) {
return $this->response($this->error('', 'REQUEST_SKU_ID'));
}
$groupbuy_model = new GroupbuyModel();
$condition = [
[ 'sku.sku_id', '=', $sku_id ],
[ 'pg.groupbuy_id', '=', $groupbuy_id ],
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ]
];
$info = $groupbuy_model->getGroupbuyGoodsDetail($condition);
return $this->response($info);
}
/**
* 团购商品详情信息
*/
public function detail()
{
$groupbuy_id = isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : 0;
if (empty($groupbuy_id)) {
return $this->response($this->error('', 'REQUEST_GROUPBUY_ID'));
}
$groupbuy_model = new GroupbuyModel();
$condition = [
[ 'pg.groupbuy_id', '=', $groupbuy_id ],
[ 'pg.site_id', '=', $this->site_id ],
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ]
];
$goods_sku_detail = $groupbuy_model->getGroupbuyGoodsDetail($condition)[ 'data' ];
if (empty($goods_sku_detail)) return $this->response($this->error());
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
$goods = new \app\model\goods\Goods();
if (!empty($res[ 'goods_sku_detail' ][ 'sku_images' ])) $res[ 'goods_sku_detail' ][ 'sku_images_list' ] = $goods->getGoodsImage($res[ 'goods_sku_detail' ][ 'sku_images' ], $this->site_id)[ 'data' ] ?? [];
if (!empty($res[ 'goods_sku_detail' ][ 'sku_image' ])) $res[ 'goods_sku_detail' ][ 'sku_image_list' ] = $goods->getGoodsImage($res[ 'goods_sku_detail' ][ 'sku_image' ], $this->site_id)[ 'data' ] ?? [];
if (!empty($res[ 'goods_sku_detail' ][ 'goods_image' ])) $res[ 'goods_sku_detail' ][ 'goods_image_list' ] = $goods->getGoodsImage($res[ 'goods_sku_detail' ][ 'goods_image' ], $this->site_id)[ 'data' ] ?? [];
// 商品服务
$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' ];
// 商品详情配置
$config_model = new ConfigModel();
$res[ 'goods_sku_detail' ][ 'config' ] = $config_model->getGoodsDetailConfig($this->site_id)[ 'data' ][ 'value' ];
return $this->response($this->success($res));
}
/**
* 查询商品SKU集合
* @return false|string
*/
public function goodsSku()
{
$goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
$groupbuy_id = isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : 0;
if (empty($goods_id)) {
return $this->response($this->error('', 'REQUEST_ID'));
}
if (empty($groupbuy_id)) {
return $this->response($this->error('', 'REQUEST_GROUPBUY_ID'));
}
$groupbuy_model = new GroupbuyModel();
$condition = [
[ 'pg.groupbuy_id', '=', $groupbuy_id ],
[ 'pg.site_id', '=', $this->site_id ],
[ 'g.goods_id', '=', $goods_id ],
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ]
];
$list = $groupbuy_model->getGroupbuyGoodsSkuList($condition, null);
return $this->response($list);
}
public function page()
{
$page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
$page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
$goods_id_arr = isset($this->params[ 'goods_id_arr' ]) ? $this->params[ 'goods_id_arr' ] : '';//goods_id数组
$condition = [
[ 'pg.status', '=', 2 ],// 状态1未开始 2进行中 3已结束
[ 'g.goods_stock', '>', 0 ],
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ],
[ 'sku.site_id', '=', $this->site_id ]
];
if (!empty($goods_id_arr)) {
$condition[] = [ 'sku.goods_id', 'in', $goods_id_arr ];
}
$groupbuy_model = new GroupbuyModel();
$list = $groupbuy_model->getGroupbuyGoodsPageList($condition, $page, $page_size, 'pg.groupbuy_id desc', '');
return $this->response($list);
}
public function lists()
{
$num = isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 0;
$condition = [
[ 'pg.status', '=', 2 ],// 状态1未开始 2进行中 3已结束
[ 'g.goods_stock', '>', 0 ],
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ],
[ 'sku.site_id', '=', $this->site_id ]
];
if (!empty($goods_id_arr)) {
$condition[] = [ 'sku.goods_id', 'in', $goods_id_arr ];
}
$groupbuy_model = new GroupbuyModel();
$list = $groupbuy_model->getGroupbuyGoodsList($condition, '', 'pg.groupbuy_id desc', $num);
return $this->response($list);
}
/**
* 获取商品海报
*/
public function poster()
{
$this->checkToken();
$promotion_type = 'groupbuy';
$qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
$qrcode_param[ 'source_member' ] = $this->member_id;
$qrcode_param[ 'id' ] = $qrcode_param[ 'groupbuy_id' ] ?? 0;
unset($qrcode_param[ 'groupbuy_id' ]);
$poster = new Poster();
$res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
return $this->response($res);
}
}