marketing.php
11.8 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<?php
/**
* description...
*
* @author Tinyning
* @package AdminController
*/
class MarketingController extends Controller
{
public $layout='admin';
private $top = null;
public $needRightActions = array('*'=>true);
public function init()
{
$menu = new Menu();
$this->assign('mainMenu',$menu->getMenu());
$menu_index = $menu->current_menu();
$this->assign('menu_index',$menu_index);
$this->assign('subMenu',$menu->getSubMenu($menu_index['menu']));
$this->assign('menu',$menu);
$nav_act = Req::get('act')==null?$this->defaultAction:Req::get('act');
$nav_act = preg_replace("/(_edit)$/", "_list", $nav_act);
$this->assign('nav_link','/'.Req::get('con').'/'.$nav_act);
$this->assign('node_index',$menu->currentNode());
$this->safebox = Safebox::getInstance();
$this->assign('manager',$this->safebox->get('manager'));
$currentNode = $menu->currentNode();
if(isset($currentNode['name']))$this->assign('admin_title',$currentNode['name']);
}
public function noRight()
{
$this->redirect("admin/noright");
}
//编辑捆绑促销
public function bundling_save()
{
$id = Req::args('id');
$goods_id = Req::args("goods_id");
if(count($goods_id)<2){
$this->msg = array("warning","捆绑促销商品数量至少2件!");
$this->redirect('bundling_edit',false,Req::args());
exit();
}
if(is_array($goods_id)){
$goods_id = array_unique($goods_id);
$goods_id = implode(',', $goods_id);
}
Req::args("goods_id",$goods_id);
$model = new Model('bundling');
$model->save();
if($id){
Log::op($this->manager['id'],"修改捆绑促销","管理员[".$this->manager['name']."]:修改了捆绑促销 ".Req::args('title'));
}else{
Log::op($this->manager['id'],"添加捆绑促销","管理员[".$this->manager['name']."]:添加了捆绑促销 ".Req::args('title'));
}
$this->redirect("bundling_list");
}
//删除捆绑促销
public function bundling_del()
{
$model = new Model("bundling");
$id = Req::args("id");
if($id){
$obj = $model->where("id = $id")->find();
$model->where("id = $id")->delete();
if($obj)Log::op($this->manager['id'],"删除捆绑促销","管理员[".$this->manager['name']."]:删除了捆绑促销 ".$obj['title']);
}
$this->redirect("bundling_list");
}
//选择捆绑促销的商品
public function bundling_goods_select()
{
$this->layout = "blank";
$s_type = Req::args("s_type");
$s_content = Req::args("s_content");
$where = "1=1";
if($s_content && $s_content!=''){
if($s_type==1){
$where .= " and goods_no = '{$s_content}'";
}else if($s_type==2) {
$where .= " and name like '{$s_content}%' ";
}
}
$this->assign("s_type",$s_type);
$this->assign("s_content",$s_content);
$goods_id = Req::args("goods_id");
if(is_array($goods_id)){
$goods_id = implode(',', $goods_id);
}
if($goods_id) $where .= " and id not in($goods_id)";
$id = Req::args('id');
if(!$id || $id=='') $id = 0;
$this->assign('id',$id);
$this->assign('goods_id',$goods_id);
$this->assign("where",$where);
$this->redirect();
}
public function radio_goods_select()
{
$this->layout = "blank";
$s_type = Req::args("s_type");
$s_content = Req::args("s_content");
$where = "1=1";
if($s_content && $s_content!=''){
if($s_type==1){
$where = "goods_no = '{$s_content}'";
}else if($s_type==2) {
$where = "name like '{$s_content}%' ";
}
}
$this->assign("s_type",$s_type);
$this->assign("s_content",$s_content);
$id = Req::args('id');
if(!$id || $id=='') $id = 0;
$this->assign('id',$id);
$this->assign("where",$where);
$this->redirect();
}
public function prom_goods_save()
{
$group = Req::args("group");
$id = Req::args('id');
if(is_array($group)){
$group = implode(',', $group);
Req::args("group",$group);
}else{
Req::args("group",'');
}
$model = new Model('prom_goods');
if($id){
$model->where("id=$id")->update();
$last_id = $id;
Log::op($this->manager['id'],"修改商品促销","管理员[".$this->manager['name']."]:修改了商品促销 ".Req::args('name'));
}else{
$last_id = $model->insert();
Log::op($this->manager['id'],"添加商品促销","管理员[".$this->manager['name']."]:添加了商品促销 ".Req::args('name'));
}
$goods_id = Req::args("goods_id");
$model->table("goods")->data(array('prom_id'=>0))->where("prom_id = $last_id")->update();
if(is_array($goods_id)){
$goods_id = implode(',', $goods_id);
$where = " id in($goods_id)";
$model->table("goods")->data(array('prom_id'=>$last_id))->where($where)->update();
}
$this->redirect("prom_goods_list");
}
public function prom_order_save()
{
$group = Req::args("group");
if(is_array($group)){
$group = implode(',', $group);
Req::args("group",$group);
}else{
Req::args("group",'');
}
$id = Req::args("id");
$model = new Model('prom_order');
if($id){
$model->where("id=$id")->update();
Log::op($this->manager['id'],"修改订单促销","管理员[".$this->manager['name']."]:修改了订单促销 ".Req::args('name'));
}else{
$model->where("id=$id")->insert();
Log::op($this->manager['id'],"添加订单促销","管理员[".$this->manager['name']."]:添加了订单促销 ".Req::args('name'));
}
$this->redirect("prom_order_list");
}
public function prom_goods_list()
{
$parse_type = array('0'=>'直接打折','1'=>'减价优惠','2'=>'固定金额出售','3'=>'买就赠优惠券','4'=>'买M件送N件');
$this->assign("parse_type",$parse_type);
$model = new Model('grade');
$rows = $model->findAll();
$grades = array(0=>'默认会员');
foreach ($rows as $row) {
$grades[$row['id']] = $row['name'];
}
$this->assign("grades",$grades);
$this->redirect();
}
public function prom_goods_del()
{
$model = new Model();
$id = Req::args("id");
if($id){
$model->table("goods")->data(array('prom_id'=>0))->where("prom_id = $id")->update();
$obj = $model->table('prom_goods')->where("id = $id")->find();
$model->table('prom_goods')->where("id = $id")->delete();
if($obj)Log::op($this->manager['id'],"删除商品促销","管理员[".$this->manager['name']."]:删除了商品促销 ".$obj['name']);
}
$this->redirect("prom_goods_list");
}
public function prom_order_del()
{
$model = new Model("prom_order");
$id = Req::args("id");
if($id){
$obj = $model->where("id = $id")->find();
$model->where("id = $id")->delete();
if($obj)Log::op($this->manager['id'],"删除订单促销","管理员[".$this->manager['name']."]:删除了订单促销 ".$obj['name']);
}
$this->redirect("prom_order_list");
}
public function prom_order_list()
{
$parse_type = array('0'=>'满额打折','1'=>'满额优惠金额','2'=>'满额送倍数积分','3'=>'满额送优惠券','4'=>'满额免运费');
$this->assign("parse_type",$parse_type);
$model = new Model('grade');
$rows = $model->findAll();
$grades = array(0=>'默认会员');
foreach ($rows as $row) {
$grades[$row['id']] = $row['name'];
}
$this->assign("grades",$grades);
$this->redirect();
}
public function goods_select()
{
$this->layout = "blank";
$s_type = Req::args("s_type");
$s_content = Req::args("s_content");
$where = "";
if($s_content && $s_content!=''){
if($s_type == 1){
$where = " and goods_no = '{$s_content}'";
}else if($s_type==2) {
$where = " and name like '{$s_content}%' ";
}
}
$this->assign("s_type",$s_type);
$this->assign("s_content",$s_content);
$goods_id = Req::args("goods_id");
if(is_array($goods_id)){
$goods_id = implode(',', $goods_id);
$where .= " and id not in($goods_id)";
}else{
$where .= "";
}
$id = Req::args('id');
if(!$id || $id=='') $id = 0;
$this->assign('id',$id);
$this->assign("where",$where);
$this->redirect();
}
public function goods_show()
{
$this->layout = "blank";
$id = Req::args('id');
$this->assign("id",$id);
$this->redirect();
}
public function voucher_list()
{
$condition = Req::args('condition');
$condition_str = Common::str2where($condition);
if($condition_str)$this->assign("where",$condition_str);
else $this->assign("where","1=1");
$this->assign("condition",$condition);
$parse_status = array(0=>'<b class="green">未使用</b>',1=>'<b>已使用</b>',2=>'<b class="red">临时锁定</b>',3=>'<s class="red"><b>禁用</b></s>');
$this->assign("parse_status",$parse_status);
$this->redirect();
}
public function voucher_csv()
{
$fields_array = array(
'id'=>'ID编号',
'name'=>'名称',
'account'=>'账号',
'password'=>'密码',
'value'=>'面值',
'start_time'=>'开始时间',
'end_time'=>'到期时间',
'status'=>'状态',
'is_send'=>'发放情况'
);
$heading = array();
$condition = Req::args('condition');
$fields = Req::args('fields');
$fields_key = array();
if(is_array($fields)){
foreach ($fields as $fied) {
if(isset($fields_array[$fied])){
$heading[] = $fields_array[$fied];
$fields_key[] = $fied;
}
}
}
$condition_str = Common::str2where($condition);
if($condition_str == null)$condition_str = " 1=1 ";
if(empty($fields_key)){
$fields_key = array_keys($fields_array);
$heading = array_values($fields_array);
}
$model = new Model('voucher');
$fields_str = implode(',', $fields_key);
$vouchers = $model->fields($fields_str)->where($condition_str)->findAll();
Http::exportCSV($heading,$vouchers,"vouchers_".date("Y_m_d"));
}
public function voucher_disabled()
{
$id = Req::args("id");
$model = new Model('voucher');
if(is_array($id)){
$ids = implode(',', $id);
$model->data(array('status'=>3))->where("id in($ids)")->update();
}
elseif ($id) {
$model->data(array('status'=>3))->where("id = $id")->update();
}
$this->redirect("voucher_list");
}
public function voucher_send()
{
$id = Req::args("id");
$model = new Model('voucher');
if(is_array($id)){
$ids = implode(',', $id);
$model->data(array('is_send'=>1))->where("id in($ids)")->update();
}
elseif ($id) {
$model->data(array('is_send'=>1))->where("id = $id")->update();
}
$this->redirect("voucher_list");
}
public function voucher_create()
{
$id = Req::args("id");
$start_time = Req::args("start_time");
$start_time = $start_time==null?date("Y-m-d"):$start_time;
$end_time = Req::args("end_time");
$end_time = $end_time==null?date("Y-m-d 23:59:59", strtotime("+30 days")):date("Y-m-d 23:59:59", strtotime($end_time));
$model = new Model('voucher_template');
$voucher_template = $model->where("id = $id")->find();
if($voucher_template){
$voucher_model = new Model('voucher');
$num = Req::args('num');
$i = 0;
while ( $i < $num) {
do{
$account = strtoupper(CHash::random(10,'char'));
$password = strtoupper(CHash::random(10,'char'));
$voucher_template['account'] = $account;
$voucher_template['password'] = $password;
$voucher_template['start_time'] = $start_time;
$voucher_template['end_time'] = $end_time;
$obj = $voucher_model->where("account = '$account'")->find();
}while($obj);
unset($voucher_template['id'],$voucher_template['point']);
$voucher_model->data($voucher_template)->insert();
$i++;
}
}
echo JSON::encode(array('status'=>'success','msg'=>'已成功生成['.$voucher_template['name'].']代金券('.$num.')张'));
}
public function voucher_template_validator()
{
$rules = array('name:required:模板名称不能为空!','value:float:面值必需是数据型格式!','point:int:积分必需为整数!','money:int:需满足的消费金额必需为整数!');
$info = Validator::check($rules);
return $info;
}
}