130 lines
2.9 KiB
PHP
130 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\live;
|
|
|
|
use app\common\controller\Api;
|
|
|
|
/**
|
|
* 直播带货
|
|
*/
|
|
class Goods extends Api
|
|
{
|
|
// 无需登录的接口,*表示全部
|
|
protected $noNeedLogin = [];
|
|
protected $noNeedRight = '*';
|
|
|
|
protected $model;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\live\Goods;
|
|
$this->actionModel = new \app\admin\model\live\GoodsAction;
|
|
}
|
|
|
|
/**
|
|
* 带货商品列表
|
|
* @return void
|
|
*/
|
|
public function index()
|
|
{
|
|
$liveId = input('live_id');
|
|
|
|
$list = $this->model
|
|
->where([
|
|
'live_id'=>$liveId
|
|
])
|
|
->normal()
|
|
->sort()
|
|
->order('explaining DESC, id ASC')
|
|
->select();
|
|
|
|
|
|
if($list){
|
|
foreach ($list as $index => &$row) {
|
|
$row->visible(['id','description','status','explaining','sellout','createtime','goods']);
|
|
|
|
$goods = $this->getGoods($row->goods_id,$row->goods_type);
|
|
|
|
if($goods){
|
|
$row->goods = $goods;
|
|
}else{
|
|
unset($list[$index]);
|
|
}
|
|
}
|
|
sort($list);
|
|
}
|
|
|
|
|
|
|
|
$this->success("获取成功",$list);
|
|
}
|
|
|
|
/**
|
|
* 获取讲解中的商品
|
|
* @return void
|
|
*/
|
|
public function explaining(){
|
|
$liveId = input('live_id');
|
|
|
|
$data = $this->model
|
|
->where([
|
|
'live_id'=>$liveId,
|
|
'explaining'=>1
|
|
])
|
|
->normal()
|
|
->field(['id','description','status','explaining','sellout','createtime','goods_id','goods_type'])
|
|
->find();
|
|
|
|
if(!$data){
|
|
$this->success("暂无讲解商品");
|
|
}
|
|
|
|
|
|
$goods = $this->getGoods($data['goods_id'],$data['goods_type']);
|
|
|
|
if(!$goods){
|
|
$this->success("暂无讲解商品");
|
|
}
|
|
$data['goods'] = $goods;
|
|
|
|
$this->success("获取成功",$data);
|
|
}
|
|
|
|
public function getGoods($goodsId,$goodsType){
|
|
$goods = \app\common\model\goods\Handle::getGoodsQuery()->where([
|
|
'id'=>$goodsId,
|
|
'type'=>$goodsType,
|
|
'status'=>1,
|
|
'hide'=>0,
|
|
'sales_type'=>['like','%alone%']
|
|
])->find();
|
|
|
|
return $goods;
|
|
}
|
|
|
|
|
|
/**
|
|
* 用户点击商品行为
|
|
* @return void
|
|
*/
|
|
public function action()
|
|
{
|
|
$liveId = input('live_id');
|
|
$goodsId = input('goods_id');
|
|
$goodsType = input('goods_type');
|
|
|
|
|
|
$actionId = $this->actionModel->insertGetId([
|
|
'uniacid'=>UNIACID,
|
|
'goods_id'=>$goodsId,
|
|
'user_id'=>$this->auth->id,
|
|
'live_id'=>$liveId,
|
|
'goods_type'=>$goodsType,
|
|
'createtime'=>time()
|
|
]);
|
|
|
|
|
|
$this->success("获取成功",$actionId);
|
|
}
|
|
} |