MarketingController.class.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class MarketingController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. public function index()
  20. {
  21. $this->user();
  22. }
  23. public function points()
  24. {
  25. $_GPC = I('request.');
  26. if (IS_POST) {
  27. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  28. D('Seller/Config')->update($data);
  29. show_json(1);
  30. }
  31. $data = D('Seller/Config')->get_all_config();
  32. $this->data = $data;
  33. $this->display();
  34. }
  35. public function coupon()
  36. {
  37. $_GPC = I('request.');
  38. $this->gpc = $_GPC;
  39. $pindex = max(1, intval($_GPC['page']));
  40. $psize = 20;
  41. $condition = ' 1 ';
  42. $params = array(':uniacid' => $_W['uniacid']);
  43. if (!empty($_GPC['keyword'])) {
  44. $_GPC['keyword'] = trim($_GPC['keyword']);
  45. $condition .= ' AND voucher_title LIKE "%'.$_GPC['keyword'].'%"';
  46. }
  47. if (!empty($_GPC['catid'])) {
  48. $_GPC['catid'] = trim($_GPC['catid']);
  49. $condition .= ' AND catid = '. $_GPC['catid'];
  50. }
  51. if (empty($starttime) || empty($endtime)) {
  52. $starttime = strtotime('-1 month');
  53. $endtime = time();
  54. }
  55. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  56. $starttime = strtotime($_GPC['time']['start']);
  57. $endtime = strtotime($_GPC['time']['end']);
  58. $this->starttime = $starttime;
  59. $this->endtime = $endtime;
  60. if (!empty($starttime)) {
  61. $condition .= ' AND add_time >= '.$starttime;
  62. }
  63. if (!empty($endtime)) {
  64. $condition .= ' AND add_time <= '.$endtime;
  65. }
  66. }
  67. if ($_GPC['gettype'] != '') {
  68. $condition .= ' AND is_index_show = '.intval($_GPC['gettype']);
  69. }
  70. if ($_GPC['type'] != '') {
  71. // $condition .= ' AND coupontype = '.intval($_GPC['type']);
  72. }
  73. $sql = 'SELECT * FROM ' . C('DB_PREFIX') . 'lionfish_comshop_coupon ' . ' where 1 and ' . $condition . ' ORDER BY displayorder DESC,id DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  74. $list = M()->query($sql);
  75. foreach ($list as &$row) {
  76. $send_count = M('lionfish_comshop_coupon_list')->where( array('voucher_id' => $row['id'] ) )->count();
  77. $usetotal = M('lionfish_comshop_coupon_list')->where( array('voucher_id' => $row['id'], 'consume' => 'Y') )->count();
  78. $row['usetotal'] = $usetotal;
  79. $row['send_count'] = $send_count;
  80. //usetotal
  81. }
  82. unset($row);
  83. $total_arr = M()->query('SELECT COUNT(*) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon where 1 and ' . $condition);
  84. $total = $total_arr[0]['count'];
  85. $pager = pagination2($total, $pindex, $psize);
  86. $category_arr = M()->query('select * from ' . C('DB_PREFIX') . 'lionfish_comshop_coupon_category order by id desc');
  87. $category = array();
  88. foreach($category_arr as $vv)
  89. {
  90. $category[$vv['id']] = $vv['name'];
  91. }
  92. $this->list = $list;
  93. $this->pager = $pager;
  94. $this->category = $category;
  95. $this->display();
  96. }
  97. public function couponsend()
  98. {
  99. $_GPC = I('request.');
  100. $where = "";
  101. $where = " and (total_count=-1 or total_count>send_count) and (end_time>".time()." or timelimit =0 ) ";
  102. $quan_list = M()->query("select * from ".C('DB_PREFIX').
  103. "lionfish_comshop_coupon where 1 {$where} order by displayorder desc ,id asc limit 1000 ");
  104. $membercount = M('lionfish_comshop_member')->where( array('groupid' => 0 ) )->count();
  105. $list = array(
  106. array('id' => 'default', 'groupname' => '默认分组', 'membercount' => $membercount )
  107. );
  108. $condition = ' ';
  109. $alllist = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member_group WHERE 1 ' . $condition . ' ORDER BY id asc' );
  110. foreach ($alllist as &$row ) {
  111. $row['membercount'] = M('lionfish_comshop_member')->where("find_in_set(".$row['id'].",groupid)")->count();
  112. }
  113. $list = array_merge($list, $alllist);
  114. $this->quan_list = $quan_list;
  115. $this->list = $list;
  116. $this->membercount = $membercount;
  117. include $this->display();
  118. }
  119. public function send()
  120. {
  121. $_GPC = I('request.');
  122. $where = "";
  123. $where = " and (total_count=-1 or total_count>send_count) and (end_time>".time()." or timelimit =0 ) ";
  124. $quan_list = M()->query("select * from ".C('DB_PREFIX').
  125. "lionfish_comshop_coupon where 1 {$where} order by displayorder desc ,id asc limit 1000 ");
  126. $membercount = M('lionfish_comshop_member')->where( array('groupid' => 0 ) )->count();
  127. $list = array(
  128. array('id' => 'default', 'groupname' => '默认分组', 'membercount' => $membercount )
  129. );
  130. $condition = ' ';
  131. $alllist = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member_group WHERE 1 ' . $condition . ' ORDER BY id asc' );
  132. foreach ($alllist as &$row ) {
  133. $row['membercount'] = M('lionfish_comshop_member')->where("find_in_set(".$row['id'].",groupid)")->count();
  134. }
  135. $list = array_merge($list, $alllist);
  136. $this->quan_list = $quan_list;
  137. $this->list = $list;
  138. $this->membercount = $membercount;
  139. include $this->display('Marketing/couponsend');
  140. }
  141. public function couponsend_do()
  142. {
  143. $_GPC = I('request.');
  144. $voucher_id = $_GPC['voucher_id'];
  145. $send_count = $_GPC['send_count'];
  146. $send_person = $_GPC['send_person'];
  147. $member_group_id = $_GPC['member_group_id'];
  148. $limit_user_list = $_GPC['limit_user_list'];
  149. $cache_key = md5(time().$voucher_id.$send_person);
  150. $ids_arr = array();
  151. if( $send_person == 1)
  152. {
  153. //送给部分人
  154. $ids_arr = explode(',', $limit_user_list);
  155. }else if( $send_person == 2 )
  156. {
  157. //送给分组
  158. $member_group_id = $member_group_id == 'default' ? 0 : $member_group_id;
  159. $mb_list = M('lionfish_comshop_member')->field('member_id')->where( array('groupid' => $member_group_id ) )->select();
  160. foreach( $mb_list as $val )
  161. {
  162. $ids_arr[] = $val['member_id'];
  163. }
  164. }else if( $send_person == 3 ){
  165. //送给所有人
  166. $mb_list = M()->query("select member_id from ".C('DB_PREFIX')."lionfish_comshop_member where 1 " );
  167. foreach( $mb_list as $val )
  168. {
  169. $ids_arr[] = $val['member_id'];
  170. }
  171. }
  172. S('_send_quan_'.$cache_key, $ids_arr);
  173. $this->cache_key = $cache_key;
  174. $this->voucher_id = $voucher_id;
  175. $this->send_count = $send_count;
  176. $this->send_person = $send_person;
  177. $this->member_group_id = $member_group_id;
  178. $this->limit_user_list = $limit_user_list;
  179. include $this->display();
  180. }
  181. public function do_coupon_quene()
  182. {
  183. $_GPC = I('request.');
  184. $voucher_id = $_GPC['voucher_id'];
  185. $send_count = $_GPC['send_count'];
  186. $cache_key = $_GPC['cache_key'];
  187. $quene_order_list = S('_send_quan_'.$cache_key);
  188. $member_id = array_shift($quene_order_list);
  189. S('_send_quan_'.$cache_key, $quene_order_list);
  190. $error_msg = "";
  191. //send quan
  192. for( $i =0; $i< $send_count; $i++ )
  193. {
  194. $res = D('Home/Voucher')->send_user_voucher_byId($voucher_id,$member_id,false, true );
  195. //int(4)
  196. if( $res == 1 )
  197. {
  198. $error_msg .= '(券id:'.$voucher_id.' 已送光)';
  199. }
  200. }
  201. if( empty($quene_order_list) )
  202. {
  203. echo json_encode( array('code' => 2) );
  204. die();
  205. }
  206. echo json_encode( array('code' => 0, 'msg' => '会员id:'.$member_id." 处理成功{$error_msg},还剩余".count($quene_order_list)."个会员未处理") );
  207. die();
  208. }
  209. public function change()
  210. {
  211. $_GPC = I('request.');
  212. $id = intval($_GPC['id']);
  213. //ids
  214. if (empty($id)) {
  215. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  216. }
  217. if (empty($id)) {
  218. show_json(0, array('message' => '参数错误'));
  219. }
  220. $type = trim($_GPC['type']);
  221. $value = trim($_GPC['value']);
  222. if (!(in_array($type, array('is_index_show', 'displayorder','is_index_alert')))) {
  223. show_json(0, array('message' => '参数错误'));
  224. }
  225. $coupon_collection_method = array();
  226. /*if($type == 'is_index_show' && $value == 0 ){
  227. $coupon_collection_method = array(
  228. "is_index_show" => "0" ,
  229. "is_index_alert" => "1"
  230. );
  231. }else{
  232. $coupon_collection_method = array(
  233. "is_index_show" => "1" ,
  234. "is_index_alert" => "0"
  235. );
  236. }*/
  237. if($type == 'is_index_show'){
  238. $coupon_collection_method = array("is_index_show" => $value);
  239. }else if($type == 'is_index_alert'){
  240. $coupon_collection_method = array("is_index_alert" => $value);
  241. }
  242. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX') . 'lionfish_comshop_coupon WHERE id in( ' . $id . ' ) ' );
  243. foreach ($items as $item) {
  244. M('lionfish_comshop_coupon')->where( array('id' => $item['id']) )->save( $coupon_collection_method );
  245. }
  246. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  247. }
  248. public function seckill()
  249. {
  250. $_GPC = I('request.');
  251. if ( IS_POST ) {
  252. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  253. $scekill_show_time_arr = $_GPC['scekill_show_time'];
  254. if( !empty($scekill_show_time_arr) )
  255. {
  256. $data['scekill_show_time'] = serialize($scekill_show_time_arr);
  257. }
  258. D('Seller/Config')->update($data);
  259. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  260. }
  261. $data = D('Seller/Config')->get_all_config();
  262. if( isset($data['scekill_show_time']) && !empty($data['scekill_show_time']) )
  263. {
  264. $data['scekill_show_time_arr'] = unserialize($data['scekill_show_time']);
  265. }
  266. $this->data = $data;
  267. $this->display();
  268. }
  269. public function photoadv()
  270. {
  271. $_GPC = I('request.');
  272. if ( IS_POST ) {
  273. $data = $_GPC['data'];
  274. if($data['type']==3 || $data['type']==4){
  275. $data['photoadv_link'] = $data['photoadv_cid'];
  276. }
  277. D('Seller/Config')->update($data);
  278. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  279. }
  280. $data = D('Seller/Config')->get_all_config();
  281. $this->data = $data;
  282. $category = D('Seller/GoodsCategory')->getFullCategory(false, true);
  283. $this->category = $category;
  284. $this->display();
  285. }
  286. public function explain()
  287. {
  288. $_GPC = I('request.');
  289. if (IS_POST) {
  290. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  291. D('Seller/Config')->update($data);
  292. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  293. }
  294. $data = D('Seller/Config')->get_all_config();
  295. $this->data = $data;
  296. $this->display();
  297. }
  298. //logcoupon&couponid=3
  299. public function logcoupon()
  300. {
  301. $_GPC = I('request.');
  302. $this->gpc = $_GPC;
  303. $pindex = max(1, intval($_GPC['page']));
  304. $psize = 20;
  305. $condition = ' 1 ';
  306. $couponid = intval($_GPC['couponid']);
  307. if (!empty($couponid)) {
  308. $coupon = M('lionfish_comshop_coupon')->where( array('id' => $couponid ) )->find();
  309. $this->coupon = $coupon;
  310. $condition .= ' AND c.voucher_id=' . intval($couponid);
  311. }
  312. $searchfield = strtolower(trim($_GPC['searchfield']));
  313. $keyword = trim($_GPC['keyword']);
  314. if (!empty($searchfield) && !empty($keyword)) {
  315. if ($searchfield == 'member') {
  316. $condition .= ' and ( m.realname like "%'.$keyword.'%" or m.nickname like "%'.$keyword.'%" or m.mobile like "%'.$keyword.'%" )';
  317. }
  318. else {
  319. if ($searchfield == 'coupon') {
  320. $condition .= ' and c.voucher_title like "%'.$keyword.'%" ';
  321. }
  322. }
  323. }
  324. if (empty($starttime) || empty($endtime)) {
  325. $starttime = strtotime('-1 month');
  326. $endtime = time();
  327. }
  328. if (empty($starttime1) || empty($endtime1)) {
  329. $starttime1 = strtotime('-1 month');
  330. $endtime1 = time();
  331. }
  332. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  333. $starttime = strtotime($_GPC['time']['start']);
  334. $endtime = strtotime($_GPC['time']['end']);
  335. $this->starttime = $starttime;
  336. $this->endtime = $endtime;
  337. $condition .= ' AND c.add_time >= '.$starttime.' AND c.add_time <= '.$endtime;
  338. }
  339. if (!empty($_GPC['time1']['start']) && !empty($_GPC['time1']['end'])) {
  340. $starttime1 = strtotime($_GPC['time1']['start']);
  341. $endtime1 = strtotime($_GPC['time1']['end']);
  342. $this->starttime1 = $starttime1;
  343. $this->endtime1 = $endtime1;
  344. $condition .= ' AND c.usetime >= '.$starttime1.' AND c.add_time <= '.$endtime1;
  345. }
  346. if ($_GPC['type'] != '') {
  347. $condition .= ' AND c.coupontype = '.intval($_GPC['type']);
  348. }
  349. if ($_GPC['used'] != '') {
  350. $condition .= ' AND c.consume = "' . trim($_GPC['used']).'" ';
  351. }
  352. if ($_GPC['gettype'] != '') {
  353. $condition .= ' AND c.gettype ='.intval($_GPC['gettype']);
  354. }
  355. $sql = 'SELECT c.*,m.username,m.avatar,m.openid,m.telephone FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon_list c ' .
  356. ' left join ' . C('DB_PREFIX'). 'lionfish_comshop_member m on m.member_id = c.user_id ' . ' where 1 and ' . $condition . ' ORDER BY c.add_time DESC';
  357. if (empty($_GPC['export'])) {
  358. $sql .= ' LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  359. }
  360. $list = M()->query($sql);
  361. foreach ($list as &$row) {
  362. $couponstr = '消费';
  363. $row['couponstr'] = $couponstr;
  364. if ($row['gettype'] == 0) {
  365. $row['gettypestr'] = '后台发放';
  366. }
  367. else if ($row['gettype'] == 1) {
  368. $row['gettypestr'] = '首页领取';
  369. }
  370. else if ($row['gettype'] == 2) {
  371. $row['gettypestr'] = '积分商城';
  372. }
  373. else if ($row['gettype'] == 14) {
  374. $row['gettypestr'] = '新人领券';
  375. }
  376. else {
  377. if ($row['gettype'] == 15) {
  378. $row['gettypestr'] = '发券分享';
  379. }
  380. }
  381. }
  382. unset($row);
  383. if ($_GPC['export'] == 1) {
  384. foreach ($list as &$row) {
  385. $row['gettime'] = date('Y-m-d H:i', $row['add_time']);
  386. if (!empty($row['usetime'])) {
  387. $row['usetime'] = date('Y-m-d H:i', $row['usetime']);
  388. }
  389. else {
  390. $row['usetime'] = '---';
  391. }
  392. }
  393. $columns = array(
  394. array('title' => 'ID', 'field' => 'id', 'width' => 12),
  395. array('title' => '优惠券', 'field' => 'voucher_title', 'width' => 24),
  396. array('title' => '类型', 'field' => 'couponstr', 'width' => 12),
  397. array('title' => '会员信息', 'field' => 'username', 'width' => 12),
  398. array('title' => '姓名', 'field' => 'realname', 'width' => 12),
  399. array('title' => '手机号', 'field' => 'telephone', 'width' => 12),
  400. array('title' => 'openid', 'field' => 'openid', 'width' => 24),
  401. array('title' => '获取方式', 'field' => 'gettypestr', 'width' => 12),
  402. array('title' => '获取时间', 'field' => 'gettime', 'width' => 12),
  403. array('title' => '使用时间', 'field' => 'usetime', 'width' => 12),
  404. array('title' => '使用单号', 'field' => 'ordersn', 'width' => 12)
  405. );
  406. D('Seller/Excel')->export($list, array('title' => '优惠券数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  407. //m('excel')->export($list, array('title' => '优惠券数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  408. //plog('sale.coupon.log.export', '导出优惠券发放记录');
  409. }
  410. $total_arr = M()->query('SELECT COUNT(*) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon_list c ' . ' left join ' . C('DB_PREFIX') . 'lionfish_comshop_member m on m.member_id = c.user_id ' . 'where 1 and ' . $condition);
  411. $total = $total_arr[0]['count'];
  412. $pager = pagination2($total, $pindex, $psize);
  413. $this->list = $list;
  414. $this->pager = $pager;
  415. $this->display();
  416. }
  417. public function recharge_diary()
  418. {
  419. $_GPC = I('request.');
  420. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  421. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  422. $keyword = I('get.keyword','','addslashes');
  423. $keyword2 = stripslashes($keyword);
  424. $this->keyword = $keyword2;
  425. $state = $_GPC['state'];
  426. $this->starttime = $starttime;
  427. $this->endtime = $endtime;
  428. $this->state = $state;
  429. $condition = ' ';
  430. if( !empty($state) && $state > 0 )
  431. {
  432. $condition .= " and cf.state ={$state} ";
  433. }else{
  434. $condition .= " and cf.state <> 0 ";
  435. }
  436. if( isset($_GPC['time']) )
  437. {
  438. if($_GPC['time']['start'])
  439. {
  440. $condition .= " and cf.add_time >= {$starttime} ";
  441. }
  442. if($_GPC['time']['end'])
  443. {
  444. $condition .= " and cf.add_time <= {$endtime} ";
  445. }
  446. }
  447. if( !empty($keyword) )
  448. {
  449. $condition .= " and m.username like '%{$keyword}%' ";
  450. }
  451. $pindex = max(1, intval($_GPC['page']));
  452. $psize = 20;
  453. $sql = "select cf.* ,m.username,m.avatar from ".C('DB_PREFIX')."lionfish_comshop_member_charge_flow as cf , ".C('DB_PREFIX')."lionfish_comshop_member as m
  454. where cf.member_id = m.member_id {$condition} order by cf.id desc limit ". (($pindex - 1) * $psize) . ',' . $psize;
  455. $sql_count = "select count(1) as count from ".C('DB_PREFIX')."lionfish_comshop_member_charge_flow as cf , ".C('DB_PREFIX')."lionfish_comshop_member as m
  456. where cf.member_id = m.member_id {$condition} ";
  457. $list = M()->query($sql);
  458. $total_arr = M()->query($sql_count );
  459. $total = $total_arr[0]['count'];
  460. foreach( $list as $key => $val )
  461. {
  462. $val['add_time'] = date('Y-m-d H:i:s',$val['add_time'] );
  463. $val['trans_id'] = '-';
  464. if($val['state'] == 3 || $val['state'] == 4)
  465. {
  466. $od_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['trans_id'] ) )->find();
  467. if( !empty($od_info) )
  468. {
  469. $val['trans_id'] = $od_info['order_num_alias'];
  470. }
  471. }
  472. $list[$key] = $val;
  473. }
  474. $pager = pagination2($total, $pindex, $psize);
  475. $all_count = M('lionfish_comshop_member_charge_flow')->where( "state != 0" )->count();
  476. $count_status_1 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 1) )->count();
  477. $count_status_3 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 3) )->count();
  478. $count_status_4 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 4) )->count();
  479. $count_status_5 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 5) )->count();
  480. $count_status_8 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 8) )->count();
  481. $count_status_9 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 9) )->count();
  482. $count_status_10 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 10) )->count();
  483. $this->list = $list;
  484. $this->pager = $pager;
  485. $this->all_count = $all_count;
  486. $this->count_status_1 = $count_status_1;
  487. $this->count_status_3 = $count_status_3;
  488. $this->count_status_4 = $count_status_4;
  489. $this->count_status_5 = $count_status_5;
  490. $this->count_status_8 = $count_status_8;
  491. $this->count_status_9 = $count_status_9;
  492. $this->count_status_10 = $count_status_10;
  493. $this->display();
  494. }
  495. public function displayordercoupon()
  496. {
  497. $_GPC = I('request.');
  498. $id = intval($_GPC['id']);
  499. if (empty($id)) {
  500. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  501. }
  502. $displayorder = intval($_GPC['value']);
  503. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon WHERE id in( ' . $id . ' ) ' );
  504. foreach ($items as $item) {
  505. M('lionfish_comshop_coupon')->where( array('id' => $id) )->save( array('displayorder' => $displayorder) );
  506. }
  507. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  508. }
  509. public function addcoupon()
  510. {
  511. $_GPC = I('request.');
  512. $id = intval($_GPC['id']);
  513. if (IS_POST) {
  514. if(empty($_GPC['displayorder'])){
  515. show_json(0, array('message' => '排序必须填写'));
  516. }
  517. if(!is_numeric($_GPC['displayorder'])){
  518. show_json(0, array('message' => '排序必须在1-999之间的整数'));
  519. }
  520. if(floor($_GPC['displayorder']) != $_GPC['displayorder']){
  521. show_json(0, array('message' => '排序必须在1-999之间的整数'));
  522. }
  523. if($_GPC['displayorder'] < 1 || $_GPC['displayorder'] > 999){
  524. show_json(0, array('message' => '排序必须在1-999之间的整数'));
  525. }
  526. if(empty($_GPC['voucher_title'])){
  527. show_json(0, array('message' => '优惠券名称必须填写'));
  528. }
  529. if(empty($_GPC['catid'])){
  530. show_json(0, array('message' => '分类必须选择'));
  531. }
  532. if(!empty($_GPC['limit_money']) && $_GPC['limit_money'] != 0 ){
  533. if($_GPC['credit'] > $_GPC['limit_money']){
  534. show_json(0, array('message' => '立减金额应小于等于使用条件金额'));
  535. }
  536. }
  537. $data = array();
  538. $data['catid'] = $_GPC['catid'];
  539. $data['voucher_title'] = $_GPC['voucher_title'];
  540. $data['thumb'] = $_GPC['thumb'];
  541. $data['credit'] = $_GPC['credit'];
  542. $data['type'] = 1;
  543. /*if(empty($_GPC['coupon_collection_method'])){
  544. $data['is_index_show'] = 0;
  545. $data['is_index_alert'] =1;
  546. }else{
  547. $data['is_index_show'] = 1;
  548. $data['is_index_alert'] =0;
  549. }*/
  550. $data['is_index_show'] = $_GPC['is_index_show'];
  551. $data['is_index_alert'] = $_GPC['is_index_alert'];
  552. $data['is_share_doubling'] = 0;
  553. $data['get_over_hour'] = $_GPC['get_over_hour'] * 24;
  554. $data['is_limit_goods_buy'] = $_GPC['is_limit_goodsbuy'];
  555. $data['is_new_man'] = $_GPC['is_new_man'];
  556. $data['share_title'] = '';
  557. $data['share_desc'] = '';
  558. $data['share_logo'] = '';
  559. $data['timelimit'] = $_GPC['timelimit'];
  560. $data['person_limit_count'] = $_GPC['person_limit_count'];
  561. $data['limit_goods_list'] = $_GPC['limit_goods_list'];
  562. $data['goodscates'] = $_GPC['goodscates'];
  563. $data['limit_money'] = $_GPC['limit_money'];
  564. $data['total_count'] = $_GPC['total_count'];
  565. $data['send_count'] = $_GPC['send_count'];
  566. $data['add_time'] = time();
  567. $data['displayorder'] = $_GPC['displayorder'];
  568. $data['begin_time'] = strtotime($_GPC['time']['start']);
  569. $data['end_time'] = strtotime($_GPC['time']['end']) + 86399;
  570. if($id > 0)
  571. {
  572. M('lionfish_comshop_coupon')->where( array('id' => $id) )->save( $data );
  573. }else{
  574. M('lionfish_comshop_coupon')->add($data);
  575. }
  576. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  577. }
  578. $category = M()->query('select * from ' . C('DB_PREFIX'). 'lionfish_comshop_coupon_category where merchid=0 order by id desc');
  579. $goods_category = D('Seller/GoodsCategory')->getFullCategory(true, true);
  580. $this->goods_category = $goods_category;
  581. $new_category = array();
  582. foreach($category as $key =>$val)
  583. {
  584. $new_category[$val['id']] = $val;
  585. }
  586. $this->category = $new_category;
  587. if (empty($id)) {
  588. $starttime = time();
  589. $endtime = strtotime(date('Y-m-d H:i:s', $starttime) . '+7 days');
  590. }else{
  591. $item = M('lionfish_comshop_coupon')->where( array('id' => $id) )->find();
  592. $item['get_over_hour'] = $item['get_over_hour'] / 24;
  593. $starttime = $item['begin_time'];
  594. $endtime = $item['end_time'];
  595. $limit_goods = array();
  596. if( !empty($item['limit_goods_list']) )
  597. {
  598. $limit_goods = M('lionfish_comshop_goods')->field('id as gid,goodsname,subtitle')->where('id in('.$item['limit_goods_list'].')')->order('id desc')->select();
  599. foreach($limit_goods as $kk => $vv)
  600. {
  601. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $vv['gid'] ) )->order('id asc')->find();
  602. $vv['image'] = tomedia($thumb['image']);
  603. $limit_goods[$kk] = $vv;
  604. }
  605. }
  606. if($item['is_index_show'] == 0 && $item['is_index_alert'] == 1){
  607. $item['coupon_collection_method']=0;
  608. }else{
  609. $item['coupon_collection_method']=1;
  610. }
  611. $this->limit_goods = $limit_goods;
  612. $this->item = $item;
  613. }
  614. $this->starttime = $starttime;
  615. $this->endtime = $endtime;
  616. $this->display();
  617. }
  618. public function fullreduction()
  619. {
  620. $_GPC = I('request.');
  621. $this->gpc = $_GPC;
  622. if (IS_POST) {
  623. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  624. $data['is_open_fullreduction'] = intval($data['is_open_fullreduction']);
  625. //验证优惠金额
  626. if($data['is_open_fullreduction'] == 1){
  627. $count = 1;
  628. if(!is_numeric($data['full_money']) || !is_numeric($data['full_reducemoney'])){
  629. show_json(0, array('message' => '1级金额必须1~10w的数字'));
  630. }
  631. $data['full_money'] = round(floatval($data['full_money']),2);
  632. $data['full_reducemoney'] = round(floatval($data['full_reducemoney']),2);
  633. if($data['full_money'] < 0 || $data['full_money'] > 100000 || $data['full_reducemoney'] < 0 || $data['full_reducemoney'] > 100000 ){
  634. show_json(0, array('message' => '1级金额必须1~10w的数字'));
  635. }
  636. if($data['full_money'] == 0 || $data['full_reducemoney'] == 0){
  637. show_json(0, array('message' => '1级优惠金额不能为0'));
  638. }
  639. $full_delete = array();
  640. for($i = 2;$i <= 5;$i++ ){
  641. if(isset($data['full_money_'.$i])){
  642. if(!is_numeric($data['full_money_'.$i]) || !is_numeric($data['full_reducemoney_'.$i])){
  643. show_json(0, array('message' => $i.'级金额必须1~10w的数字'));
  644. }
  645. $data['full_money_'.$i] = floatval(round($data['full_money_'.$i],2));
  646. $data['full_reducemoney_'.$i] = floatval(round($data['full_reducemoney_'.$i],2));
  647. if($data['full_money_'.$i] < 0 || $data['full_money_'.$i] > 100000 || $data['full_reducemoney_'.$i] < 0 || $data['full_reducemoney_'.$i] > 100000 ){
  648. show_json(0, array('message' => $i.'级金额必须1~10w的数字'));
  649. }
  650. if($data['full_money_'.$i] == 0 || $data['full_reducemoney_'.$i] == 0){
  651. show_json(0, array('message' => $i.'级优惠金额不能为0'));
  652. }
  653. if($i == 2){
  654. if($data['full_money_'.$i] < $data['full_money']){
  655. show_json(0, array('message' => $i.'级优惠金额不能低于上级金额'));
  656. }
  657. if($data['full_reducemoney_'.$i] < $data['full_reducemoney']){
  658. show_json(0, array('message' => $i.'级优惠金额不能低于上级金额'));
  659. }
  660. }else{
  661. if($data['full_money_'.$i] < $data['full_money_'.($i-1)]){
  662. show_json(0, array('message' => $i.'级优惠金额不能低于上级金额'));
  663. }
  664. if($data['full_reducemoney_'.$i] < $data['full_reducemoney_'.($i-1)]){
  665. show_json(0, array('message' => $i.'级优惠金额不能低于上级金额'));
  666. }
  667. }
  668. $count++;
  669. }else{
  670. $full_delete['full_money_'.$i] = 0;
  671. $full_delete['full_reducemoney_'.$i] = 0;
  672. }
  673. }
  674. }
  675. D('Seller/Config')->delete_config($full_delete);
  676. D('Seller/Config')->update($data);
  677. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  678. }
  679. $data = D('Seller/Config')->get_all_config();
  680. $this->data = $data;
  681. $this->display();
  682. }
  683. public function deletecategory()
  684. {
  685. $_GPC = I('request.');
  686. $id = intval($_GPC['id']);
  687. M('lionfish_comshop_coupon_category')->where( array('id' => $id) )->delete();
  688. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  689. }
  690. public function deletecoupon()
  691. {
  692. $_GPC = I('request.');
  693. $id = intval($_GPC['id']);
  694. if (empty($id)) {
  695. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  696. }
  697. $items = M('lionfish_comshop_coupon')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  698. foreach ($items as $item ) {
  699. M('lionfish_comshop_coupon')->where( array('id' => $item['id']) )->delete();
  700. }
  701. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  702. }
  703. public function category()
  704. {
  705. $_GPC = I('request.');
  706. if (!empty($_GPC['catid'])) {
  707. foreach ($_GPC['catid'] as $k => $v) {
  708. $data = array('name' => trim($_GPC['catname'][$k]), 'displayorder' => $k, 'status' => intval($_GPC['status'][$k]));
  709. if (empty($v)) {
  710. M('lionfish_comshop_coupon_category')->add($data);
  711. }
  712. else {
  713. M('lionfish_comshop_coupon_category')->where( array('id' => $v) )->save( $data );
  714. }
  715. }
  716. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  717. }
  718. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon_category WHERE merchid=0 ORDER BY displayorder asc');
  719. $this->list = $list;
  720. $this->display();
  721. }
  722. public function querycoupon()
  723. {
  724. $_GPC = I('request.');
  725. $this->gpc = $_GPC;
  726. $kwd = trim($_GPC['keyword']);
  727. $diy = intval($_GPC['diy']);
  728. $live = intval($_GPC['live']);
  729. $condition = ' and ( (timelimit = 1 and end_time > '.time().' ) or timelimit =0 )';
  730. if (!(empty($kwd)))
  731. {
  732. $condition .= ' AND voucher_title like "%'.$kwd.'%"';
  733. }
  734. $time = time();
  735. $ds = M()->query('SELECT * FROM ' . C('DB_PREFIX').
  736. 'lionfish_comshop_coupon WHERE 1 ' . $condition . ' ORDER BY id asc');
  737. $this->ds = $ds;
  738. $this->time = $time;
  739. include $this->display();
  740. }
  741. /**
  742. 签到奖励
  743. **/
  744. public function signinreward()
  745. {
  746. $_GPC = I('request.');
  747. if (IS_POST) {
  748. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  749. D('Seller/Config')->update($data);
  750. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  751. }
  752. $data = D('Seller/Config')->get_all_config();
  753. $this->data = $data;
  754. include $this->display();
  755. }
  756. public function delrecharge()
  757. {
  758. $id = I('request.id');
  759. M('lionfish_comshop_chargetype')->where( array('id' => $id ) )->delete();
  760. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  761. }
  762. /**
  763. * 充值设置
  764. * @return [type] [description]
  765. */
  766. public function recharge ()
  767. {
  768. $_GPC = I('request.');
  769. if (IS_POST) {
  770. $catid = $_GPC['catid'];
  771. $money = $_GPC['money'];
  772. $give = $_GPC['give'];
  773. $need_ids = array();
  774. foreach( $catid as $id )
  775. {
  776. if( $id > 0 )
  777. {
  778. $need_ids[] = $id;
  779. }
  780. }
  781. $list = M('lionfish_comshop_chargetype')->field('id')->order('id asc')->select();
  782. foreach($list as $vv )
  783. {
  784. if( empty($need_ids) || !in_array($vv['id'], $need_ids) )
  785. {
  786. M('lionfish_comshop_chargetype')->where( array('id' => $vv['id']) )->delete();
  787. }
  788. }
  789. //以上清理历史数据
  790. foreach( $catid as $key => $id )
  791. {
  792. if( $id > 0 )
  793. {
  794. M('lionfish_comshop_chargetype')->where( array('id' => $id) )->save( array('money' => $money[$key], 'send_money' => $give[$key]) );
  795. }else{
  796. $data = array();
  797. $data['money'] = $money[$key];
  798. $data['send_money'] = $give[$key];
  799. $data['addtime'] = time();
  800. $data['uniacid'] = $_W['uniacid'];
  801. M('lionfish_comshop_chargetype')->add($data);
  802. }
  803. }
  804. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  805. }
  806. $list = M('lionfish_comshop_chargetype')->order( 'id asc' )->select();
  807. $this->list = $list;
  808. $this->display();
  809. }
  810. public function recharge_config ()
  811. {
  812. $_GPC = I('request.');
  813. if (IS_POST) {
  814. $catid = $_GPC['catid'];
  815. $money = $_GPC['money'];
  816. $give = $_GPC['give'];
  817. $need_ids = array();
  818. foreach( $catid as $id )
  819. {
  820. if( $id > 0 )
  821. {
  822. $need_ids[] = $id;
  823. }
  824. }
  825. $list = M('lionfish_comshop_chargetype')->field('id')->order('id asc')->select();
  826. foreach($list as $vv )
  827. {
  828. if( empty($need_ids) || !in_array($vv['id'], $need_ids) )
  829. {
  830. M('lionfish_comshop_chargetype')->where( array('id' => $vv['id']) )->delete();
  831. }
  832. }
  833. //以上清理历史数据
  834. foreach( $catid as $key => $id )
  835. {
  836. if( $id > 0 )
  837. {
  838. M('lionfish_comshop_chargetype')->where( array('id' => $id) )->save( array('money' => $money[$key], 'send_money' => $give[$key]) );
  839. }else{
  840. $data = array();
  841. $data['money'] = $money[$key];
  842. $data['send_money'] = $give[$key];
  843. $data['addtime'] = time();
  844. $data['uniacid'] = $_W['uniacid'];
  845. M('lionfish_comshop_chargetype')->add($data);
  846. }
  847. }
  848. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  849. }
  850. $list = M('lionfish_comshop_chargetype')->order( 'id asc' )->select();
  851. $this->list = $list;
  852. $this->display('Marketing/recharge');
  853. }
  854. public function special ()
  855. {
  856. $_GPC = I('request.');
  857. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  858. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  859. $searchtime = isset($_GPC['searchtime']) && !empty($_GPC['searchtime']) ? $_GPC['searchtime'] : '';
  860. $this->starttime = $starttime;
  861. $this->endtime = $endtime;
  862. $pindex = max(1, intval($_GPC['page']));
  863. $psize = 20;
  864. $condition = ' 1 ';
  865. if (!empty($_GPC['keyword'])) {
  866. $_GPC['keyword'] = trim($_GPC['keyword']);
  867. $condition .= ' AND name LIKE "%'.trim($_GPC['keyword']).'%" ';
  868. }
  869. if (empty($starttime) || empty($endtime)) {
  870. $starttime = strtotime('-1 month');
  871. $endtime = time();
  872. }
  873. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  874. $starttime = strtotime($_GPC['time']['start']);
  875. $endtime = strtotime($_GPC['time']['end']);
  876. if (!empty($starttime)) {
  877. $condition .= ' AND addtime >= '.$starttime;
  878. }
  879. if (!empty($endtime)) {
  880. $condition .= ' AND addtime <= '.$endtime;
  881. }
  882. }
  883. if ($_GPC['gettype'] != '') {
  884. $condition .= ' AND enabled = '.intval($_GPC['gettype']);
  885. }
  886. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special ' . ' where 1 and ' . $condition . ' ORDER BY displayorder DESC,id DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  887. $list = M()->query($sql);
  888. $total_arr = M()->query('SELECT COUNT(*) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special where 1 and ' . $condition );
  889. $total = $total_arr[0]['count'];
  890. $pager = pagination2($total, $pindex, $psize);
  891. $this->list = $list;
  892. $this->pager = $pager;
  893. $this->_GPC = $_GPC;
  894. $this->display();
  895. }
  896. public function addspecial ()
  897. {
  898. $_GPC = I('request.');
  899. $id = intval($_GPC['id']);
  900. if (IS_POST) {
  901. $data = array();
  902. $data['name'] = $_GPC['name'];
  903. $data['cover'] = $_GPC['cover'];
  904. $data['type'] = intval($_GPC['type']);
  905. $data['enabled'] = intval($_GPC['enabled']);
  906. $data['is_index'] = intval($_GPC['is_index']);
  907. $data['show_type'] = intval($_GPC['show_type']);
  908. $data['index_pos'] = intval($_GPC['index_pos']);
  909. $data['special_title'] = $_GPC['special_title'];
  910. $data['special_cover'] = $_GPC['special_cover'];
  911. $data['displayorder'] = $_GPC['displayorder'];
  912. $data['goodsids'] = $_GPC['limit_goods_list'];
  913. $data['bg_color'] = trim($_GPC['bg_color']);
  914. $data['begin_time'] = strtotime($_GPC['time']['start']);
  915. $data['end_time'] = strtotime($_GPC['time']['end']) ;
  916. $data['addtime'] = time();
  917. if($id > 0)
  918. {
  919. M('lionfish_comshop_special')->where( array('id' => $id) )->save( $data );
  920. }else{
  921. $id = M('lionfish_comshop_special')->add($data);
  922. }
  923. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  924. }
  925. $item = M('lionfish_comshop_special')->where( array('id' => $id ) )->find();
  926. if (empty($item)) {
  927. $starttime = time();
  928. $endtime = strtotime(date('Y-m-d H:i:s', $starttime) . '+7 days');
  929. }else{
  930. $item['get_over_hour'] = $item['get_over_hour'] / 24;
  931. $starttime = $item['begin_time'];
  932. $endtime = $item['end_time'];
  933. $limit_goods = array();
  934. $time = time();
  935. //goodsids
  936. if( !empty($item['goodsids']) )
  937. {
  938. $goodsids_arr = explode(',', $item['goodsids'] );
  939. //$limit_goods = M('lionfish_comshop_goods')->field('id as gid,goodsname,subtitle,total,')->where( array('id' => array('in', $goodsids_arr ) ) )->order('id desc')->select();
  940. $sql_goods = "select g.id as gid,g.goodsname,g.subtitle,g.total,g.grounding,gc.begin_time,gc.end_time from "
  941. .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc "
  942. ." where g.id in (".$item['goodsids'].") and g.id=gc.goods_id order by g.id desc ";
  943. ///echo $sql_goods;
  944. $limit_goods = M()->query($sql_goods);
  945. foreach($limit_goods as $kk => $vv)
  946. {
  947. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $vv['gid'] ) )->order('id asc')->find();
  948. $vv['image'] = tomedia($thumb['image']);
  949. if($time >= $vv['begin_time'] && $time <= $vv['end_time']){
  950. $vv['is_finished'] = 0;
  951. }else{
  952. $vv['is_finished'] = 1;//已结束
  953. }
  954. if($vv['total'] <= 0){
  955. $vv['is_grab'] = 1;//已抢光
  956. }else{
  957. $vv['is_grab'] = 0;
  958. }
  959. $limit_goods[$kk] = $vv;
  960. }
  961. }
  962. $this->limit_goods = $limit_goods;
  963. }
  964. $this->starttime = $starttime;
  965. $this->endtime = $endtime;
  966. $this->item = $item;
  967. $this->_GPC = $_GPC;
  968. $this->display();
  969. }
  970. public function changespecial()
  971. {
  972. $_GPC = I('request.');
  973. $id = intval($_GPC['id']);
  974. //ids
  975. if (empty($id)) {
  976. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  977. }
  978. if (empty($id)) {
  979. show_json(0, array('message' => '参数错误'));
  980. }
  981. $type = trim($_GPC['type']);
  982. $value = trim($_GPC['value']);
  983. if (!(in_array($type, array('enabled', 'displayorder' , 'is_index')))) {
  984. show_json(0, array('message' => '参数错误'));
  985. }
  986. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE id in( ' . $id . ' ) ' );
  987. foreach ($items as $item) {
  988. M('lionfish_comshop_special')->where( array('id' => $item['id']) )->save( array($type => $value) );
  989. }
  990. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  991. }
  992. public function deletespecial()
  993. {
  994. $_GPC = I('request.');
  995. $id = intval($_GPC['id']);
  996. if (empty($id)) {
  997. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  998. }
  999. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE id in( ' . $id . ' ) ');
  1000. foreach ($items as $item ) {
  1001. M('lionfish_comshop_special')->where( array('id' => $item['id']) )->delete();
  1002. }
  1003. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1004. }
  1005. /**
  1006. * 弹窗选择
  1007. * @return [type] [description]
  1008. */
  1009. public function couponquery()
  1010. {
  1011. $kwd = I('request.keyword','','trim');
  1012. $is_ajax = I('request.is_ajax',0,'intval');
  1013. $coupon_ids = I('request.coupon_ids');
  1014. $condition = ' ( (timelimit = 1 and end_time > '.time().' ) or timelimit =0 )';
  1015. if (!empty($kwd)) {
  1016. $condition .= ' AND voucher_title LIKE "%'.$kwd.'%"';
  1017. }
  1018. /**
  1019. 分页开始
  1020. **/
  1021. $page = I('request.page',1,'intval');
  1022. $page = max(1, $page);
  1023. $page_size = 10;
  1024. /**
  1025. 分页结束
  1026. **/
  1027. $ds = M('lionfish_comshop_coupon')->where( $condition )->order('id desc')->limit( (($page - 1) * $page_size) . ',' . $page_size )->select();
  1028. $total = M('lionfish_comshop_coupon')->where( $condition )->count();
  1029. $category_arr = M()->query('select * from ' . C('DB_PREFIX') . 'lionfish_comshop_coupon_category order by id desc');
  1030. $category = array();
  1031. foreach($category_arr as $vv)
  1032. {
  1033. $category[$vv['id']] = $vv['name'];
  1034. }
  1035. $ret_html = '';
  1036. foreach ($ds as &$value) {
  1037. if(in_array($value['id'],$coupon_ids)){
  1038. $value['is_exist'] = 1;
  1039. }else{
  1040. $value['is_exist'] = 0;
  1041. }
  1042. if($is_ajax == 1)
  1043. {
  1044. $ret_html .= '<tr>';
  1045. $ret_html .= '<td style="width:50px;">'.$value['id'].'</td>';
  1046. $ret_html .= '<td style="width:200px;">'.$value['voucher_title'].'<label class="label label-success">购物</label>';
  1047. if($value['catid']) {
  1048. $ret_html .= '<label class="label label-primary">'.$category[$value['catid']].'</label>';
  1049. }
  1050. if($value['is_new_man']==1) {
  1051. $ret_html .= '<label class="layui-badge">新人券</label>';
  1052. }
  1053. $ret_html .= '</td>';
  1054. $ret_html .= '<td>';
  1055. $ret_html .= $value['credit']. '元 ';
  1056. if( $value['limit_money']>0) {
  1057. $ret_html .= '<span class="text-danger">满'.$value['limit_money'].'.可用</span>';
  1058. }else{
  1059. $ret_html .= '<span class="text-warning">不限</span>';
  1060. }
  1061. $ret_html .= '</td>';
  1062. $ret_html .= '<td>';
  1063. if($value['total_count']==-1){
  1064. $ret_html .= '无限';
  1065. }else{
  1066. $ret_html .= '剩余:'.($value['total_count']-$value['send_count'])<0?0:$value['total_count']-$value['send_count'];
  1067. }
  1068. $ret_html .= '</td>';
  1069. if($value['is_exist'] == 1){
  1070. $ret_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_dan_head" disabled="disabled" style="color:#999;">选择</a></td>';
  1071. }else{
  1072. $ret_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_dan_head" data-json=\''.json_encode($value).'\'>选择</a></td>';
  1073. }
  1074. $ret_html .= '</tr>';
  1075. }
  1076. }
  1077. $pager = pagination($total, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => 1));
  1078. unset($value);
  1079. if( $is_ajax == 1 )
  1080. {
  1081. echo json_encode( array('code' => 0, 'html' => $ret_html,'pager' => $pager) );
  1082. die();
  1083. }
  1084. $this->ds = $ds;
  1085. $this->pager = $pager;
  1086. $this->category = $category;
  1087. $this->display();
  1088. }
  1089. /**
  1090. * 弹窗专题选择
  1091. */
  1092. public function special_select ()
  1093. {
  1094. $_GPC = I('request.');
  1095. if(IS_AJAX) {
  1096. $page = I('request.page', 1);
  1097. $page_size = I('request.page_size', 10);
  1098. $condition = "1";
  1099. if (!empty($_GPC['promotion_name'])) {
  1100. $_GPC['promotion_name'] = trim($_GPC['promotion_name']);
  1101. $condition .= ' AND name LIKE "%'.trim($_GPC['promotion_name']).'%" ';
  1102. }
  1103. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special ' . ' where ' . $condition ;
  1104. $count=count(M()->query($sql));
  1105. $Page = new \Think\Page($count, $page_size);
  1106. $list = M()->query('SELECT * FROM '.C('DB_PREFIX').'lionfish_comshop_special WHERE '.$condition.' ORDER BY displayorder DESC,id DESC LIMIT '.($page-1)*$page_size.','.$Page->listRows);
  1107. if(count($list)) {
  1108. foreach($list as $kk => $vv)
  1109. {
  1110. $vv['image'] = tomedia($vv['cover']);
  1111. $list[$kk] = $vv;
  1112. }
  1113. }
  1114. $page_count = ceil($count/$page_size);
  1115. $res = array( "code" => 0, "data" => array('list'=>$list, 'count'=>$count, 'page_count'=>$page_count) );
  1116. echo json_encode($res);
  1117. die();
  1118. } else {
  1119. $this->display();
  1120. }
  1121. }
  1122. }
  1123. ?>