You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.4 KiB

<?php
namespace app\mall\controller\api;
use app\mall\model\MallCollect;
class Collect extends Base
{
/**
* 商品收藏
* @date 2021-03-01
*/
public function collect()
{
$param = input('post.');
$collect_model = new MallCollect();
if (!$param['collect']) { //取消收藏
$res = $collect_model->dataDel([
['uid', '=', UID],
['product_id', '=', $param['product_id']],
['user_id', '=', USER_ID]
]);
if (!$res) {
return sendErrorMessage(4001, '取消收藏失败');
}
$msg = '取消收藏成功';
$collect = false;
} else { //收藏
$data = [
'uid' => UID,
'user_id' => USER_ID,
'user_agent' => USER_AGENT,
'product_id' => $param['product_id']
];
$res = $collect_model->dataUpdate($data);
if (!$res) {
return sendErrorMessage(4002, '收藏失败');
}
$msg = '收藏成功';
$collect = true;
}
return sendSuccessMessage([
'collect' => $collect
], $msg);
}
/**
* 我的收藏
* @date 2022-12-01
*/
public function listMyCollect()
{
$param = input('post.');
$collect_logic = new \app\mall\logic\Collect();
$result = $collect_logic -> listMyCollect($param['keyword']);
return json($result);
}
/**
* 删除我的收藏
* @date 2021-03-01
*/
public function deleteMyCollect()
{
$param = input('post.');
$collect_logic = new \app\mall\logic\Collect();
$collect_ids = explode(',', $param['collect_ids']);
$result = $collect_logic -> deleteMyCollect($collect_ids);
return json($result);
}
/**
* 商品是否收藏
* @date 2021-03-01
*/
public function hasCollect()
{
$param = input('post.');
$collect_model = new MallCollect();
//判断是否收藏
$collect_id = $collect_model->getOneData([
['uid', '=', UID],
['product_id', '=', $param['product_id']],
['user_id', '=', USER_ID]
], 'id');
$collect = $collect_id ? true : false;
return sendSuccessMessage([
'collect' => $collect
]);
}
}