card.ctrl.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $_W['page']['title'] = '会员卡管理 - 会员中心';
  8. $dos = array('display', 'manage', 'delete', 'coupon', 'submit', 'modal', 'record', 'notice', 'editor', 'sign','ajax');
  9. $do = in_array($do, $dos) ? $do : 'other';
  10. load()->model('mc');
  11. load()->model('activity');
  12. activity_coupon_type_init();
  13. $setting = pdo_fetch("SELECT * FROM ".tablename('mc_card')." WHERE uniacid = '{$_W['uniacid']}'");
  14. if($do == 'ajax') {
  15. $op = trim($_GPC['op']);
  16. $sql = 'SELECT `uniacid` FROM ' . tablename('mc_card') . " WHERE `uniacid` = :uniacid";
  17. $setting = pdo_fetch($sql, array(':uniacid' => $_W['uniacid']));
  18. if($op == 'status') {
  19. if(empty($setting)) {
  20. $open = array(
  21. 'uniacid' => $_W['uniacid'],
  22. 'title' => '我的会员卡',
  23. 'format_type' => 1,
  24. 'fields' => iserializer(array(
  25. array('title' => '姓名', 'require' => 1, 'bind' => 'realname'),
  26. array('title' => '手机', 'require' => 1, 'bind' => 'mobile'),
  27. )),
  28. 'status' => 1,
  29. );
  30. pdo_insert('mc_card', $open);
  31. }
  32. if (false === pdo_update('mc_card', array('status' => intval($_GPC['status'])), array('uniacid' => $_W['uniacid']))) {
  33. exit('error');
  34. }
  35. } elseif($op == 'other') {
  36. if(empty($setting)) {
  37. exit('还没有开启会员卡,请先开启会员卡');
  38. }
  39. $field = trim($_GPC['field']);
  40. if(!in_array($field, array('recommend_status', 'sign_status'))) {
  41. exit('非法操作');
  42. }
  43. pdo_update('mc_card', array($field => intval($_GPC['status'])), array('uniacid' => $_W['uniacid']));
  44. }
  45. exit('success');
  46. }
  47. if($do == 'editor') {
  48. uni_user_permission_check('mc_card_editor');
  49. if (!empty($_GPC['wapeditor'])) {
  50. $params = $_GPC['wapeditor']['params'];
  51. if (empty($params)) {
  52. message('请您先设计手机端页面.', '', 'error');
  53. }
  54. $params = json_decode(ihtml_entity_decode($params), true);
  55. if (empty($params)) {
  56. message('请您先设计手机端页面.', '', 'error');
  57. }
  58. if (!empty($params)) {
  59. foreach ($params as $key => &$value) {
  60. $params_new[$value['id']] = $value;
  61. if ($value['id'] == 'cardRecharge') {
  62. $recharges_key = $key;
  63. }
  64. if ($value['id'] == 'cardBasic') {
  65. $value['params']['description'] = str_replace(array("\r\n", "\n"), '<br/>', $value['params']['description']);
  66. $value['originParams']['description'] = str_replace(array("\r\n", "\n"), '<br/>', $value['originParams']['description']);
  67. }
  68. }
  69. }
  70. if (!empty($params[$recharges_key])) {
  71. foreach ($params[$recharges_key]['params']['recharges'] as &$row) {
  72. if ($row['backtype'] == '0') {
  73. $row['backunit'] = '元';
  74. } else {
  75. $row['backunit'] = '积分';
  76. }
  77. }
  78. }
  79. $html = htmlspecialchars_decode($_GPC['wapeditor']['html'], ENT_QUOTES);
  80. $html = str_replace(array("{\$_W['uniacid']}", "{\$_W['acid']}"), array($_W['uniacid'], $_W['acid']), $html);
  81. $basic = $params_new['cardBasic']['params'];
  82. $activity = $params_new['cardActivity']['params'];
  83. $nums = $params_new['cardNums']['params'];
  84. $times = $params_new['cardTimes']['params'];
  85. $recharges = $params_new['cardRecharge']['params'];
  86. $title = trim($basic['title']) ? trim($basic['title']) : message('名称不能为空');
  87. $format_type = 1;
  88. $format = trim($basic['format']);
  89. if(!empty($basic['fields'])) {
  90. foreach($basic['fields'] as $field) {
  91. if(!empty($field['title']) && !empty($field['bind'])) {
  92. $fields[] = $field;
  93. }
  94. }
  95. }
  96. if($basic['background']['type'] == 'system') {
  97. $image = pathinfo($basic['background']['image']);
  98. $basic['background']['image'] = $image['filename'];
  99. }
  100. if (!empty($recharges['recharges'])) {
  101. foreach ($recharges['recharges'] as $row) {
  102. if ($recharges['recharge_type'] == 1 && ($row['condition'] <= 0 || $row['back'] <= 0)) {
  103. message('充值优惠设置数值不能为负数或零', referer(), 'error');
  104. }
  105. }
  106. }
  107. if ($activity['grant_rate'] < 0) {
  108. message('付款返积分比率不能为负数', referer(), 'error');
  109. }
  110. $update = array(
  111. 'title' => $title,
  112. 'format_type' => $basic['format_type'],
  113. 'format' => $format,
  114. 'color' => iserializer($basic['color']),
  115. 'background' => iserializer(array(
  116. 'background' => $basic['background']['type'],
  117. 'image' => $basic['background']['image'],
  118. )),
  119. 'logo' => $basic['logo'],
  120. 'description' => trim($basic['description']),
  121. 'grant_rate' => intval($activity['grant_rate']),
  122. 'offset_rate' => intval($basic['offset_rate']),
  123. 'offset_max' => intval($basic['offset_max']),
  124. 'fields' => iserializer($fields),
  125. 'grant' => iserializer(
  126. array(
  127. 'credit1' => intval($basic['grant']['credit1']),
  128. 'credit2' => intval($basic['grant']['credit2']),
  129. 'coupon' => $basic['grant']['coupon'],
  130. )
  131. ),
  132. 'discount_type' => intval($activity['discount_type']),
  133. 'nums_status' => intval($nums['nums_status']),
  134. 'nums_text' => trim($nums['nums_text']),
  135. 'times_status' => intval($times['times_status']),
  136. 'times_text' => trim($times['times_text']),
  137. 'params' => json_encode($params),
  138. 'html' => $html
  139. );
  140. $grant = iunserializer($update['grant']);
  141. if ($grant['credit1'] < 0 || $grant['credit2'] < 0) {
  142. message('领卡赠送积分或余额不能为负数', referer(), 'error');
  143. }
  144. if ($update['offset_rate'] < 0 || $update['offset_max'] < 0) {
  145. message('抵现比率的数值不能为负数或零', referer(), 'error');
  146. }
  147. if($update['discount_type'] != 0 && !empty($activity['discounts'])) {
  148. $update['discount'] = array();
  149. foreach($activity['discounts'] as $discount) {
  150. if ($update['discount_type'] == 1) {
  151. if (!empty($discount['condition_1']) || !empty($discount['discount_1'])) {
  152. if ($discount['condition_1'] < 0 || $discount['discount_1'] < 0) {
  153. message('消费优惠设置数值不能为负数', referer(), 'error');
  154. }
  155. }
  156. } else {
  157. if (!empty($discount['condition_2']) || !empty($discount['discount_2'])) {
  158. if ($discount['condition_2'] < 0 || $discount['discount_2'] < 0) {
  159. message('消费优惠设置数值不能为负数', referer(), 'error');
  160. }
  161. }
  162. }
  163. $groupid = intval($discount['groupid']);
  164. if($groupid <= 0) continue;
  165. $update['discount'][$groupid] = array(
  166. 'condition_1' => trim($discount['condition_1']),
  167. 'discount_1' => trim($discount['discount_1']),
  168. 'condition_2' => trim($discount['condition_2']),
  169. 'discount_2' => trim($discount['discount_2']),
  170. );
  171. }
  172. $update['discount'] = iserializer($update['discount']);
  173. }
  174. if($update['nums_status'] != 0 && !empty($nums['nums'])) {
  175. $update['nums'] = array();
  176. foreach($nums['nums'] as $row) {
  177. if ($row['num'] <= 0 || $row['recharge'] <= 0) {
  178. message('充值返次数设置不能为负数或零', referer(), 'error');
  179. }
  180. $num = floatval($row['num']);
  181. $recharge = trim($row['recharge']);
  182. if($num <= 0 || $recharge <= 0) continue;
  183. $update['nums'][$recharge] = array(
  184. 'recharge' => $recharge,
  185. 'num' => $num
  186. );
  187. }
  188. $update['nums'] = iserializer($update['nums']);
  189. }
  190. if($update['times_status'] != 0 && !empty($times['times'])) {
  191. $update['times'] = array();
  192. foreach($times['times'] as $row) {
  193. if ($row['time'] <= 0 || $row['recharge'] <= 0) {
  194. message('充值返时长设置不能为负数或零', referer(), 'error');
  195. }
  196. $time = intval($row['time']);
  197. $recharge = trim($row['recharge']);
  198. if($time <= 0 || $recharge <= 0) continue;
  199. $update['times'][$recharge] = array(
  200. 'recharge' => $recharge,
  201. 'time' => $time
  202. );
  203. }
  204. $update['times'] = iserializer($update['times']);
  205. }
  206. if (!empty($setting)) {
  207. pdo_update('mc_card', $update, array('uniacid' => $_W['uniacid']));
  208. } else {
  209. $update['status'] = '1';
  210. $update['uniacid'] = $_W['uniacid'];
  211. pdo_insert('mc_card', $update);
  212. }
  213. message('会员卡设置成功!', url('mc/card/editor'), 'success');
  214. }
  215. $unisetting = uni_setting_load('creditnames');
  216. $fields_temp = mc_acccount_fields();
  217. $fields = array();
  218. foreach($fields_temp as $key => $val) {
  219. $fields[$key] = array(
  220. 'title' => $val,
  221. 'bind' => $key
  222. );
  223. }
  224. $params = json_decode($setting['params'], true);
  225. if (!empty($params)) {
  226. foreach ($params as $key => &$value) {
  227. if ($value['id'] == 'cardBasic') {
  228. $value['params']['description'] = str_replace("<br/>", "\n", $value['params']['description']);
  229. }
  230. $card_params[$key] = $value;
  231. $params_new[$value['id']] = $value;
  232. }
  233. }
  234. $setting['params'] = json_encode($card_params);
  235. $discounts_params = $params_new['cardActivity']['params']['discounts'];
  236. $discounts_temp = array();
  237. if(!empty($discounts_params)) {
  238. foreach($discounts_params as $row) {
  239. $discounts_temp[$row['groupid']] = $row;
  240. }
  241. }
  242. $discounts = array();
  243. foreach($_W['account']['groups'] as $group) {
  244. $discounts[$group['groupid']] = array(
  245. 'groupid' => $group['groupid'],
  246. 'title' => $group['title'],
  247. 'credit' => $group['credit'],
  248. 'condition_1' => $discounts_temp[$group['groupid']]['condition_1'],
  249. 'discount_1' => $discounts_temp[$group['groupid']]['discount_1'],
  250. 'condition_2' => $discounts_temp[$group['groupid']]['condition_2'],
  251. 'discount_2' => $discounts_temp[$group['groupid']]['discount_2'],
  252. );
  253. }
  254. $setting['params'] = preg_replace('/\n/', '', $setting['params']);
  255. template('mc/card-editor');
  256. exit();
  257. }
  258. if ($do == 'manage') {
  259. uni_user_permission_check('mc_card_manage');
  260. $cardid = intval($_GPC['cardid']);
  261. if ($_W['ispost']) {
  262. $status = array('status' => intval($_GPC['status']));
  263. if (false === pdo_update('mc_card_members', $status, array('uniacid' => $_W['uniacid'], 'id' => $cardid))) {
  264. exit('error');
  265. }
  266. exit('success');
  267. }
  268. if ($setting['status'] == 0) {
  269. message('会员卡功能未开启', url('mc/card/editor'), 'error');
  270. }
  271. $pindex = max(1, intval($_GPC['page']));
  272. $psize = 10;
  273. $param = array(':uniacid' => $_W['uniacid']);
  274. $cardsn = trim($_GPC['cardsn']);
  275. if(!empty($cardsn)) {
  276. $where .= ' AND a.cardsn LIKE :cardsn';
  277. $param[':cardsn'] = "%{$cardsn}%";
  278. }
  279. $status = isset($_GPC['status']) ? intval($_GPC['status']) : -1;
  280. if ($status >= 0) {
  281. $where .= " AND a.status = :status";
  282. $param[':status'] = $status;
  283. }
  284. $num = isset($_GPC['num']) ? intval($_GPC['num']) : -1;
  285. if($num >= 0) {
  286. if(!$num) {
  287. $where .= " AND a.nums = 0";
  288. } else {
  289. $where .= " AND a.nums > 0";
  290. }
  291. }
  292. $endtime = isset($_GPC['endtime']) ? intval($_GPC['endtime']) : -1;
  293. if($endtime >= 0) {
  294. $where .= " AND a.endtime <= :endtime";
  295. $param[':endtime'] = strtotime($endtime . 'days');
  296. }
  297. $keyword = trim($_GPC['keyword']);
  298. if(!empty($keyword)) {
  299. $where .= " AND (b.mobile LIKE '%{$keyword}%' OR b.realname LIKE '%{$keyword}%')";
  300. }
  301. $sql = 'SELECT a.*, b.realname, b.groupid, b.credit1, b.credit2, b.mobile FROM ' . tablename('mc_card_members') . " AS a LEFT JOIN " . tablename('mc_members') . " AS b ON a.uid = b.uid WHERE a.uniacid = :uniacid $where ORDER BY a.id DESC LIMIT ".($pindex - 1) * $psize.','.$psize;
  302. $list = pdo_fetchall($sql, $param);
  303. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_card_members') . " AS a LEFT JOIN " . tablename('mc_members') . " AS b ON a.uid = b.uid WHERE a.uniacid = :uniacid $where", $param);
  304. $pager = pagination($total, $pindex, $psize);
  305. template('mc/card');
  306. }
  307. if ($do == 'delete') {
  308. $cardid = intval($_GPC['cardid']);
  309. if (pdo_delete('mc_card_members',array('id' =>$cardid))) {
  310. message('删除会员卡成功',url('mc/card/manage'),'success');
  311. } else {
  312. message('删除会员卡失败',url('mc/card/manage'),'error');
  313. }
  314. }
  315. if($do == 'coupon') {
  316. $title = trim($_GPC['keyword']);
  317. $condition = ' WHERE uniacid = :uniacid AND (amount-dosage>0) AND starttime <= :time AND endtime >= :time';
  318. $param = array(
  319. ':uniacid' => $_W['uniacid'],
  320. ':time' => TIMESTAMP,
  321. );
  322. $data = pdo_fetchall('SELECT * FROM ' . tablename('activity_coupon') . $condition, $param);
  323. if(empty($data)) {
  324. exit('empty');
  325. }
  326. template('mc/coupon-model');
  327. exit();
  328. }
  329. if($do == 'modal') {
  330. $uid = intval($_GPC['uid']);
  331. $setting = pdo_get('mc_card', array('uniacid' => $_W['uniacid']));
  332. $card = pdo_get('mc_card_members', array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  333. if(empty($card)) {
  334. exit('error');
  335. }
  336. template('mc/card-model');
  337. exit();
  338. }
  339. if($do == 'submit') {
  340. load()->model('mc');
  341. $uid = intval($_GPC['uid']);
  342. $setting = pdo_get('mc_card', array('uniacid' => $_W['uniacid']));
  343. $card = pdo_get('mc_card_members', array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  344. if(empty($card)) {
  345. message('用户会员卡信息不存在', referer(), 'error');
  346. }
  347. $type = trim($_GPC['type']);
  348. if($type == 'nums_plus') {
  349. $fee = floatval($_GPC['fee']);
  350. $tag = intval($_GPC['nums']);
  351. if(!$fee && !$tag) {
  352. message('请完善充值金额和充值次数', referer(), 'error');
  353. }
  354. $total_num = $card['nums'] + $tag;
  355. pdo_update('mc_card_members', array('nums' => $total_num), array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  356. $log = array(
  357. 'uniacid' => $_W['uniacid'],
  358. 'uid' => $uid,
  359. 'type' => 'nums',
  360. 'model' => 1,
  361. 'fee' => $fee,
  362. 'tag' => $tag,
  363. 'addtime' => TIMESTAMP,
  364. 'note' => date('Y-m-d H:i') . "充值{$fee}元,管理员手动添加{$tag}次,添加后总次数为{$total_num}次",
  365. 'remark' => trim($_GPC['remark']),
  366. );
  367. pdo_insert('mc_card_record', $log);
  368. mc_notice_nums_plus($card['openid'], $setting['nums_text'], $tag, $total_num);
  369. }
  370. if($type == 'nums_times') {
  371. $tag = intval($_GPC['nums']);
  372. if(!$tag) {
  373. message('请填写消费次数', referer(), 'error');
  374. }
  375. if($card['nums'] < $tag) {
  376. message('当前用户的消费次数不够', referer(), 'error');
  377. }
  378. $total_num = $card['nums'] - $tag;
  379. pdo_update('mc_card_members', array('nums' => $total_num), array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  380. $log = array(
  381. 'uniacid' => $_W['uniacid'],
  382. 'uid' => $uid,
  383. 'type' => 'nums',
  384. 'model' => 2,
  385. 'fee' => 0,
  386. 'tag' => $tag,
  387. 'addtime' => TIMESTAMP,
  388. 'note' => date('Y-m-d H:i') . "消费1次,管理员手动减1次,消费后总次数为{$total_num}次",
  389. 'remark' => trim($_GPC['remark']),
  390. );
  391. pdo_insert('mc_card_record', $log);
  392. mc_notice_nums_times($card['openid'], $card['cardsn'], $setting['nums_text'], $total_num);
  393. }
  394. if($type == 'times_plus') {
  395. $fee = floatval($_GPC['fee']);
  396. $endtime = strtotime($_GPC['endtime']);
  397. $days = intval($_GPC['days']);
  398. if($endtime <= $card['endtime'] && !$days) {
  399. message('服务到期时间不能小于会员当前的服务到期时间或未填写延长服务天数', '', 'error');
  400. }
  401. $tag = floor(($endtime - $card['endtime']) / 86400);
  402. if($days > 0) {
  403. $tag = $days;
  404. if($card['endtime'] > TIMESTAMP) {
  405. $endtime = $card['endtime'] + $days * 86400;
  406. } else {
  407. $endtime = strtotime($days . 'days');
  408. }
  409. }
  410. pdo_update('mc_card_members', array('endtime' => $endtime), array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  411. $endtime = date('Y-m-d', $endtime);
  412. $log = array(
  413. 'uniacid' => $_W['uniacid'],
  414. 'uid' => $uid,
  415. 'type' => 'times',
  416. 'model' => 1,
  417. 'fee' => $fee,
  418. 'tag' => $tag,
  419. 'addtime' => TIMESTAMP,
  420. 'note' => date('Y-m-d H:i') . "充值{$fee}元,管理员手动设置{$setting['times_text']}到期时间为{$endtime},设置之前的{$setting['times_text']}到期时间为".date('Y-m-d', $card['endtime']),
  421. 'remark' => trim($_GPC['remark']),
  422. );
  423. pdo_insert('mc_card_record', $log);
  424. mc_notice_times_plus($card['openid'], $card['cardsn'], $setting['times_text'], $fee, $tag, $endtime);
  425. }
  426. if($type == 'times_times') {
  427. $endtime = strtotime($_GPC['endtime']);
  428. if($endtime > $card['endtime']) {
  429. message("该会员的{$setting['times_text']}到期时间为:" . date('Y-m-d', $card['endtime']) . ",您当前在进行消费操作,设置到期时间不能超过" . date('Y-m-d', $card['endtime']) , '', 'error');
  430. }
  431. $flag = intval($_GPC['flag']);
  432. if($flag) {
  433. $endtime = TIMESTAMP;
  434. }
  435. $tag = floor(($card['endtime'] - $endtime) / 86400);
  436. pdo_update('mc_card_members', array('endtime' => $endtime), array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  437. $endtime = date('Y-m-d', $endtime);
  438. $log = array(
  439. 'uniacid' => $_W['uniacid'],
  440. 'uid' => $uid,
  441. 'type' => 'times',
  442. 'model' => 2,
  443. 'fee' => 0,
  444. 'tag' => $tag,
  445. 'addtime' => TIMESTAMP,
  446. 'note' => date('Y-m-d H:i') . "管理员手动设置{$setting['times_text']}到期时间为{$endtime},设置之前的{$setting['times_text']}到期时间为".date('Y-m-d', $card['endtime']),
  447. 'remark' => trim($_GPC['remark']),
  448. );
  449. pdo_insert('mc_card_record', $log);
  450. mc_notice_times_times($card['openid'], "您好,您的{$setting['times_text']}到期时间已变更", $setting['times_text'], $endtime);
  451. }
  452. message('操作成功', referer(), 'success');
  453. }
  454. if($do == 'record') {
  455. $uid = intval($_GPC['uid']);
  456. $card = pdo_get('mc_card_members', array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  457. $where = ' WHERE uniacid = :uniacid AND uid = :uid';
  458. $param = array(':uniacid' => $_W['uniacid'], ':uid' => $uid);
  459. $type = trim($_GPC['type']);
  460. if(!empty($type)) {
  461. $where .= ' AND type = :type';
  462. $param[':type'] = $type;
  463. }
  464. if(empty($_GPC['endtime']['start'])) {
  465. $starttime = strtotime('-30 days');
  466. $endtime = TIMESTAMP;
  467. } else {
  468. $starttime = strtotime($_GPC['endtime']['start']);
  469. $endtime = strtotime($_GPC['endtime']['end']) + 86399;
  470. }
  471. $where .= ' AND addtime >= :starttime AND addtime <= :endtime';
  472. $param[':starttime'] = $starttime;
  473. $param[':endtime'] = $endtime;
  474. $pindex = max(1, intval($_GPC['page']));
  475. $psize = 30;
  476. $limit = " ORDER BY id DESC LIMIT " . ($pindex -1) * $psize . ", {$psize}";
  477. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_card_record') . " {$where}", $param);
  478. $list = pdo_fetchall('SELECT * FROM ' . tablename('mc_card_record') . " {$where} {$limit}", $param);
  479. $pager = pagination($total, $pindex, $psize);
  480. template('mc/card');
  481. }
  482. if($do == 'notice') {
  483. uni_user_permission_check('mc_card_other');
  484. $op = trim($_GPC['op']) ? trim($_GPC['op']) : 'list';
  485. if($op == 'list') {
  486. $pindex = max(1, intval($_GPC['page']));
  487. $psize = 30;
  488. $limit = " ORDER BY id DESC LIMIT " . ($pindex -1) * $psize . ", {$psize}";
  489. $addtime = intval($_GPC['addtime']);
  490. $where = ' WHERE uniacid = :uniacid AND type = 1';
  491. $param = array(':uniacid' => $_W['uniacid']);
  492. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_card_notices') . " {$where}", $param);
  493. $notices = pdo_fetchall('SELECT * FROM ' . tablename('mc_card_notices') . " {$where} {$limit}", $param);
  494. $pager = pagination($total, $pindex, $psize);
  495. }
  496. if($op == 'post') {
  497. $id = intval($_GPC['id']);
  498. if($id > 0) {
  499. $notice = pdo_get('mc_card_notices', array('uniacid' => $_W['uniacid'], 'id' => $id));
  500. if(empty($notice)) {
  501. message('通知不存在或已被删除', referer(), 'error');
  502. }
  503. }
  504. if(checksubmit()) {
  505. $title = trim($_GPC['title']) ? trim($_GPC['title']) : message('通知标题不能为空');
  506. $content = trim($_GPC['content']) ? trim($_GPC['content']) : message('通知内容不能为空');
  507. $data = array(
  508. 'uniacid' => $_W['uniacid'],
  509. 'type' => 1,
  510. 'uid' => 0,
  511. 'title' => $title,
  512. 'thumb' => trim($_GPC['thumb']),
  513. 'groupid' => intval($_GPC['groupid']),
  514. 'content' => htmlspecialchars_decode($_GPC['content']),
  515. 'addtime' => TIMESTAMP
  516. );
  517. if($id > 0) {
  518. pdo_update('mc_card_notices', $data, array('uniacid' => $_W['uniacid'], 'id' => $id));
  519. } else {
  520. pdo_insert('mc_card_notices', $data);
  521. }
  522. message('发布通知成功', url('mc/card/notice') , 'success');
  523. }
  524. }
  525. if($op == 'del') {
  526. $id = intval($_GPC['id']);
  527. pdo_delete('mc_card_notices', array('uniacid' => $_W['uniacid'], 'id' => $id));
  528. message('删除成功', referer(), 'success');
  529. }
  530. template('mc/card-notice');
  531. }
  532. if ($do == 'sign') {
  533. uni_user_permission_check('mc_card_other');
  534. $op = trim($_GPC['op']) ? trim($_GPC['op']) : 'sign-credit';
  535. if ($op == 'sign-credit') {
  536. $set = pdo_get('mc_card_credit_set', array('uniacid' => $_W['uniacid']));
  537. if(empty($set)) {
  538. $set = array();
  539. } else {
  540. $set['sign'] = iunserializer($set['sign']);
  541. }
  542. if(checksubmit()) {
  543. $data = array(
  544. 'uniacid' => $_W['uniacid'],
  545. 'sign' => array(
  546. 'everydaynum' => intval($_GPC['sign']['everydaynum']),
  547. 'first_group_day' => intval($_GPC['sign']['first_group_day']),
  548. 'first_group_num' => intval($_GPC['sign']['first_group_num']),
  549. 'second_group_day' => intval($_GPC['sign']['second_group_day']),
  550. 'second_group_num' => intval($_GPC['sign']['second_group_num']),
  551. 'third_group_day' => intval($_GPC['sign']['third_group_day']),
  552. 'third_group_num' => intval($_GPC['sign']['third_group_num']),
  553. 'full_sign_num' => intval($_GPC['sign']['full_sign_num']),
  554. ),
  555. 'content' => htmlspecialchars_decode($_GPC['content']),
  556. );
  557. $data['sign'] = iserializer($data['sign']);
  558. if(empty($set['uniacid'])) {
  559. pdo_insert('mc_card_credit_set', $data);
  560. } else {
  561. pdo_update('mc_card_credit_set', $data, array('uniacid' => $_W['uniacid']));
  562. }
  563. message('积分策略更新成功', referer(), 'success');
  564. }
  565. }
  566. if ($op == 'record-list') {
  567. $pindex = max(1, intval($_GPC['page']));
  568. $psize = 10;
  569. $list = pdo_fetchall("SELECT * FROM ". tablename('mc_card_sign_record'). " WHERE uniacid = :uniacid ORDER BY id DESC LIMIT " . ($pindex - 1)*$psize. ','. $psize, array(':uniacid' => $_W['uniacid']));
  570. foreach ($list as $key => &$value){
  571. $value['addtime'] = date('Y-m-d H:i:s', $value['addtime']);
  572. $value['realname'] = pdo_fetchcolumn("SELECT realname FROM ". tablename('mc_members'). ' WHERE uniacid = :uniacid AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':uid' => $value['uid']));
  573. }
  574. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ". tablename('mc_card_sign_record'). " WHERE uniacid = :uniacid", array(':uniacid' => $_W['uniacid']));
  575. $pager = pagination($total, $pindex, $psize);
  576. }
  577. template('mc/card-sign');
  578. }
  579. if($do == 'other') {
  580. uni_user_permission_check('mc_card_other');
  581. template('mc/card-other');
  582. }