Newpeoplegift.php
19.3 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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: 当燃
* 专题管理
* Date: 2016-03-09
*/
namespace app\admin\controller;
use phpDocumentor\Reflection\DocBlock\Tag\VarTagTest;
use think\AjaxPage;
use think\model\Merge;
use think\Page;
use app\admin\logic\GoodsLogic;
use think\db;
class Newpeoplegift extends Base
{
public function _initialize()
{
parent::_initialize();
$timegap = I('timegap');
$ishis = I('ishis');
$timegap = urldecode(urldecode($timegap));
if ($timegap) {
$gap = explode(' - ', $timegap);
$begin = $gap[0];
$end = $gap[1];
} else {
// $lastweek = date('Y-m-d',strtotime("-1 month"));//30天前
// $begin = I('begin',$lastweek).' 00:00:00';
//
// $end = I('end',date('Y-m-d')).' 23:59:59';
}
if ($timegap) {
$this->assign('start_time', $begin);
$this->assign('end_time', $end);
$this->begin = strtotime($begin);
$this->end = strtotime($end);
$this->assign('timegap', date('Y-m-d h:m:s', $this->begin) . ' - ' . date('Y-m-d h:m:s', $this->end));
}
$this->assign('ishis', $ishis);
}
public function index()
{
$getp = I('p');
if (empty($getp)) {
$getp = 0;
}
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$oldurl = U('Admin/Marketinglibao/index', array(
"p" => $getp
));
$this->assign('oldurl', urlencode($oldurl));
$this->assign('pagenum', $pagenum);
$this->assign('cur_page', $getp);
return $this->fetch('', getAdmStoId());
}
public function ajaxindex()
{
$cur_page = 1;//当前页数
if ((int)I('p/s') > 0) {
$cur_page = I('p/s');
}
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
$ylp_postdata["pageSize"] = $pagenum;
}
$begin = $this->begin;
$end = $this->end;
$activityName = I('activityName') ? trim(I('activityName')) : ''; // 活动名称
$status = I('status');//活动状态
$where["a.store_id"] = getAdmStoId();
if ($begin) {
$where['a.begindate'] = array('egt', $begin);
}
if ($end) {
$where['a.enddate'] = array('elt', $end);
}
//$where['a.isdel'] = 0;
if ($activityName) {
$where["a.activity_name"] = array('like','%'.$activityName.'%');
}
if ($status != "") {
switch ($status) {
case "0":
$where['a.isdel'] = 0;
$where['a.begindate'] = array('gt', time());
break;
case "1":
$where['a.isdel'] = 0;
$where['a.begindate'] = array('elt', time());
$where['a.enddate'] = array('gt', time());
break;
case "-1":
//$where['a.isdel'] = 1;
$where="a.isdel=1 or a.enddate<".time();
break;
}
}
$data1 = M('marketing_newpeople_gift')->alias("a")->where($where)->select();
$count = count($data1);
$Page = new AjaxPage($count, $pagenum);
$show = $Page->show();
$list = M('marketing_newpeople_gift')->alias("a")
->join('marketing_libao_form b', 'a.store_id=b.store_id and a.gifbagid=b.id', 'left')
->where($where)
->limit($Page->firstRow . ',' . $Page->listRows)
->field('a.*,b.lbtitle')
->order(array('sort_order', 'id' => 'desc'))
->select();
$oldurl = U('Admin/Newpeoplegift/ajaxindex', array(
"pagenum" => $pagenum,
"p" => $cur_page
));
$this->assign('oldurl', urlencode($oldurl));
$this->assign('page', $show);
$this->assign('pager', $Page);
$this->assign('pagenum', $pagenum);
$this->assign('cur_page', $cur_page);
$this->assign('list', $list);
$this->assign('timegap', date('Y-m-d h:m:s', $this->begin) . ' - ' . date('Y-m-d h:m:s', $this->end));
return $this->fetch('', getAdmStoId());
}
public function addindex()
{
$getadmstoid = getAdmStoId();
$accdb = getERPId();
$m = db::query("select max(sort_order)odr from __PREFIX__marketing_newpeople_gift where store_id=" . $getadmstoid);
$md = (int)$m[0]["odr"];
$md++;
$deatillp['sort_order'] = $md;
$deatillp['is_show'] = 1;
$deatillp['begindate'] = time();
$deatillp['enddate'] = time() + 3600 * 24 * 30;
$getid = I('id/d', 0);
$lblist = M('marketing_libao_form')->where(array('store_id' => $getadmstoid, 'is_act' => 1,"isdel"=>0))->select();
$this->assign('lblist', $lblist);
//修改
if ($getid) {
$deatillp = M('marketing_newpeople_gift')->where(array('store_id' => getAdmStoId(), 'id' => $getid))->find();
if($deatillp){
//开始时间大于当前时间
if ($deatillp['startime']<time())
{
$this->assign('is_stime', 1);
}
}
}
$this->assign('deatillp', $deatillp);
$this->initEditor(); // 编辑器
return $this->fetch('', getAdmStoId());
}
public function addindexhand()
{
if (IS_POST) {
$data = input('post.');
$lbid = $data['id'];
$rr = M("admin")->where("admin_id", getAdminId())->find();
$data['begindate'] = strtotime($data['begindate']);
$data['enddate'] = strtotime($data['enddate']);
if ($lbid) {
$oldurl = I('oldurl/s');
if ($oldurl) {
$oldurl = urldecode(urldecode($oldurl));
}
$this->assign('oldurl', $oldurl);
unset($data['id']);
$data['edittime'] = time();
$data['editip'] = getIP();
$data['editman'] = $rr['ERPName'];
$results = M('marketing_newpeople_gift')->where(array('store_id' => getAdmStoId(), 'id' => $lbid))->save($data);
if ($results) {
$this->success('操作成功', U('admin/Newpeoplegift/index'));
exit;
} else {
$this->error('操作失败');
exit;
}
} else {
$data['store_id'] = getAdmStoId();
$data['edittime'] = time();
$data['addtime'] = time();
$data['addip'] = getIP();
$data['addman'] = $rr['ERPName'];
$results = M('marketing_newpeople_gift')->save($data);
if ($results) {
$this->success('操作成功', U('admin/Newpeoplegift/addindex'));
exit;
} else {
$this->error('操作失败');
exit;
}
}
}
}
//删除礼包活动
public function dellibao()
{
$getadmstoid = getAdmStoId();
$id = $this->request->param('id');
//$lqnum = M('marketing_user_buyreceive_form')->where(array('store_id' => $getadmstoid, 'act_id' => $id, 'act_type' => 1))->count();
//if ($lqnum > 0) {
$updatadata['isdel'] = 1;
M('marketing_newpeople_gift')->where(array('store_id' => $getadmstoid, 'id' => $id, 'isdel' => 0))->save($updatadata);
//}
/*---
else {
M('marketing_newpeople_gift')->where(array('store_id' => $getadmstoid, 'id' => $id))->delete();
}--*/
$return_arr = array(
'status' => 1,
'msg' => '操作成功',
'data' => array('url' => U('admin/Newpeoplegift/index')),
);
$this->ajaxReturn($return_arr);
}
private function initEditor()
{
$this->assign("URL_upload", U('Admin/Ueditor/imageUp', array('savepath' => 'newpeoplegift', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_fileUp", U('Admin/Ueditor/fileUp', array('savepath' => 'newpeoplegift', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp', array('savepath' => 'newpeoplegift', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage', array('savepath' => 'newpeoplegift', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_imageManager", U('Admin/Ueditor/imageManager', array('savepath' => 'newpeoplegift', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_imageUp", U('Admin/Ueditor/imageUp', array('savepath' => 'newpeoplegift', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_getMovie", U('Admin/Ueditor/getMovie', array('savepath' => 'newpeoplegift', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_Home", "");
}
//领取记录
public function lqlist()
{
//--查看购买记录的类型--
$type=I("type",1);
$this->assign('type', $type);
$cur_page = 1;//当前页数
if ((int)I('p/s') > 0) {
$cur_page = I('p/s');
}
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
$ylp_postdata["pageSize"] = $pagenum;
}
if ($this->begin > 100 && $this->end > 100) {
$begin = $this->begin;
$end = $this->end;
$this->assign('timegap', date('Y-m-d h:m:s', $this->begin) . '-' . date('Y-m-d h:m:s', $this->end));
}
$begin= $add_time_begin=I("add_time_begin");
$end=$add_time_end=I("add_time_end");
if($add_time_begin){
$this->assign('start_time', $add_time_begin);
$this->assign('end_time', $add_time_end);
$this->assign('timegap', $add_time_begin . ' - ' . $add_time_end);
}
$mobile = I('mobile') ? trim(I('mobile')) : '';
$where["a.store_id"] = getAdmStoId();
$where2="1=1";
if ($begin) {
$where2.= ' and a.addtime>='. strtotime($begin);
}
if ($end) {
$where2.= ' and a.addtime<='.strtotime($end);
}
if ($mobile) {
$where['c.mobile|c.nickname'] = array('like', urldecode(urldecode($mobile)));
}
$where["a.act_type"] = $type;
if ($mobile) {
$where["c.mobile"] = urldecode($mobile);
}
$count = M('marketing_user_buyreceive_form')->alias("a")
->join('marketing_libao_form b', 'a.store_id=b.store_id and a.lb_id=b.id', 'left')
->join('(select store_id,user_id,mobile,vipname,nickname from wxd_users where store_id=' . getAdmStoId() . ') c', 'a.user_id=c.user_id', 'left')
->where($where)
->where($where2)
//->fetchSql(true)
->count();
$Page = new Page($count, $pagenum);
$show = $Page->show();
$list = M('marketing_user_buyreceive_form')->alias("a")
->join('marketing_libao_form b', 'a.store_id=b.store_id and a.lb_id=b.id', 'left')
->join('(select store_id,user_id,mobile,vipname,nickname from wxd_users where store_id=' . getAdmStoId() . ') c', 'a.user_id=c.user_id', 'left')
->where($where)
->where($where2)
->limit($Page->firstRow . ',' . $Page->listRows)
->field('a.*,b.lbtitle,b.lb_type,c.mobile,c.nickname')
->order(array('id' => 'desc'))
->select();
$oldurl = U('Admin/Newpeoplegift/lqlist', array(
"pagenum" => $pagenum,
"p" => $cur_page
));
$this->assign('oldurl', urlencode($oldurl));
$this->assign('keyword', $mobile);
$this->assign('page', $show);
$this->assign('pager', $Page);
$this->assign('pagenum', $pagenum);
$this->assign('cur_page', $cur_page);
$this->assign('list', $list);
return $this->fetch('', getAdmStoId());
}
/*购买记录导出*/
public function export_lqlist()
{
$cur_page = 1;//当前页数
if ((int)I('p/s') > 0) {
$cur_page = I('p/s');
}
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
$ylp_postdata["pageSize"] = $pagenum;
}
if ($this->begin > 100 && $this->end > 100) {
$begin = $this->begin;
$end = $this->end;
$this->assign('timegap', date('Y-m-d h:m:s', $this->begin) . ' - ' . date('Y-m-d h:m:s', $this->end));
}
$mobile = I('mobile') ? trim(I('mobile')) : '';
$where["a.store_id"] = getAdmStoId();
if ($begin) {
$where['a.addtime'] = array('egt', $begin);
}
if ($end) {
$where['a.addtime'] = array('elt', $end);
}
if ($mobile) {
$where['c.mobile|c.nickname'] = array('like', urldecode(urldecode($mobile)));
}
$where["a.act_type"] = 1;
if ($mobile) {
$where["c.mobile"] = urldecode($mobile);
}
$list = M('marketing_user_buyreceive_form')->alias("a")
->join('marketing_libao_form b', 'a.store_id=b.store_id and a.lb_id=b.id', 'left')
->join('(select store_id,user_id,mobile,vipname,nickname from wxd_users where store_id=' . getAdmStoId() . ') c', 'a.user_id=c.user_id', 'left')
->where($where)
->field('a.*,b.lbtitle,b.lb_type,c.mobile,c.nickname')
->order(array('id' => 'desc'))
->select();
$strTable = '<table border="1">';
$strTable .= '<tr style="font-weight: bold;">';
$strTable .= '<td style="text-align:center;" width="200">礼包名称</td>';
$strTable .= '<td style="text-align:center;" width="150">礼包类型</td>';
$strTable .= '<td style="text-align:center;" width="100">会员昵称</td>';
$strTable .= '<td style="text-align:center;" width="100">手机号</td>';
$strTable .= '<td style="text-align:center;" width="150">购买时间</td>';
$strTable .= '</tr>';
if (is_array($list)) {
foreach ($list as $k => $val) {
$strTable .= '<tr>';
$strTable .= '<td style="text-align:left;">' . $val['lbtitle'] . ' </td>';
$strTable .= '<td style="text-align:center;">' . (stripos($val['lb_type'], ',1,') !== false ? "礼品" : "") . (stripos($val['lb_type'], ',2,') !== false ? "/优惠券" : "") . (stripos($val['lb_type'], ',3,') !== false ? "/服务项目" : "") . (stripos($val['lb_type'], ',4,') !== false ? "/积分" : "") . (stripos($val['lb_type'], ',5,') !== false ? "/成长值" : "") . '</td>';
$strTable .= '<td style="text-align:left;">' . $val['nickname'] . ' </td>';
$strTable .= '<td style="text-align:center;">' . $val['mobile'] . '</td>';
$strTable .= '<td style="text-align:center;"> ' . date("Y-m-d H:i:s", $val['addtime']) . '</td>';
$strTable .= '</tr>';
}
}
$strTable .= '</table>';
echo $strTable;
unset($redmoneylist);
downloadExcel($strTable, '新人有礼领取礼包记录');
exit();
}
//礼包详细
public function details()
{
$getId = I('id/d');
$getadmstoid = getAdmStoId();
if (empty($getId)) {
$this->error('传递参数有误');
exit;
}
$info = M('marketing_user_buyreceive_form')->alias("a")
->join('marketing_libao_form b', 'a.store_id=b.store_id and a.lb_id=b.id', 'left')
->field('a.*,b.lbtitle,b.lb_type')
->where(array('a.store_id' => $getadmstoid, 'a.id' => $getId))->find();
if (empty($info)) {
$this->error('找不到相关信息');
exit;
}
$deatillp_list1 = M('marketing_user_buyreceive_list')->alias("a")
->join("(select goods_id,goods_sn,goods_name,sku,market_price from wxd_goods where store_id=" . $getadmstoid . ") g", 'a.goods_id=g.goods_id', 'left')
->where(array('a.store_id' => $getadmstoid, 'a.form_order_sn' => $info['order_sn'], 'a.lbtype' => 1))->select();
$deatillp_list2 = M('marketing_user_buyreceive_list')->where(array('store_id' => $getadmstoid, 'form_order_sn' => $info['order_sn'], 'lbtype' => 2))->select();
$deatillp_list3 = M('marketing_user_buyreceive_list')->alias("a")
->join("(select fromid,fw_name,fw_no from wxd_marketing_libao_list where store_id=" . $getadmstoid . " and lbid=".$info['lb_id']." ) g", ' a.service_init_id=g.fromid ')
->where(array('a.store_id' => $getadmstoid, 'a.form_order_sn' => $info['order_sn'], 'a.lbtype' => 3))->select();
$deatillp_list4 = M('marketing_user_buyreceive_list')->where(array('store_id' => $getadmstoid, 'form_order_sn' => $info['order_sn'], 'lbtype' => 4))->find();
$deatillp_list5 = M('marketing_user_buyreceive_list')->where(array('store_id' => $getadmstoid, 'form_order_sn' => $info['order_sn'], 'lbtype' => 5))->find();
$this->assign('deatillp', $info);
$this->assign('deatillp_list1', $deatillp_list1);
$this->assign('deatillp_list2', $deatillp_list2);
$this->assign('deatillp_list3', $deatillp_list3);
$this->assign('deatillp_list4', $deatillp_list4);
$this->assign('deatillp_list5', $deatillp_list5);
return $this->fetch('', getAdmStoId());
}
//新人礼判断是否时间有交叉
public function is_time_ok(){
$start=I("begindate");
$end=I("enddate");
$id=I("id");
$wh="1=1 and isdel=0";
if($start) $start=strtotime($start);
if($end) $end=strtotime($end);
if($id) $wh.=" and id<>".$id;
$res=M("marketing_newpeople_gift")->where("store_id",getAdmStoId())->where($wh)
->where("begindate<=".$start." and ". $start."<=enddate")->find();
if($res) return json(["code" => -1, "msg" => "活动时间不能交叉"]);
$res=M("marketing_newpeople_gift")->where("store_id",getAdmStoId())->where($wh)
->where("begindate<=".$end." and ". $end."<=enddate")->find();
if($res) return json(["code" => -1, "msg" => "活动时间交叉"]);
$res=M("marketing_newpeople_gift")->where("store_id",getAdmStoId())->where($wh)
->where("begindate>=".$start." and ". $end.">=enddate")->find();
if($res) json(["code" => -1, "msg" => "活动时间交叉"]);
return json(["code" => 0, "msg" => "活动时间OK"]);
}
}