MarketingController.class.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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['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 couponsend_do()
  120. {
  121. $_GPC = I('request.');
  122. $voucher_id = $_GPC['voucher_id'];
  123. $send_count = $_GPC['send_count'];
  124. $send_person = $_GPC['send_person'];
  125. $member_group_id = $_GPC['member_group_id'];
  126. $limit_user_list = $_GPC['limit_user_list'];
  127. $cache_key = md5(time().$voucher_id.$send_person);
  128. $ids_arr = array();
  129. if( $send_person == 1)
  130. {
  131. //送给部分人
  132. $ids_arr = explode(',', $limit_user_list);
  133. }else if( $send_person == 2 )
  134. {
  135. //送给分组
  136. $member_group_id = $member_group_id == 'default' ? 0 : $member_group_id;
  137. $mb_list = M('lionfish_comshop_member')->field('member_id')->where( array('groupid' => $member_group_id ) )->select();
  138. foreach( $mb_list as $val )
  139. {
  140. $ids_arr[] = $val['member_id'];
  141. }
  142. }else if( $send_person == 3 ){
  143. //送给所有人
  144. $mb_list = M()->query("select member_id from ".C('DB_PREFIX')."lionfish_comshop_member where 1 " );
  145. foreach( $mb_list as $val )
  146. {
  147. $ids_arr[] = $val['member_id'];
  148. }
  149. }
  150. S('_send_quan_'.$cache_key, $ids_arr);
  151. $this->cache_key = $cache_key;
  152. $this->voucher_id = $voucher_id;
  153. $this->send_count = $send_count;
  154. $this->send_person = $send_person;
  155. $this->member_group_id = $member_group_id;
  156. $this->limit_user_list = $limit_user_list;
  157. include $this->display();
  158. }
  159. public function do_coupon_quene()
  160. {
  161. $_GPC = I('request.');
  162. $voucher_id = $_GPC['voucher_id'];
  163. $send_count = $_GPC['send_count'];
  164. $cache_key = $_GPC['cache_key'];
  165. $quene_order_list = S('_send_quan_'.$cache_key);
  166. $member_id = array_shift($quene_order_list);
  167. S('_send_quan_'.$cache_key, $quene_order_list);
  168. //send quan
  169. for( $i =0; $i< $send_count; $i++ )
  170. {
  171. $res = D('Home/Voucher')->send_user_voucher_byId($voucher_id,$member_id,false);
  172. }
  173. if( empty($quene_order_list) )
  174. {
  175. echo json_encode( array('code' => 2) );
  176. die();
  177. }
  178. echo json_encode( array('code' => 0, 'msg' => '会员id:'.$member_id." 处理成功,还剩余".count($quene_order_list)."个会员未处理") );
  179. die();
  180. }
  181. public function change()
  182. {
  183. $_GPC = I('request.');
  184. $id = intval($_GPC['id']);
  185. //ids
  186. if (empty($id)) {
  187. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  188. }
  189. if (empty($id)) {
  190. show_json(0, array('message' => '参数错误'));
  191. }
  192. $type = trim($_GPC['type']);
  193. $value = trim($_GPC['value']);
  194. if (!(in_array($type, array('is_index_show', 'displayorder')))) {
  195. show_json(0, array('message' => '参数错误'));
  196. }
  197. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX') . 'lionfish_comshop_coupon WHERE id in( ' . $id . ' ) ' );
  198. foreach ($items as $item) {
  199. M('lionfish_comshop_coupon')->where( array('id' => $item['id']) )->save( array($type => $value) );
  200. }
  201. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  202. }
  203. public function seckill()
  204. {
  205. $_GPC = I('request.');
  206. if ( IS_POST ) {
  207. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  208. $scekill_show_time_arr = $_GPC['scekill_show_time'];
  209. if( !empty($scekill_show_time_arr) )
  210. {
  211. $data['scekill_show_time'] = serialize($scekill_show_time_arr);
  212. }
  213. D('Seller/Config')->update($data);
  214. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  215. }
  216. $data = D('Seller/Config')->get_all_config();
  217. if( isset($data['scekill_show_time']) && !empty($data['scekill_show_time']) )
  218. {
  219. $data['scekill_show_time_arr'] = unserialize($data['scekill_show_time']);
  220. }
  221. $this->data = $data;
  222. $this->display();
  223. }
  224. public function explain()
  225. {
  226. $_GPC = I('request.');
  227. if (IS_POST) {
  228. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  229. D('Seller/Config')->update($data);
  230. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  231. }
  232. $data = D('Seller/Config')->get_all_config();
  233. $this->data = $data;
  234. $this->display();
  235. }
  236. //logcoupon&couponid=3
  237. public function logcoupon()
  238. {
  239. $_GPC = I('request.');
  240. $this->gpc = $_GPC;
  241. $pindex = max(1, intval($_GPC['page']));
  242. $psize = 20;
  243. $condition = ' 1 ';
  244. $couponid = intval($_GPC['couponid']);
  245. if (!empty($couponid)) {
  246. $coupon = M('lionfish_comshop_coupon')->where( array('id' => $couponid ) )->find();
  247. $this->coupon = $coupon;
  248. $condition .= ' AND c.voucher_id=' . intval($couponid);
  249. }
  250. $searchfield = strtolower(trim($_GPC['searchfield']));
  251. $keyword = trim($_GPC['keyword']);
  252. if (!empty($searchfield) && !empty($keyword)) {
  253. if ($searchfield == 'member') {
  254. $condition .= ' and ( m.realname like "%'.$keyword.'%" or m.nickname like "%'.$keyword.'%" or m.mobile like "%'.$keyword.'%" )';
  255. }
  256. else {
  257. if ($searchfield == 'coupon') {
  258. $condition .= ' and c.voucher_title like "%'.$keyword.'%" ';
  259. }
  260. }
  261. }
  262. if (empty($starttime) || empty($endtime)) {
  263. $starttime = strtotime('-1 month');
  264. $endtime = time();
  265. }
  266. if (empty($starttime1) || empty($endtime1)) {
  267. $starttime1 = strtotime('-1 month');
  268. $endtime1 = time();
  269. }
  270. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  271. $starttime = strtotime($_GPC['time']['start']);
  272. $endtime = strtotime($_GPC['time']['end']);
  273. $this->starttime = $starttime;
  274. $this->endtime = $endtime;
  275. $condition .= ' AND c.add_time >= '.$starttime.' AND c.add_time <= '.$endtime;
  276. }
  277. if (!empty($_GPC['time1']['start']) && !empty($_GPC['time1']['end'])) {
  278. $starttime1 = strtotime($_GPC['time1']['start']);
  279. $endtime1 = strtotime($_GPC['time1']['end']);
  280. $this->starttime1 = $starttime1;
  281. $this->endtime1 = $endtime1;
  282. $condition .= ' AND c.usetime >= '.$starttime1.' AND c.add_time <= '.$endtime1;
  283. }
  284. if ($_GPC['type'] != '') {
  285. $condition .= ' AND c.coupontype = '.intval($_GPC['type']);
  286. }
  287. if ($_GPC['used'] != '') {
  288. $condition .= ' AND c.consume = "' . trim($_GPC['used']).'" ';
  289. }
  290. if ($_GPC['gettype'] != '') {
  291. $condition .= ' AND c.gettype ='.intval($_GPC['gettype']);
  292. }
  293. $sql = 'SELECT c.*,m.username,m.avatar,m.openid,m.telephone FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon_list c ' .
  294. ' 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';
  295. if (empty($_GPC['export'])) {
  296. $sql .= ' LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  297. }
  298. $list = M()->query($sql);
  299. foreach ($list as &$row) {
  300. $couponstr = '消费';
  301. $row['couponstr'] = $couponstr;
  302. if ($row['gettype'] == 0) {
  303. $row['gettypestr'] = '后台发放';
  304. }
  305. else if ($row['gettype'] == 1) {
  306. $row['gettypestr'] = '首页领取';
  307. }
  308. else if ($row['gettype'] == 2) {
  309. $row['gettypestr'] = '积分商城';
  310. }
  311. else if ($row['gettype'] == 14) {
  312. $row['gettypestr'] = '新人领券';
  313. }
  314. else {
  315. if ($row['gettype'] == 15) {
  316. $row['gettypestr'] = '发券分享';
  317. }
  318. }
  319. }
  320. unset($row);
  321. if ($_GPC['export'] == 1) {
  322. foreach ($list as &$row) {
  323. $row['gettime'] = date('Y-m-d H:i', $row['add_time']);
  324. if (!empty($row['usetime'])) {
  325. $row['usetime'] = date('Y-m-d H:i', $row['usetime']);
  326. }
  327. else {
  328. $row['usetime'] = '---';
  329. }
  330. }
  331. $columns = array(
  332. array('title' => 'ID', 'field' => 'id', 'width' => 12),
  333. array('title' => '优惠券', 'field' => 'voucher_title', 'width' => 24),
  334. array('title' => '类型', 'field' => 'couponstr', 'width' => 12),
  335. array('title' => '会员信息', 'field' => 'username', 'width' => 12),
  336. array('title' => '姓名', 'field' => 'realname', 'width' => 12),
  337. array('title' => '手机号', 'field' => 'telephone', 'width' => 12),
  338. array('title' => 'openid', 'field' => 'openid', 'width' => 24),
  339. array('title' => '获取方式', 'field' => 'gettypestr', 'width' => 12),
  340. array('title' => '获取时间', 'field' => 'gettime', 'width' => 12),
  341. array('title' => '使用时间', 'field' => 'usetime', 'width' => 12),
  342. array('title' => '使用单号', 'field' => 'ordersn', 'width' => 12)
  343. );
  344. D('Seller/Excel')->export($list, array('title' => '优惠券数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  345. //m('excel')->export($list, array('title' => '优惠券数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  346. //plog('sale.coupon.log.export', '导出优惠券发放记录');
  347. }
  348. $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);
  349. $total = $total_arr[0]['count'];
  350. $pager = pagination2($total, $pindex, $psize);
  351. $this->list = $list;
  352. $this->pager = $pager;
  353. $this->display();
  354. }
  355. public function recharge_diary()
  356. {
  357. $_GPC = I('request.');
  358. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  359. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  360. $keyword = $_GPC['keyword'];
  361. $state = $_GPC['state'];
  362. $this->starttime = $starttime;
  363. $this->endtime = $endtime;
  364. $this->keyword = $keyword;
  365. $this->state = $state;
  366. $condition = ' ';
  367. if( !empty($state) && $state > 0 )
  368. {
  369. $condition .= " and cf.state ={$state} ";
  370. }else{
  371. $condition .= " and cf.state <> 0 ";
  372. }
  373. if( isset($_GPC['time']) )
  374. {
  375. if($_GPC['time']['start'])
  376. {
  377. $condition .= " and cf.add_time >= {$starttime} ";
  378. }
  379. if($_GPC['time']['end'])
  380. {
  381. $condition .= " and cf.add_time <= {$endtime} ";
  382. }
  383. }
  384. if( !empty($keyword) )
  385. {
  386. $condition .= " and m.username like '%{$keyword}%' ";
  387. }
  388. $pindex = max(1, intval($_GPC['page']));
  389. $psize = 20;
  390. $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
  391. where cf.member_id = m.member_id {$condition} order by cf.id desc limit ". (($pindex - 1) * $psize) . ',' . $psize;
  392. $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
  393. where cf.member_id = m.member_id {$condition} ";
  394. $list = M()->query($sql);
  395. $total_arr = M()->query($sql_count );
  396. $total = $total_arr[0]['count'];
  397. foreach( $list as $key => $val )
  398. {
  399. $val['add_time'] = date('Y-m-d H:i:s',$val['add_time'] );
  400. if($val['state'] == 3 || $val['state'] == 4)
  401. {
  402. $od_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['trans_id'] ) )->find();
  403. if( !empty($od_info) )
  404. {
  405. $val['trans_id'] = $od_info['order_num_alias'];
  406. }
  407. }
  408. $list[$key] = $val;
  409. }
  410. $pager = pagination2($total, $pindex, $psize);
  411. $all_count = M('lionfish_comshop_member_charge_flow')->where( "state != 0" )->count();
  412. $count_status_1 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 1) )->count();
  413. $count_status_3 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 3) )->count();
  414. $count_status_4 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 4) )->count();
  415. $count_status_5 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 5) )->count();
  416. $count_status_8 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 8) )->count();
  417. $count_status_9 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 9) )->count();
  418. $count_status_10 = M('lionfish_comshop_member_charge_flow')->where( array('state' => 10) )->count();
  419. $this->list = $list;
  420. $this->pager = $pager;
  421. $this->all_count = $all_count;
  422. $this->count_status_1 = $count_status_1;
  423. $this->count_status_3 = $count_status_3;
  424. $this->count_status_4 = $count_status_4;
  425. $this->count_status_5 = $count_status_5;
  426. $this->count_status_8 = $count_status_8;
  427. $this->count_status_9 = $count_status_9;
  428. $this->count_status_10 = $count_status_10;
  429. $this->display();
  430. }
  431. public function displayordercoupon()
  432. {
  433. $_GPC = I('request.');
  434. $id = intval($_GPC['id']);
  435. if (empty($id)) {
  436. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  437. }
  438. $displayorder = intval($_GPC['value']);
  439. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon WHERE id in( ' . $id . ' ) ' );
  440. foreach ($items as $item) {
  441. M('lionfish_comshop_coupon')->where( array('id' => $id) )->save( array('displayorder' => $displayorder) );
  442. }
  443. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  444. }
  445. public function addcoupon()
  446. {
  447. $_GPC = I('request.');
  448. $id = intval($_GPC['id']);
  449. if (IS_POST) {
  450. $data = array();
  451. $data['catid'] = $_GPC['catid'];
  452. $data['voucher_title'] = $_GPC['voucher_title'];
  453. $data['thumb'] = $_GPC['thumb'];
  454. $data['credit'] = $_GPC['credit'];
  455. $data['type'] = 1;
  456. $data['is_index_show'] = $_GPC['is_index_show'];
  457. $data['is_index_alert'] = $_GPC['is_index_alert'];
  458. $data['is_share_doubling'] = 0;
  459. $data['get_over_hour'] = $_GPC['get_over_hour'] * 24;
  460. $data['is_limit_goods_buy'] = $_GPC['is_limit_goodsbuy'];
  461. $data['is_new_man'] = $_GPC['is_new_man'];
  462. $data['share_title'] = '';
  463. $data['share_desc'] = '';
  464. $data['share_logo'] = '';
  465. $data['timelimit'] = $_GPC['timelimit'];
  466. $data['person_limit_count'] = $_GPC['person_limit_count'];
  467. $data['limit_goods_list'] = $_GPC['limit_goods_list'];
  468. $data['goodscates'] = $_GPC['goodscates'];
  469. $data['limit_money'] = $_GPC['limit_money'];
  470. $data['total_count'] = $_GPC['total_count'];
  471. $data['send_count'] = $_GPC['send_count'];
  472. $data['add_time'] = time();
  473. $data['displayorder'] = $_GPC['displayorder'];
  474. $data['begin_time'] = strtotime($_GPC['time']['start']);
  475. $data['end_time'] = strtotime($_GPC['time']['end']) + 86399;
  476. if($id > 0)
  477. {
  478. M('lionfish_comshop_coupon')->where( array('id' => $id) )->save( $data );
  479. }else{
  480. M('lionfish_comshop_coupon')->add($data);
  481. }
  482. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  483. }
  484. $category = M()->query('select * from ' . C('DB_PREFIX'). 'lionfish_comshop_coupon_category where merchid=0 order by id desc');
  485. $goods_category = D('Seller/GoodsCategory')->getFullCategory(true, true);
  486. $this->goods_category = $goods_category;
  487. $new_category = array();
  488. foreach($category as $key =>$val)
  489. {
  490. $new_category[$val['id']] = $val;
  491. }
  492. $this->category = $category;
  493. if (empty($id)) {
  494. $starttime = time();
  495. $endtime = strtotime(date('Y-m-d H:i:s', $starttime) . '+7 days');
  496. }else{
  497. $item = M('lionfish_comshop_coupon')->where( array('id' => $id) )->find();
  498. $item['get_over_hour'] = $item['get_over_hour'] / 24;
  499. $starttime = $item['begin_time'];
  500. $endtime = $item['end_time'];
  501. $limit_goods = array();
  502. if( !empty($item['limit_goods_list']) )
  503. {
  504. $limit_goods = M('lionfish_comshop_goods')->field('id as gid,goodsname,subtitle')->where('id in('.$item['limit_goods_list'].')')->order('id desc')->select();
  505. foreach($limit_goods as $kk => $vv)
  506. {
  507. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $vv['gid'] ) )->order('id asc')->find();
  508. $vv['image'] = tomedia($thumb['image']);
  509. $limit_goods[$kk] = $vv;
  510. }
  511. }
  512. $this->limit_goods = $limit_goods;
  513. $this->item = $item;
  514. }
  515. $this->starttime = $starttime;
  516. $this->endtime = $endtime;
  517. $this->display();
  518. }
  519. public function fullreduction()
  520. {
  521. $_GPC = I('request.');
  522. $this->gpc = $_GPC;
  523. if (IS_POST) {
  524. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  525. $data['is_open_fullreduction'] = intval($data['is_open_fullreduction']);
  526. $data['full_money'] = floatval($data['full_money']);
  527. $data['full_reducemoney'] = floatval($data['full_reducemoney']);
  528. D('Seller/Config')->update($data);
  529. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  530. }
  531. $data = D('Seller/Config')->get_all_config();
  532. $this->data = $data;
  533. $this->display();
  534. }
  535. public function deletecategory()
  536. {
  537. $_GPC = I('request.');
  538. $id = intval($_GPC['id']);
  539. M('lionfish_comshop_coupon_category')->where( array('id' => $id) )->delete();
  540. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  541. }
  542. public function deletecoupon()
  543. {
  544. $_GPC = I('request.');
  545. $id = intval($_GPC['id']);
  546. if (empty($id)) {
  547. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  548. }
  549. $items = M('lionfish_comshop_coupon')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  550. foreach ($items as $item ) {
  551. M('lionfish_comshop_coupon')->where( array('id' => $item['id']) )->delete();
  552. }
  553. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  554. }
  555. public function category()
  556. {
  557. $_GPC = I('request.');
  558. if (!empty($_GPC['catid'])) {
  559. foreach ($_GPC['catid'] as $k => $v) {
  560. $data = array('name' => trim($_GPC['catname'][$k]), 'displayorder' => $k, 'status' => intval($_GPC['status'][$k]));
  561. if (empty($v)) {
  562. M('lionfish_comshop_coupon_category')->add($data);
  563. }
  564. else {
  565. M('lionfish_comshop_coupon_category')->where( array('id' => $v) )->save( $data );
  566. }
  567. }
  568. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  569. }
  570. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_coupon_category WHERE merchid=0 ORDER BY displayorder asc');
  571. $this->list = $list;
  572. $this->display();
  573. }
  574. public function querycoupon()
  575. {
  576. $_GPC = I('request.');
  577. $this->gpc = $_GPC;
  578. $kwd = trim($_GPC['keyword']);
  579. $diy = intval($_GPC['diy']);
  580. $live = intval($_GPC['live']);
  581. $condition = ' and ( (timelimit = 1 and end_time > '.time().' ) or timelimit =0 )';
  582. if (!(empty($kwd)))
  583. {
  584. $condition .= ' AND voucher_title like "%'.$kwd.'%"';
  585. }
  586. $time = time();
  587. $ds = M()->query('SELECT * FROM ' . C('DB_PREFIX').
  588. 'lionfish_comshop_coupon WHERE 1 ' . $condition . ' ORDER BY id asc');
  589. $this->ds = $ds;
  590. $this->time = $time;
  591. include $this->display();
  592. }
  593. /**
  594. 签到奖励
  595. **/
  596. public function signinreward()
  597. {
  598. $_GPC = I('request.');
  599. if (IS_POST) {
  600. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  601. D('Seller/Config')->update($data);
  602. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  603. }
  604. $data = D('Seller/Config')->get_all_config();
  605. $this->data = $data;
  606. include $this->display();
  607. }
  608. public function delrecharge()
  609. {
  610. $id = I('request.id');
  611. M('lionfish_comshop_chargetype')->where( array('id' => $id ) )->delete();
  612. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  613. }
  614. /**
  615. * 充值设置
  616. * @return [type] [description]
  617. */
  618. public function recharge ()
  619. {
  620. $_GPC = I('request.');
  621. if (IS_POST) {
  622. $catid = $_GPC['catid'];
  623. $money = $_GPC['money'];
  624. $give = $_GPC['give'];
  625. $need_ids = array();
  626. foreach( $catid as $id )
  627. {
  628. if( $id > 0 )
  629. {
  630. $need_ids[] = $id;
  631. }
  632. }
  633. $list = M('lionfish_comshop_chargetype')->field('id')->order('id asc')->select();
  634. foreach($list as $vv )
  635. {
  636. if( empty($need_ids) || !in_array($vv['id'], $need_ids) )
  637. {
  638. M('lionfish_comshop_chargetype')->where( array('id' => $vv['id']) )->delete();
  639. }
  640. }
  641. //以上清理历史数据
  642. foreach( $catid as $key => $id )
  643. {
  644. if( $id > 0 )
  645. {
  646. M('lionfish_comshop_chargetype')->where( array('id' => $id) )->save( array('money' => $money[$key], 'send_money' => $give[$key]) );
  647. }else{
  648. $data = array();
  649. $data['money'] = $money[$key];
  650. $data['send_money'] = $give[$key];
  651. $data['addtime'] = time();
  652. $data['uniacid'] = $_W['uniacid'];
  653. M('lionfish_comshop_chargetype')->add($data);
  654. }
  655. }
  656. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  657. }
  658. $list = M('lionfish_comshop_chargetype')->order( 'id asc' )->select();
  659. $this->list = $list;
  660. $this->display();
  661. }
  662. public function special ()
  663. {
  664. $_GPC = I('request.');
  665. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  666. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  667. $searchtime = isset($_GPC['searchtime']) && !empty($_GPC['searchtime']) ? $_GPC['searchtime'] : '';
  668. $this->starttime = $starttime;
  669. $this->endtime = $endtime;
  670. $pindex = max(1, intval($_GPC['page']));
  671. $psize = 20;
  672. $condition = ' 1 ';
  673. if (!empty($_GPC['keyword'])) {
  674. $_GPC['keyword'] = trim($_GPC['keyword']);
  675. $condition .= ' AND name LIKE "%'.trim($_GPC['keyword']).'%" ';
  676. }
  677. if (empty($starttime) || empty($endtime)) {
  678. $starttime = strtotime('-1 month');
  679. $endtime = time();
  680. }
  681. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  682. $starttime = strtotime($_GPC['time']['start']);
  683. $endtime = strtotime($_GPC['time']['end']);
  684. if (!empty($starttime)) {
  685. $condition .= ' AND addtime >= '.$starttime;
  686. }
  687. if (!empty($endtime)) {
  688. $condition .= ' AND addtime <= '.$endtime;
  689. }
  690. }
  691. if ($_GPC['gettype'] != '') {
  692. $condition .= ' AND enabled = '.intval($_GPC['gettype']);
  693. }
  694. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special ' . ' where 1 and ' . $condition . ' ORDER BY displayorder DESC,id DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  695. $list = M()->query($sql);
  696. $total_arr = M()->query('SELECT COUNT(*) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special where 1 and ' . $condition );
  697. $total = $total_arr[0]['count'];
  698. $pager = pagination2($total, $pindex, $psize);
  699. $this->list = $list;
  700. $this->pager = $pager;
  701. $this->_GPC = $_GPC;
  702. $this->display();
  703. }
  704. public function addspecial ()
  705. {
  706. $_GPC = I('request.');
  707. $id = intval($_GPC['id']);
  708. if (IS_POST) {
  709. $data = array();
  710. $data['name'] = $_GPC['name'];
  711. $data['cover'] = $_GPC['cover'];
  712. $data['type'] = intval($_GPC['type']);
  713. $data['enabled'] = intval($_GPC['enabled']);
  714. $data['is_index'] = intval($_GPC['is_index']);
  715. $data['show_type'] = intval($_GPC['show_type']);
  716. $data['special_title'] = $_GPC['special_title'];
  717. $data['special_cover'] = $_GPC['special_cover'];
  718. $data['displayorder'] = $_GPC['displayorder'];
  719. $data['goodsids'] = $_GPC['limit_goods_list'];
  720. $data['bg_color'] = trim($_GPC['bg_color']);
  721. $data['begin_time'] = strtotime($_GPC['time']['start']);
  722. $data['end_time'] = strtotime($_GPC['time']['end']) ;
  723. $data['addtime'] = time();
  724. if($id > 0)
  725. {
  726. M('lionfish_comshop_special')->where( array('id' => $id) )->save( $data );
  727. }else{
  728. $id = M('lionfish_comshop_special')->add($data);
  729. }
  730. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  731. }
  732. $item = M('lionfish_comshop_special')->where( array('id' => $id ) )->find();
  733. if (empty($item)) {
  734. $starttime = time();
  735. $endtime = strtotime(date('Y-m-d H:i:s', $starttime) . '+7 days');
  736. }else{
  737. $item['get_over_hour'] = $item['get_over_hour'] / 24;
  738. $starttime = $item['begin_time'];
  739. $endtime = $item['end_time'];
  740. $limit_goods = array();
  741. //goodsids
  742. if( !empty($item['goodsids']) )
  743. {
  744. $goodsids_arr = explode(',', $item['goodsids'] );
  745. $limit_goods = M('lionfish_comshop_goods')->field('id as gid,goodsname,subtitle')->where( array('id' => array('in', $goodsids_arr ) ) )->order('id desc')->select();
  746. foreach($limit_goods as $kk => $vv)
  747. {
  748. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $vv['gid'] ) )->order('id asc')->find();
  749. $vv['image'] = tomedia($thumb['image']);
  750. $limit_goods[$kk] = $vv;
  751. }
  752. }
  753. $this->limit_goods = $limit_goods;
  754. }
  755. $this->starttime = $starttime;
  756. $this->endtime = $endtime;
  757. $this->item = $item;
  758. $this->_GPC = $_GPC;
  759. $this->display();
  760. }
  761. public function changespecial()
  762. {
  763. $_GPC = I('request.');
  764. $id = intval($_GPC['id']);
  765. //ids
  766. if (empty($id)) {
  767. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  768. }
  769. if (empty($id)) {
  770. show_json(0, array('message' => '参数错误'));
  771. }
  772. $type = trim($_GPC['type']);
  773. $value = trim($_GPC['value']);
  774. if (!(in_array($type, array('enabled', 'displayorder' , 'is_index')))) {
  775. show_json(0, array('message' => '参数错误'));
  776. }
  777. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE id in( ' . $id . ' ) ' );
  778. foreach ($items as $item) {
  779. M('lionfish_comshop_special')->where( array('id' => $item['id']) )->save( array($type => $value) );
  780. }
  781. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  782. }
  783. public function deletespecial()
  784. {
  785. $_GPC = I('request.');
  786. $id = intval($_GPC['id']);
  787. if (empty($id)) {
  788. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  789. }
  790. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE id in( ' . $id . ' ) ');
  791. foreach ($items as $item ) {
  792. M('lionfish_comshop_special')->where( array('id' => $item['id']) )->delete();
  793. }
  794. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  795. }
  796. }
  797. ?>