<?php
|
|
namespace app\api\logic;
|
use app\common\logic\Basic as BasicLogic;
|
use app\common\model\user\Collect as ModelUserCollect;
|
use app\api\logic\taoke\Parser;
|
use app\api\logic\taoke\device\Jd as LogicJd;
|
|
class UserCollect extends BasicLogic
|
{
|
|
protected $model;
|
|
protected function initialize()
|
{
|
$this->model = new ModelUserCollect();
|
}
|
|
|
/**
|
* 获取收藏记录
|
*
|
* @param [type] $page
|
* @param [type] $pageSize
|
* @return void
|
*/
|
public function getList($page,$pageSize)
|
{
|
$list = $this->model
|
->field('id,goodsId,goods_sign,sourceType,faction,title as dtitle,mainPic,originalPrice,actualPrice,shopName,couponPrice,monthSales,create_time')
|
->where(['user_id'=>USERID])
|
->page($page,$pageSize)
|
->order('create_time desc')
|
->select();
|
if (empty($list)) return [];
|
$LogicJd = new LogicJd();
|
foreach($list as &$item){
|
$item['create_time_str'] = formatTime($item['create_time']);
|
$item['create_time'] = date("Y-m-d",$item['create_time']);
|
$item['labelImg'] = Parser::initSourse($item['sourceType']);
|
}
|
return $list;
|
}
|
|
|
/**
|
* 判断商品是否收藏
|
*/
|
public static function isCollect($goods)
|
{
|
if(USERID == "") return 0;
|
$field = $goods['sourceType'] == 'pdd' ? 'goods_sign' : 'goodsId';
|
$find = ModelUserCollect::field('id')->where(['user_id'=>USERID,$field=>$goods[$field]])->find();
|
return empty($find) ? 0 : 1;
|
|
}
|
|
|
/**
|
* 商品收藏
|
*
|
* @param [type] $user_id 用户id
|
* @param [type] $goods 商品信息
|
* @return void
|
*/
|
public function addCollect($user_id,$goods)
|
{
|
$save_data = [
|
'user_id' => $user_id,
|
'goodsId' => $goods['goodsId'],
|
'goods_sign' => isset($goods['goods_sign']) ? $goods['good_sign'] : '',
|
'sourceType' => $goods['sourceType'],
|
'faction' => $goods['faction'],
|
'title' => $goods['title'],
|
'mainPic' => $goods['mainPic'],
|
'originalPrice' => $goods['originalPrice'],
|
'actualPrice' => $goods['actualPrice'],
|
'shopName' => $goods['shopName'],
|
'couponPrice' => $goods['couponPrice'],
|
'monthSales' => $goods['monthSales'],
|
'create_time' => time()
|
];
|
|
$res = $this->model->save($save_data);
|
if(!$res) fault('收藏失败');
|
return true;
|
}
|
|
|
/**
|
* 商品收藏
|
*
|
* @param [type] $user_id 用户id
|
* @return void
|
*/
|
public function delCollect($user_id,$goodsId)
|
{
|
$goodsId = strpos($goodsId,',') ? explode(',',$goodsId) : [$goodsId];
|
$res = $this->model->where(['user_id'=>$user_id])->whereIn('goodsId',$goodsId)->delete();
|
if(!$res) fault('收藏失败');
|
return true;
|
}
|
|
|
/**
|
* 删除记录
|
*
|
* * @param [type] $user_id
|
* @param [type] $ids
|
* @return void
|
*/
|
public function deleteLog($user_id,$ids)
|
{
|
$ids = strpos($ids, ',') == false ? [$ids] : explode(',', $ids);
|
|
$res = $this->model->where(['user_id'=>$user_id])->whereIn('id',$ids)->update(['delete_time'=>time()]);
|
|
if(!$res) fault('删除失败');
|
|
return true;
|
|
}
|
|
|
|
|
}
|