Marketinglibao.php
37.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
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
<?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\Page;
use app\admin\logic\GoodsLogic;
use think\db;
class Marketinglibao extends Base
{
//--- 礼包列表页 ---
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
));
$ishis = I('ishis');
$this->assign('oldurl', urlencode($oldurl));
$this->assign('pagenum', $pagenum);
$this->assign('cur_page', $getp);
$this->assign('ishis', $ishis);
return $this->fetch('', getAdmStoId());
}
//--- 礼包列表页ajax ---
public function ajaxindex()
{
$cur_page = 1;//当前页数
if ((int)I('p/s') > 0) {
$cur_page = I('p/s');
}
$ylp_postdata["page"] = $cur_page;
$pagenum = 10;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
$ylp_postdata["pageSize"] = $pagenum;
}
$startTime = I('startTime') ? trim(I('startTime')) : ''; // 开始时间
$endTime = I('endTime') ? trim(I('endTime')) : ''; // 结束时间
$activityName = I('activityName') ? trim(I('activityName')) : ''; // 活动名称
$activityId = I('activityId') ? trim(I('activityId')) : ''; // 活动编号
$status = I('status');//活动状态
$ishis = I('ishis');
$ylp_postdata["startTime"] = urlencode($startTime);
$ylp_postdata["endTime"] = urlencode($endTime);
$ylp_postdata["activityName"] = urlencode($activityName);
$ylp_postdata["id"] = urlencode($activityId);
$ylp_postdata["status"] = $status;
$url = parameter_connect($ylp_postdata);
$oldurl = U('Admin/Marketinglibao/ajaxindex', array(
"pagenum" => $pagenum,
"p" => $cur_page
));
$key_word = I('activityName') ? trim(I('activityName')) : ''; // 关键词搜索
if ($key_word !== "") {
$where['lbtitle'] = array('like', '%' . $key_word . '%');
}
if ($startTime) {
$where['startime'] = array('egt', strtotime($startTime));
}
if ($endTime) {
$where['endtime'] = array('elt', strtotime($endTime));
}
$where['isdel'] = 0;
if ($ishis) $where['isdel'] = 1;
if ($status != "" && $status != null) {
$where['isshow'] = $status;
}
$data1 = M('marketing_libao_form')->where($where)->count();
$Page = new AjaxPage($data1, $pagenum);
$show = $Page->show();
$data = M('marketing_libao_form')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order(array('sort_order' => 'desc', 'addtime' => 'desc'))->select();
foreach ($data as $k => $v) {
$num = M("marketing_user_buyreceive_form")
->where("pay_state=1 and act_type=0")
->where("lb_id", $v['id'])->where('store_id', getAdmStoId())->count();
$data[$k]['bnum'] = $num;
}
$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('goodsList', $data);
return $this->fetch('', getAdmStoId());
}
//--- 添加修改礼包 ---
public function addindex()
{
$getadmstoid = getAdmStoId();
$accdb = getERPId();
$rank_switch = tpCache('shopping.rank_switch', $getadmstoid);//PLUS开关
$islook = I("islook");
$this->assign("islook", $islook);
if ($rank_switch) {
$this->assign('rank_switch', $rank_switch);
$plus_data['storeId'] = $getadmstoid;
$plus_list = getApiData_mini("/api/weshop/plus/vip/mem/bership/list", $plus_data, $getadmstoid);
if ($plus_list) {
$plus_list = json_decode($plus_list, true);
if ($plus_list['code'] == 0 && $plus_list['data']) {
$this->assign('plus_list', $plus_list['data']);
}
}
}
//会员权益
$grade_data['storeId'] = $getadmstoid;
$init_data = getApiData_mini("api/weshop/users/grade/vip/init/get", $grade_data, $getadmstoid);
$isBool = 0;
if ($init_data) {
$init_data = json_decode($init_data, true);
if ($init_data['code'] === 0 && $init_data['data']) {
try {
$isBool = $init_data['data']['isBool'];
} catch (\Exception $e) {
}
$this->assign('isBool', $isBool);
if ($isBool) {
//会员权益列表
$grade_list = getApiData_mini("/api/weshop/users/grade/vipgradeinfo/page", $grade_data, $getadmstoid);
if ($grade_list) {
$grade_list = json_decode($grade_list, true);
if ($grade_list['code'] == 0 && $grade_list['data']['pageData']) {
$this->assign('grade_list', $grade_list['data']['pageData']);
}
}
}
}
}
//默认添加
$m = db::query("select max(sort_order)odr from __PREFIX__marketing_libao_form where store_id=" . $getadmstoid);
$md = (int)$m[0]["odr"];
$md++;
$deatillp['sort_order'] = $md;
$deatillp['isshow'] = 1;
$deatillp['lb_type'] = ",1,";
$deatillp['startime'] = date('Y-m-d H:i:s');
$deatillp['endtime'] = date('Y-m-d 23:59:59', time() + 3600 * 24 * 30);
//---如果有ID的话,是修改----
$id = I("id");
if ($id) {
$deatillp = M("marketing_libao_form")->where("store_id", $getadmstoid)->where("id", $id)->find();
if (empty($deatillp)) {
$this->error("找不到相关信息");
}
//开始时间大于当前时间
if ($deatillp['startime'] < time()) {
$this->assign('is_stime', 1);
}
//-- 时间修改 --
if ($deatillp['startime']) $deatillp['startime'] = date("Y-m-d H:i:s", $deatillp['startime']);
if ($deatillp['endtime']) $deatillp['endtime'] = date("Y-m-d H:i:s", $deatillp['endtime']);
if ($deatillp['exchange_starttime']) $deatillp['exchange_starttime'] = date("Y-m-d H:i:s", $deatillp['exchange_starttime']);
if ($deatillp['exchange_endtime']) $deatillp['exchange_endtime'] = date("Y-m-d H:i:s", $deatillp['exchange_endtime']);
$deatillp_list1 = M("marketing_libao_list")->where("lbtype", 1)->where("store_id", $getadmstoid)->where("lbid", $id)->select();
$deatillp_list2 = M("marketing_libao_list")->where("lbtype", 2)->where("store_id", $getadmstoid)->where("lbid", $id)->select();
$deatillp_list3 = M("marketing_libao_list")->where("lbtype", 3)->where("store_id", $getadmstoid)->where("lbid", $id)->select();
if ($deatillp_list1) {
foreach ($deatillp_list1 as $k => $v) {
$g = M("goods")->where("goods_id", $v['fromid'])->find();
$deatillp_list1[$k]['goods_sn'] = $g['goods_sn'];
$deatillp_list1[$k]['goods_name'] = $g['goods_name'];
$deatillp_list1[$k]['goods_code'] = $g['sku'];
$deatillp_list1[$k]['pos_price'] = $g['market_price'];
}
$this->assign('deatillp_list1', $deatillp_list1); //礼品的
}
if ($deatillp_list2) {
foreach ($deatillp_list2 as $k => $v) {
$g = M("coupon")->where("id", $v['fromid'])->find();
$deatillp_list2[$k]['name'] = $g['name'];
$deatillp_list2[$k]['use_start_time'] = date("Y-m-d", $g['use_start_time']);
$deatillp_list2[$k]['use_end_time'] = date("Y-m-d", $g['use_end_time']);
$deatillp_list2[$k]['money'] = $g['money'];
$deatillp_list2[$k]['condition'] = $g['condition'];
switch ($g['type']) {
case 1:
$deatillp_list2[$k]['type'] = '免费发放';
break;
case 2:
$deatillp_list2[$k]['type'] = '注册发放';
break;
case 3:
$deatillp_list2[$k]['type'] = '邀请发放';
break;
case 5:
$deatillp_list2[$k]['type'] = '优惠活动';
break;
case 6:
$deatillp_list2[$k]['type'] = '包邮券';
$deatillp_list2[$k]['money'] = '无';
break;
case 7:
$deatillp_list2[$k]['type'] = '会员权益';
break;
case 8:
$deatillp_list2[$k]['type'] = '新人专享';
break;
case 9:
$deatillp_list2[$k]['type'] = 'PLUS专享';
break;
default:
break;
}
}
$this->assign('deatillp_list2', $deatillp_list2); //礼券的
}
if ($deatillp_list3) $this->assign('deatillp_list3', $deatillp_list3); //服务项目
} else {
$deatillp['exchange_type'] = 1;
}
$this->assign('deatillp', $deatillp);
$this->initEditor(); // 编辑器
return $this->fetch('', getAdmStoId());
}
//--- 礼包保存 ---
public function addMarketinglibaohand()
{
$parm = I("post.");
$stoid = getAdmStoId();
//-- 礼包类型的处理,要用逗号连接 --
$lb_type = ",";
if ($parm["lb_type1"]) {
$lb_type .= "1,";
unset($parm['lb_type1']);
}
if ($parm["lb_type2"]) {
$lb_type .= "2,";
unset($parm['lb_type2']);
}
if ($parm["lb_type3"]) {
$lb_type .= "3,";
unset($parm['lb_type3']);
}
if ($parm["lb_type4"]) {
$lb_type .= "4,";
unset($parm['lb_type4']);
}
if ($parm["lb_type5"]) {
$lb_type .= "5,";
unset($parm['lb_type5']);
}
if ($lb_type != ",") {
$parm["lb_type"] = $lb_type;
}
//-- input值 ---
$g_arr = $parm['grade_str'];
$p_arr = $parm['plustype_str'];
//-- checkbox值 ---
// $gs_arr= $parm["grade_state"];
// $ps_arr= $parm["plustype_state"];
$grade_str = "";
if ($g_arr) {
foreach ($g_arr as $k => $v) {
$val = $parm["grade_state" . ($k + 1)];
if ($val) {
$grade_str .= $v . ",";
}
}
if ($grade_str) $parm['grade'] = $grade_str;
}
$plus_str = "";
if ($p_arr) {
foreach ($p_arr as $k => $v) {
$val = $parm["plustype_state" . ($k + 1)];
if ($val) {
$plus_str .= $p_arr[$k] . ",";
}
}
if ($plus_str) $parm['plustype'] = $plus_str;
}
if ($parm["startime"]) $parm["startime"] = strtotime($parm["startime"]);
if ($parm["endtime"]) $parm["endtime"] = strtotime($parm["endtime"]);
if ($parm["exchange_starttime"])
$parm["exchange_starttime"] = strtotime($parm["exchange_starttime"]);
if ($parm["exchange_endtime"])
$parm["exchange_endtime"] = strtotime($parm["exchange_endtime"]);
//---如果有ID就是修改---
if ($parm['id']) {
$id = $parm['id'];
unset($parm['id']);
if ($parm['is_act']) $parm['is_act'] = 1;
$rs = M("marketing_libao_form")->where("id", $id)->update($parm);
$rs_str = M("marketing_libao_form")->where("id", $id)->fetchSql(true)->update($parm);
if ($rs !== false) {
M("marketing_libao_list")->where('lbid', $id)->delete();
$num = $parm['num'];
$list_arr = null;
foreach ($num as $k => $v) {
$in_data = null;
$in_data['lbid'] = $id;
$in_data['store_id'] = $stoid;
$in_data['billdate'] = time();
$in_data['lbtype'] = $parm['lbtype'][$k];
$in_data['fromid'] = $parm['fromid'][$k];
$in_data['num'] = $v;
$in_data['fw_name'] = "";
$in_data['fw_no'] = "";
if ($parm['fw_name'][$k]) $in_data['fw_name'] = $parm['fw_name'][$k];
if ($parm['fw_no'][$k]) $in_data['fw_no'] = $parm['fw_no'][$k];
$list_arr[] = $in_data;
}
if ($list_arr)
$rs = M("marketing_libao_list")->insertAll($list_arr);
$this->success("保存成功", U('Admin/Marketinglibao/index'));
}
} else {
$parm['store_id'] = $stoid;
$parm['addtime'] = time();
//--- 添加数据 ---
$rs = M("marketing_libao_form")->insertGetId($parm);
if ($rs) {
$num = $parm['num'];
$list_arr = null;
if ($num) {
foreach ($num as $k => $v) {
$in_data = null;
$in_data['lbid'] = $rs;
$in_data['store_id'] = $stoid;
$in_data['billdate'] = time();
$in_data['lbtype'] = $parm['lbtype'][$k];
$in_data['fromid'] = $parm['fromid'][$k];
$in_data['num'] = $v;
$in_data['fw_name'] = "";
$in_data['fw_no'] = "";
if ($parm['fw_name'][$k]) $in_data['fw_name'] = $parm['fw_name'][$k];
if ($parm['fw_no'][$k]) $in_data['fw_no'] = $parm['fw_no'][$k];
$list_arr[] = $in_data;
}
}
if ($list_arr)
$rs = M("marketing_libao_list")->insertAll($list_arr);
$this->success("保存成功", U('Admin/Marketinglibao/index'));
}
$this->error("保存失败");
}
}
//--- 礼包编辑器 ---
private function initEditor()
{
$this->assign("URL_upload", U('Admin/Ueditor/imageUp', array('savepath' => 'marketinglibao', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_fileUp", U('Admin/Ueditor/fileUp', array('savepath' => 'marketinglibao', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp', array('savepath' => 'marketinglibao', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage', array('savepath' => 'marketinglibao', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_imageManager", U('Admin/Ueditor/imageManager', array('savepath' => 'marketinglibao', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_imageUp", U('Admin/Ueditor/imageUp', array('savepath' => 'marketinglibao', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_getMovie", U('Admin/Ueditor/getMovie', array('savepath' => 'marketinglibao', 'savepath1' => strtolower(getERPId()))));
$this->assign("URL_Home", "");
}
/*--渲染商品,选中商品的代码--*/
function search()
{
$is_ajax = I("is_ajax");
if ($is_ajax) {
/*--访问接口选择商品--*/
$p = I('p/d', 1);
$key = trim(urldecode(I('key/s')));
if ($key) {
$where['goods_name|goods_sn|sku'] = array('like', '%' . $key . '%');
}
$t = time();
$where['store_id'] = getAdmStoId();
$rs = M('goods')->where($where)
->where("is_on_sale=1 and on_time<" . $t . " and (down_time>" . $t . " or down_time=0 or down_time='')")
->order('goods_id desc')->page("$p,20")->select();
if ($rs) {
$data['code'] = 1;
$data['msg'] = "获取商品列表成功";
$data['count'] = count($rs);
foreach ($rs as $k => $v) {
$data['data'][$k]['Id'] = $v['goods_id'];
$data['data'][$k]['WaresType'] = $v['is_virtual'] == 1 ? 2 : 0;
$data['data'][$k]['WareNo'] = $v['goods_sn'];
$data['data'][$k]['WareName'] = $v['goods_name'];
$data['data'][$k]['BarCode'] = $v['sku'];
$data['data'][$k]['PosPrice'] = number_format(empty($v['market_price']) ? 0 : $v['market_price'], 2, ".", "");
$data['data'][$k]['VipPrice'] = number_format(empty($v['shop_price']) ? 0 : $v['shop_price'], 2, ".", "");
}
return json($data);
} else {
return json(["code" => -1, "msg" => "无商品信息"]);
}
}
return $this->fetch('', getAdmStoId());
}
//服务项目查询
public function smitemlist()
{
$cur_page = I('p/d', 0);//当前页数
if ($cur_page <= 0) {
$cur_page = 1;
}
$this->assign('cur_page', $cur_page);
$keyword = I('keyword');
$pagenum = I('pagenum/d', 10);
$this->assign("pagenum", $pagenum);
$this->assign("keyword", $keyword);
return $this->fetch('', getAdmStoId());
}
//---服务项目查询----
public function ajax_smitem()
{
$stoid = getAdmStoId();
$sto = tpCache('shop_info', $stoid);//商户信息
$sto_erpid = $sto['ERPId'];
$keyword = I('keyword');
$getp = I('p/d', 1);
$PrivilegeId = I('PrivilegeId/s');
$pagenum = I('pagenum/d', 10);
$where = array();
$where["XZType"] = "SMItem";
if ($keyword != "") {
$where["XZName"] = urlencode($keyword);
}
$list = getApiData_java_p("/api/erp/grade/smitem/page", $sto_erpid, $where, $getp, $pagenum, null, "GET");
if ($list) {
$list = json_decode($list, true);
if ($list['code'] == 0) {
$count = $list['data']['total'];
$list = $list['data']['pageData'];
$Page = new AjaxPage($count, $pagenum);
$show = $Page->show();
$this->assign('page', $show);
$this->assign('pager', $Page);
$this->assign('count', $count);
$this->assign("list", $list);
}
}
return $this->fetch('', getAdmStoId());
}
public function dellibao()
{
$id = $this->request->param('id');
$return_arr = null;
if (empty($id)) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败,参数有误',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
$getadmstoid = getAdmStoId();
//判断是否新人有礼有用
$new_info = M('marketing_newpeople_gift')->where(array('store_id' => $getadmstoid, 'isdel' => 0, 'gifbagid' => $id))->find();
if ($new_info) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败,该礼包新人专享活动正在使用',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
//评价有礼
$commentsinfo = M('marketing_comments_reward')->where(array('store_id' => $getadmstoid, 'isdel' => 0, 'giftbagid' => $id))->find();
if ($commentsinfo) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败,该礼包评价有礼活动正在使用',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
//节日有礼
$commentsinfo = M('marketing_holiday_reward')->where(array('store_id' => $getadmstoid, 'isdel' => 0, 'giftbagid' => $id))->find();
if ($commentsinfo) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败,该礼包节日有礼活动正在使用',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
//生日有礼
$commentsinfo = M('marketing_birthday_reward')->where(array('store_id' => $getadmstoid, 'isdel' => 0, 'giftbagid' => $id))->find();
if ($commentsinfo) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败,该礼包生日有礼活动正在使用',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
//生日有礼
$commentsinfo = M('marketing_birthday_reward')->where(array('store_id' => $getadmstoid, 'isdel' => 0, 'giftbagid' => $id))->find();
if ($commentsinfo) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败,该礼包生日有礼活动正在使用',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
$commentsinfo = M('wxd_marketing_help_list')->alias('a')
->join('marketing_help_form b','a.store_id=b.store_id and a.help_id=b.id','left')
->where(array('a.store_id' => $getadmstoid, 'b.isdel' => 0, 'a.giftbagid' => $id))->find();
if ($commentsinfo) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败,该礼包助力有礼活动正在使用',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
$rs = M('marketing_libao_form')->where(array('store_id' => getAdmStoId(), 'id' => $id))->save(array('isdel' => 1));
if (empty($rs)) {
$return_arr = array(
'status' => 0,
'msg' => '删除失败',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
$return_arr = array(
'status' => 1,
'msg' => '操作成功',
'data' => array('url' => U('admin/Marketinglibao/index')),
);
$this->ajaxReturn($return_arr);
}
//购买礼包记录
public function salelist()
{
$pagenum = 20;//每页显示多少条
if ((int)I('pagenum/s') > 0) {
$pagenum = I('pagenum/s');
}
$p = I('p', 1);
$start_time = I('add_time_begin');
$end_time = I('add_time_end');
$begin = $this->begin;
$end = $this->end;
if (empty($start_time)) {
$lastweek = date('Y-m-d', strtotime("-1 month"));//30天前
$start_time = $lastweek . ' 00:00:00';
}
if (empty($end_time)) {
$end_time = I('end', date('Y-m-d')) . ' 23:59:59';
}
$this->assign('start_time', $start_time);
$this->assign('end_time', $end_time);
$mobile = I('mobile');//手机号码
$order_sn = I('order_sn');//手机号码
$lbid = I('lbid');//礼包ID
$this->assign('lbid', $lbid);
$keyword = I('keyword');//关键字
if (empty($keyword)) $keyword = $mobile;
$getisend = I('act_id');
$where = " a.store_id=" . getAdmStoId();
if ($keyword) {
$where .= " and (c.mobile='" . $keyword . "' or c.nickname like '%" . $keyword . "%') ";
}
if ($lbid) {
$where .= " and a.lb_id=" . $lbid;
}
if ($start_time) {
$start_time = urldecode($start_time);
$where .= " and a.addtime>=" . strtotime($start_time);
}
if ($end_time) {
$end_time = urldecode($end_time);
$where .= " and a.addtime<=" . strtotime($end_time);
}
$where .= " and a.act_type=0"; // 只查礼包
$lbtype = I('lbtype');
if ($lbtype != "") {
$where .= " and b.lbtype=" . $lbtype;
}
$paytype = I('paytype');
$paytypes = intval($paytype);
switch ($paytypes) {
case 3: //未付款
$where .= " and pay_state=0 && pay_type=2";
break;
case 1: //积分兑换
$where .= " and a.pay_state=1 and a.pay_type=2 and a.pay_integral <> ''";
break;
case 2: //微支付
$where .= " and a.pay_state=1 and a.pay_type=2 ";
break;
}
$qdrecord = M('marketing_user_buyreceive_form');
$count = $qdrecord->alias('a')
->join('marketing_libao_form b', ' a.lb_id=b.id', 'left')
->join('(select nickname,vipname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', ' a.user_id=c.user_id', 'left')
->where($where)
->count();
$Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数
$redmoneylist = $qdrecord->alias('a')
->join('marketing_libao_form b', ' a.lb_id=b.id', 'left')
->join('(select nickname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', ' a.user_id=c.user_id ', 'left')
->where($where)
->limit($Page->firstRow . ',' . $Page->listRows)
->order('a.addtime desc')
->field('a.*,c.nickname,c.mobile,b.lb_type,b.lbtitle')
->select();// 查询满足要求的总记录数
$redmoneylist_s = $qdrecord->alias('a')
->join('marketing_libao_form b', ' a.lb_id=b.id', 'left')
->join('(select nickname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', ' a.user_id=c.user_id ', 'left')
->where($where)
->limit($Page->firstRow . ',' . $Page->listRows)
->order('a.addtime desc')
->field('a.*,c.nickname,c.mobile,b.lb_type,b.lbtitle')
->fetchSql(true)
->select();// 查询满足要求的总记录数
$lblist = M('marketing_libao_form')->where('store_id=' . getAdmStoId())->select();
$show = $Page->show();
$this->assign('page', $show);
$this->assign('total', $count);
$this->assign('lblist', $lblist);
$this->assign('p', $p - 1);
$this->assign('order_sn', $order_sn);
$this->assign('lbtype', $lbtype);
$this->assign('paytype', $paytype);
$this->assign('keyword', $keyword);
$this->assign('redmoneylist', $redmoneylist);
$this->assign('pagenum', $pagenum);
$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 export_salelist()
{
$begin = I('add_time_begin');
$end = I('add_time_end');
$this->assign('start_time', $begin);
$this->assign('end_time', $end);
$mobile = I('mobile');//手机号码
$order_sn = I('order_sn');//手机号码
$lbid = I('lbid');//礼包ID
$this->assign('lbid', $lbid);
$keyword = I('keyword');//关键字
$where = " a.store_id=" . getAdmStoId();
if ($keyword) {
$where .= " and (c.mobile='" . $keyword . "' or c.nickname like '%" . $keyword . "%') ";
}
if ($lbid) {
$where .= " and a.lb_id=" . $lbid;
}
if ($begin) {
$where .= " and a.addtime>=" . strtotime($begin);
}
if ($end) {
$where .= " and a.addtime<=" . strtotime($end);
}
$paytype = I('paytype');
switch ($paytype) {
//未付款
case 3:
$condition['pay_state'] = 0;
break;
//积分兑换
case 1:
$where .= " and a.pay_state=1 and a.pay_type=1 ";
break;
//微支付
case 2:
$where .= " and a.pay_state=1 and a.pay_type=2 ";
break;
}
$qdrecord = M('marketing_user_buyreceive_form');
$redmoneylist = $qdrecord->alias('a')
->join('marketing_libao_form b', ' a.lb_id=b.id', 'left')
->join('(select nickname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', ' a.user_id=c.user_id', 'left')
->where($where)
->where($condition)
->order('a.addtime desc')
->field('a.*,c.nickname,c.mobile,b.lb_type,b.lbtitle')
->select();// 查询满足要求的总记录数
$strTable = '<table border="1">';
$strTable .= '<tr style="font-weight: bold;">';
$strTable .= '<td style="text-align:center;width:50px;">序号</td>';
$strTable .= '<td style="text-align:center;" width="200">礼包名称</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="100">手机号</td>';
$strTable .= '<td style="text-align:center;" width="150">购买时间</td>';
$strTable .= '</tr>';
if (is_array($redmoneylist)) {
foreach ($redmoneylist as $k => $val) {
$strTable .= '<tr>';
$strTable .= '<td style="text-align:left;"> ' . ($k + 1) . '</td>';
$strTable .= '<td style="text-align:left;">' . $val['lbtitle'] . ' </td>';
$type = "";
if (stripos($val[lb_type], ',1,') !== false) $type .= "礼品";
if (stripos($val[lb_type], ',2,') !== false) $type .= " 优惠券";
if (stripos($val[lb_type], ',3,') !== false) $type .= " 服务项目";
if (stripos($val[lb_type], ',4,') !== false) $type .= " 积分";
if (stripos($val[lb_type], ',5,') !== false) $type .= " 成长值";
$strTable .= '<td style="text-align:center;">' . $type . '</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()
{
//echo "1"; exit;
$lbvipid = I('id');
//礼包购买数量
$by = M('marketing_user_buyreceive_form')
->alias('a')
->where('a.id=' . $lbvipid)
->find();
//礼包
$libao = M("marketing_libao_form")->where("id", $by['lb_id'])->find();
$list = M('marketing_libao_list')->where("lbid", $by['lb_id'])->order("lbtype")->select();
foreach ($list as $k => $v) {
//$libao['lbtype']=$v['lbtype'];
if ($v['lbtype'] == 1) {
$g = M("goods")->where("goods_id", $v['fromid'])->find();
$list[$k]['goods_sn'] = $g['goods_sn'];
$list[$k]['goods_name'] = $g['goods_name'];
$list[$k]['goods_code'] = $g['sku'];
$list[$k]['pos_price'] = $g['market_price'];
}
if ($v['lbtype'] == 2) {
$g = M("coupon")->where("id", $v['fromid'])->find();
$list[$k]['name'] = $g['name'];
$list[$k]['use_start_time'] = date("Y-m-d", $g['use_start_time']);
$list[$k]['use_end_time'] = date("Y-m-d", $g['use_end_time']);
$list[$k]['money'] = $g['money'];
$list[$k]['condition'] = $g['condition'];
switch ($g['type']) {
case 1:
$list[$k]['type'] = '免费发放';
break;
case 2:
$list[$k]['type'] = '注册发放';
break;
case 3:
$list[$k]['type'] = '邀请发放';
break;
case 5:
$list[$k]['type'] = '优惠活动';
break;
case 6:
$list[$k]['type'] = '包邮券';
$list[$k]['money'] = "无";
break;
case 7:
$list[$k]['type'] = '会员权益';
break;
case 8:
$list[$k]['type'] = '新人专享';
break;
case 9:
$list[$k]['type'] = 'PLUS专享';
break;
default:
break;
}
}
}
$this->assign('lbtype', $libao['lbtype']);
$this->assign('isget', $by['pay_state']);
$this->assign('list', $list);
return $this->fetch('', getAdmStoId());
}
/*--渲染优惠券--*/
function getCp()
{
return $this->fetch('searchcp', getAdmStoId());
}
/*--访问接口选择优惠券--*/
public function SelectCp()
{
$p = I('p/d', 1);
$key = trim(urldecode(I('key/s')));
if ($key) {
$where['name|money|condition'] = array('like', '%' . $key . '%');
}
$where['store_id'] = array('=', getAdmStoId());
$cptype = I('coupontype');
$w = " and ((endtype=0 and (use_end_time>" . time() . " or use_end_time=0)) or endtype=1)";
$w .= " and send_end_time>" . time();
if ($cptype) {
$where['type'] = array('=', $cptype);
}
$count = M('coupon')->where($where)->where('(type=5 or type=6) ' . $w)->count();
$Page = new Page($count, 10);
$show = $Page->show();
$data = M('coupon')->where($where)->where('(type=5 or type=6) ' . $w)
->order('add_time desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
mlog(json_encode($data, true) . ' 记录数:' . $count . '页面:' . $Page->firstRow . ',' . $Page->listRows . ' 条件:' . json_encode($where), "lbcp/" . getAdmStoId());
// upload_ylp_log('商品选择');
if ($data) {
foreach ($data as $k => $v) {
$data[$k]['use_end_time'] = date('Y-m-d H:i:s', $v['use_end_time']);
$data[$k]['use_start_time'] = date('Y-m-d H:i:s', $v['use_start_time']);
switch ($v['type']) {
case 1:
$data[$k]['type'] = '免费发放';
break;
case 2:
$data[$k]['type'] = '注册发放';
break;
case 3:
$data[$k]['type'] = '邀请发放';
break;
case 5:
$data[$k]['type'] = '优惠活动';
break;
case 6:
$data[$k]['type'] = '包邮券';
$data[$k]['money'] = '无';
break;
default:
break;
}
}
return json(['code' => 1, "data" => $data, 'msg' => '数据获取成功', 'count' => $count]);
} else {
return json(["code" => -1, "msg" => "未找到您要搜索的优惠券"]);
}
}
}