初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\goods;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
* 区别于课程列表,这里展示的是处理课程外的所有商品,如会员卡、活动
|
||||
*/
|
||||
class Goods extends Api
|
||||
{
|
||||
// 无需登录的接口,*表示全部
|
||||
protected $noNeedLogin = ['index'];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
|
||||
public function index(){
|
||||
|
||||
$limit = input('limit',5);
|
||||
$page = input('page',1);
|
||||
$searchKey = input('searchKey','');
|
||||
$sort = input('sort','time');
|
||||
$type = input('type','');
|
||||
|
||||
$sort = $sort == 'time' ? 'createtime' : 'views';
|
||||
|
||||
$where = [];
|
||||
$where['status'] = 1;
|
||||
$where['sales_type'] = ['like',"%alone%"];
|
||||
$where['hide'] = 0;
|
||||
|
||||
if($searchKey){
|
||||
$where['name'] = ['like',"%{$searchKey}%"];
|
||||
}
|
||||
if($type){
|
||||
$where['type'] = $type;
|
||||
}
|
||||
|
||||
$list = \app\common\model\goods\Handle::getGoodsQuery()
|
||||
->where($where)
|
||||
->limit($limit)
|
||||
->page($page)
|
||||
->order($sort,'desc')
|
||||
->select();
|
||||
|
||||
if($list){
|
||||
foreach ($list as &$item){
|
||||
$extendInfo = \app\common\model\goods\Handle::parseGoodsExtendInfo($item['id'],$item['type']);
|
||||
if($extendInfo){
|
||||
$item = array_merge($item,$extendInfo);
|
||||
}
|
||||
|
||||
$goodsType = $item['type'] ?? '';
|
||||
$isVirtualPay = \app\common\library\pay\VirtualPayService::isUseVirtualPay($goodsType);
|
||||
$item['is_virtual_pay'] = $isVirtualPay ? 1 : 0;
|
||||
if ($isVirtualPay) {
|
||||
$item = \app\common\library\pay\VirtualPayService::convertPriceFields($item, ['price', 'price_marking']);
|
||||
}
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
|
||||
|
||||
$this->success('获取成功', $list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user