MarketingController.class.php 41 KB

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