221 lines
8.5 KiB
PHP
221 lines
8.5 KiB
PHP
<?php
|
||
/**
|
||
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
|
||
* =========================================================
|
||
* Copy right 2019-2029 成都云之牛科技有限公司, 保留所有权利。
|
||
* ----------------------------------------------
|
||
* 官方网址: https://www.cdcloudshop.com
|
||
* =========================================================
|
||
*/
|
||
|
||
namespace addon\presale\api\controller;
|
||
|
||
use addon\presale\model\Presale as PresaleModel;
|
||
use addon\presale\model\PresaleOrderCommon;
|
||
use addon\presale\model\PresaleOrderRefund;
|
||
use app\api\controller\BaseApi;
|
||
use addon\presale\model\Poster;
|
||
use app\model\goods\GoodsService;
|
||
use app\model\web\Config as ConfigModel;
|
||
|
||
/**
|
||
* 预售商品
|
||
*/
|
||
class Goods extends BaseApi
|
||
{
|
||
|
||
/**
|
||
* 【废弃】基础信息
|
||
*/
|
||
public function info()
|
||
{
|
||
$presale_id = isset($this->params[ 'id' ]) ? $this->params[ 'id' ] : 0;
|
||
$sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
|
||
if (empty($presale_id)) {
|
||
return $this->response($this->error('', 'REQUEST_PRESALE_ID'));
|
||
}
|
||
if (empty($sku_id)) {
|
||
return $this->response($this->error('', 'REQUEST_SKU_ID'));
|
||
}
|
||
|
||
$presale_model = new PresaleModel();
|
||
$condition = [
|
||
[ 'sku.sku_id', '=', $sku_id ],
|
||
[ 'pp.presale_id', '=', $presale_id ],
|
||
[ 'pp.status', '=', 1 ],
|
||
[ 'g.goods_state', '=', 1 ],
|
||
[ 'g.is_delete', '=', 0 ]
|
||
];
|
||
$info = $presale_model->getPresaleGoodsDetail($condition, '');
|
||
if (empty($info[ 'data' ])) {
|
||
return $this->response($this->error());
|
||
}
|
||
|
||
$info[ 'data' ][ 'purchased_num' ] = 0;
|
||
$token = $this->checkToken();
|
||
if ($token[ 'code' ] >= 0) {
|
||
$info[ 'data' ][ 'purchased_num' ] = $presale_model->getGoodsPurchasedNum($info[ 'data' ][ 'presale_id' ], $this->member_id);
|
||
}
|
||
|
||
// 预约人数
|
||
$info[ 'data' ][ 'sale_num' ] = $presale_model->getPresaleOrderCount([
|
||
[ 'presale_id', '=', $info[ 'data' ][ 'presale_id' ] ],
|
||
[ 'order_status', '<>', PresaleOrderCommon::ORDER_CLOSE ]
|
||
])[ 'data' ];
|
||
|
||
return $this->response($info);
|
||
}
|
||
|
||
/**
|
||
* 预售商品详情信息
|
||
*/
|
||
public function detail()
|
||
{
|
||
$presale_id = isset($this->params[ 'id' ]) ? $this->params[ 'id' ] : 0;
|
||
if (empty($presale_id)) {
|
||
return $this->response($this->error('', 'REQUEST_PRESALE_ID'));
|
||
}
|
||
$sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
|
||
|
||
$presale_model = new PresaleModel();
|
||
$condition = [
|
||
[ 'pp.presale_id', '=', $presale_id ],
|
||
[ 'pp.site_id', '=', $this->site_id ],
|
||
[ 'pp.status', '=', 1 ],
|
||
[ 'g.goods_state', '=', 1 ],
|
||
[ 'g.is_delete', '=', 0 ]
|
||
];
|
||
if ($sku_id > 0) {
|
||
$condition[] = [ 'ppg.sku_id', '=', $sku_id ];
|
||
}
|
||
$goods_sku_detail = $presale_model->getPresaleGoodsDetail($condition, '')[ 'data' ];
|
||
if (empty($goods_sku_detail)) {
|
||
return $this->response($this->error());
|
||
}
|
||
|
||
$res = [];
|
||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||
$res[ 'goods_sku_detail' ][ 'purchased_num' ] = 0;
|
||
|
||
$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' ] ?? [];
|
||
|
||
$token = $this->checkToken();
|
||
if ($token[ 'code' ] >= 0) {
|
||
$res[ 'goods_sku_detail' ][ 'purchased_num' ] = $presale_model->getGoodsPurchasedNum($goods_sku_detail[ 'presale_id' ], $this->member_id);
|
||
$res[ 'goods_sku_detail' ][ 'buying_num' ] = $presale_model->getPresaleOrderCount([
|
||
[ 'member_id', '=', $this->member_id ],
|
||
[ 'presale_id', '=', $goods_sku_detail[ 'presale_id' ] ],
|
||
[ 'order_status', 'not in', [ PresaleOrderCommon::ORDER_CLOSE, PresaleOrderCommon::ORDER_PAY ] ],
|
||
[ 'refund_status', '<>', PresaleOrderRefund::REFUND_COMPLETE ]
|
||
])[ 'data' ];
|
||
}
|
||
// 预约人数
|
||
$res[ 'goods_sku_detail' ][ 'sale_num' ] = $presale_model->getPresaleOrderCount([
|
||
[ 'presale_id', '=', $goods_sku_detail[ 'presale_id' ] ],
|
||
[ 'order_status', '<>', PresaleOrderCommon::ORDER_CLOSE ]
|
||
])[ '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;
|
||
$presale_id = isset($this->params[ 'presale_id' ]) ? $this->params[ 'presale_id' ] : 0;
|
||
if (empty($presale_id)) {
|
||
return $this->response($this->error('', 'REQUEST_PRESALE_ID'));
|
||
}
|
||
if (empty($goods_id)) {
|
||
return $this->response($this->error('', 'REQUEST_ID'));
|
||
}
|
||
|
||
$presale_model = new PresaleModel();
|
||
|
||
$condition = [
|
||
[ 'pp.presale_id', '=', $presale_id ],
|
||
[ 'g.goods_id', '=', $goods_id ],
|
||
[ 'pp.status', '=', 1 ],
|
||
[ 'pp.site_id', '=', $this->site_id ],
|
||
[ 'g.goods_state', '=', 1 ],
|
||
[ 'g.is_delete', '=', 0 ],
|
||
];
|
||
$list = $presale_model->getPresaleGoodsSkuList($condition);
|
||
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 = [
|
||
[ 'pp.status', '=', 1 ],// 状态(0未开始 1进行中 2已结束)
|
||
[ 'g.goods_state', '=', 1 ],
|
||
[ 'g.is_delete', '=', 0 ],
|
||
[ 'g.site_id', '=', $this->site_id ]
|
||
];
|
||
|
||
if (!empty($goods_id_arr)) {
|
||
$condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
|
||
}
|
||
|
||
$presale_model = new PresaleModel();
|
||
$list = $presale_model->getPresaleGoodsPageList($condition, $page, $page_size, 'pp.presale_id desc', '');
|
||
|
||
return $this->response($list);
|
||
}
|
||
|
||
|
||
public function lists()
|
||
{
|
||
$num = isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 0;
|
||
|
||
$condition = [
|
||
[ 'pp.status', '=', 1 ],// 状态(0未开始 1进行中 2已结束)
|
||
[ 'g.goods_state', '=', 1 ],
|
||
[ 'g.is_delete', '=', 0 ],
|
||
[ 'g.site_id', '=', $this->site_id ]
|
||
];
|
||
|
||
if (!empty($goods_id_arr)) {
|
||
$condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
|
||
}
|
||
|
||
$presale_model = new PresaleModel();
|
||
$list = $presale_model->getPresaleList($condition,'', 'pp.presale_id desc', $num);
|
||
|
||
return $this->response($list);
|
||
}
|
||
|
||
/**
|
||
* 获取商品海报
|
||
*/
|
||
public function poster()
|
||
{
|
||
$this->checkToken();
|
||
|
||
$promotion_type = 'presale';
|
||
$qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
|
||
$qrcode_param[ 'source_member' ] = $this->member_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);
|
||
}
|
||
} |