SalesmangoodsController.php
3.4 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class SalesmangoodsController extends AdminBaseController{
/**
*业务员商品列表
*/
public function salesman_list(){
if($this -> request -> isPost()){
$where = [
'type' => 2,
];
if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
$start_time = strtotime($_POST['start_time']);
$end_time = strtotime($_POST['end_time']);
$where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
}
if(!empty($_POST['keyword'])){
$keyword = $_POST['keyword'];
$where['a.book_name'] = ['like',"%$keyword%"];
}
$data = Db::name('goods') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b',"a.uid=b.id",'LEFT') -> where($where) -> paginate(1000000);
$this -> assign('data',$data);
return $this -> fetch();
}else{
$data = Db::name('goods') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b',"a.uid=b.id",'LEFT') -> where('type',2) -> paginate(12);
$this -> assign('data',$data);
return $this -> fetch();
}
}
/**
* 业务员商品编辑查看
*/
public function salesman_edit(){
if($this -> request -> isPost()){
if($_POST['money'] > $_POST['price']){
$this -> error('佣金不能大于售价');
}
if(!empty($_POST['det_img'])){
$_POST['det_img'] = json_encode($_POST['det_img']);
$_POST['det_name'] = json_encode($_POST['det_name']);
}
$data = Db::name('goods') -> update($_POST);
if($data){
$this -> success('保存成功',url('Salesmangoods/salesman_edit',array('id'=>$_POST['id'])));
}else{
$this -> error('保存失败');
}
}else{
$id = $this -> request -> param();
$data = Db::name('goods') -> where('id',$id['id']) -> find();
if(!empty($data['det_img'])){
$data['det_img'] = json_decode($data['det_img'],true);
$data['det_name'] = json_decode($data['det_name'],true);
foreach ($data['det_img'] as $key => $val){
$data['more'][$key]['url'] = $data['det_img'][$key];
$data['more'][$key]['name'] = $data['det_name'][$key];
}
}
$data_gradeall = Db::name('gradeall ') -> select();
$this -> assign('data_gradeall',$data_gradeall);
$this -> assign('data',$data);
return $this -> fetch();
}
}
/**
* 业务员商品列删除
*/
public function salesman_del(){
$data = Db::name('goods') -> delete($_POST['id']);
//删除浏览记录
Db::name('browsing_history') -> where('goods_id',$_POST['id']) -> delete();
//删除收藏
Db::name('collect') -> where('goods_id',$_POST['id']) -> delete();
//删除购物车
Db::name('shopping_cart') -> where('goods_id',$_POST['id']) -> delete();
if($data){
return true;
}else{
return false;
}
}
}