Distribut.php
6.89 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: IT宇宙人
*
* Date: 2016-03-09
*/
namespace app\manager\controller;
use think\Page;
use app\manager\logic\GoodsLogic;
use think\Db;
class Distribut extends Base {
/*
* 初始化操作
*/
public function _initialize() {
parent::_initialize();
}
/**
* 分销树状关系
*/
public function tree(){
$where = 'is_distribut = 1 and first_leader = 0';
if($this->request->param('user_id'))
$where = "user_id = '{$this->request->param('user_id')}'";
$list = M('users')->where($where)->select();
$this->assign('list',$list);
return $this->fetch();
}
/**
* 分销商列表
*/
public function distributor_list(){
$condition['is_distribut'] = 1;
$nickname = I('nickname');
if(!empty($nickname)){
$condition['nickname'] = array('like',"%$nickname%");
}
$count = M('users')->where($condition)->count();
$Page = new Page($count,10);
$show = $Page->show();
$user_list = M('users')->where($condition)->order('distribut_money DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
foreach ($user_list as $k=>$val){
$user_list[$k]['fisrt_leader'] = M('users')->where(array('first_leader'=>$val['user_id']))->count();
$user_list[$k]['second_leader'] = M('users')->where(array('second_leader'=>$val['user_id']))->count();
$user_list[$k]['third_leader'] = M('users')->where(array('third_leader'=>$val['user_id']))->count();
$user_list[$k]['lower_sum'] = $user_list[$k]['fisrt_leader'] +$user_list[$k]['second_leader'] + $user_list[$k]['third_leader'];
}
$this->assign('page',$show);
$this->assign('pager',$Page);
$this->assign('user_list',$user_list);
return $this->fetch();
}
/**
* 分销设置
*/
public function set(){
header("Location:".U('Admin/System/index',array('inc_type'=>'distribut')));
exit;
}
public function goods_list(){
$GoodsLogic = new GoodsLogic();
$brandList = $GoodsLogic->getSortBrands();
$categoryList = $GoodsLogic->getSortCategory();
$this->assign('categoryList',$categoryList);
$this->assign('brandList',$brandList);
$where = ' commission > 0 ';
$cat_id = I('cat_id/d');
$bind = array();
if($cat_id > 0)
{
$grandson_ids = getCatGrandson($cat_id);
$where .= " and cat_id in(". implode(',', $grandson_ids).") "; // 初始化搜索条件
}
$key_word = I('key_word') ? trim(I('key_word')) : '';
if($key_word)
{
$where = "$where and (goods_name like :key_word1 or goods_sn like :key_word2)" ;
$bind['key_word1'] = "%$key_word%";
$bind['key_word2'] = "%$key_word%";
}
$brand_id = I('brand_id');
if($brand_id){
$where = "$where and brand_id = :brand_id";
$bind['brand_id'] = $brand_id;
}
$model = M('Goods');
$count = $model->where($where)->bind($bind)->count();
$Page = new Page($count,10);
$show = $Page->show();
$goodsList = $model->where($where)->bind($bind)->order('sales_sum desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$catList = D('goods_category')->select();
$catList = convert_arr_key($catList, 'id');
$this->assign('catList',$catList);
$this->assign('pager',$Page);
$this->assign('goodsList',$goodsList);
$this->assign('page',$show);
return $this->fetch();
}
/**
* 分成记录
*/
public function rebate_log()
{
$model = M("rebate_log");
$status = I('status');
$user_id = I('user_id');
$order_sn = I('order_sn');
$create_time = I('create_time');
$create_time = $create_time ? $create_time : date('Y-m-d',strtotime('-1 year')).' - '.date('Y-m-d',strtotime('+1 day'));
$create_time2 = explode(' - ',$create_time);
$where = " create_time >= '".strtotime($create_time2[0])."' and create_time <= '".strtotime($create_time2[1])."' ";
if($status === '0' || $status > 0)
$where .= " and status = $status ";
$user_id && $where .= " and user_id = $user_id ";
$order_sn && $where .= " and order_sn like '%{$order_sn}%' ";
$count = $model->where($where)->count();
$Page = new Page($count,16);
$list = $model->where($where)->order("`id` desc")->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('create_time',$create_time);
$show = $Page->show();
$this->assign('show',$show);
$this->assign('list',$list);
C('TOKEN_ON',false);
return $this->fetch();
}
/**
* 获取某个人下级元素
*/
public function ajax_lower()
{
$id = $this->request->param('id');
$list = M('users')->where("first_leader =".$id)->select();
$this->assign('list',$list);
return $this->fetch();
}
/**
* 修改编辑 分成
*/
public function editRebate(){
$id = I('id');
$rebate_log = DB::name('rebate_log')->where('id',$id)->find();
if (IS_POST) {
$data = I('post.');
// 如果是确定分成 将金额打入分佣用户余额
if ($data['status'] == 3 && $rebate_log['status'] != 3) {
accountLog($data['user_id'], $rebate_log['money'], 0, "订单:{$rebate_log['order_sn']}分佣", $rebate_log['money']);
}
DB::name('rebate_log')->update($data);
$this->success("操作成功!!!", U('Admin/Distribut/rebate_log'));
exit;
}
$user = M('users')->where("user_id = {$rebate_log[user_id]}")->find();
if($user['nickname'])
$rebate_log['user_name'] = $user['nickname'];
elseif($user['email'])
$rebate_log['user_name'] = $user['email'];
elseif($user['mobile'])
$rebate_log['user_name'] = $user['mobile'];
$this->assign('user',$user);
$this->assign('rebate_log',$rebate_log);
return $this->fetch();
}
}