Collect.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/11
* Time: 15:20
*/
namespace app\index\controller;
use app\common\controller\Frontend;
use app\index\model\Goodscollect;
class Collect extends Frontend
{
protected $noNeedLogin = [''];
protected $noNeedRight = ['*'];
public function index(){
$user_id = $this->auth->id;
$goods_id = $this->request->param('goods_id',0,'intval');
if(empty($goods_id)){
$this->error('缺少必要参数');
}
$where['user_id'] = ['eq',$user_id];
$where['goods_id'] = ['eq',$goods_id];
$collectModel = new Goodscollect();
$data = $collectModel->findData($where);
$arr['user_id'] = $user_id;
$arr['goods_id'] = $goods_id;
$arr['createtime'] = time();
if(empty($data)){
$result = $collectModel->insertData($arr);
}else{
$result = $collectModel->deleteData($where);
}
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS',$result);
}
}