VirtualcardController.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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 353399459@qq.com
  12. *
  13. */
  14. namespace Seller\Controller;
  15. /**
  16. * @author yj
  17. * @desc 虚拟卡密后台控制器
  18. * Class VirtualCardController
  19. * @package Seller\Controller
  20. */
  21. class VirtualcardController extends CommonController{
  22. protected function _initialize(){
  23. parent::_initialize();
  24. }
  25. public function index(){
  26. $_GET['goods_type'] = 'virtualcard';
  27. $Goods_controller = A('Goods');
  28. $Goods_controller->index();
  29. }
  30. public function addgoods()
  31. {
  32. $_GET['goods_type'] = 'virtualcard';
  33. $Goods_controller = A('Goods');
  34. $Goods_controller->addgoods();
  35. }
  36. public function edit()
  37. {
  38. $_GET['goods_type'] = 'virtualcard';
  39. $Goods_controller = A('Goods');
  40. $Goods_controller->edit();
  41. }
  42. /**
  43. * @author yj
  44. * @desc
  45. */
  46. public function config()
  47. {
  48. $_GPC = I('request.');
  49. if (IS_POST) {
  50. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  51. $data['isopen_virtualcard'] = isset($data['isopen_virtualcard']) ? $data['isopen_virtualcard']:0;
  52. //是否参与分销
  53. $data['virtualcard_is_takecommiss'] = isset($data['virtualcard_is_takecommiss']) ? $data['virtualcard_is_takecommiss']:0;
  54. //0 横向, 1左右布局
  55. $data['virtualcard_layout'] = isset($data['virtualcard_layout']) ? $data['virtualcard_layout']:0;
  56. $data['is_open_virtualcard_show'] = isset($data['is_open_virtualcard_show']) ? $data['is_open_virtualcard_show']:0;
  57. $data['virtualcard_name_modify'] = isset($data['virtualcard_name_modify']) ? $data['virtualcard_name_modify']:'';
  58. $data['iscan_virtualcard_refund'] = isset($data['iscan_virtualcard_refund']) ? $data['iscan_virtualcard_refund']:0;
  59. //兑换 防止刷 分钟
  60. $data['virtcard_flush_limit_miniter'] = isset($data['virtcard_flush_limit_miniter']) ? $data['virtcard_flush_limit_miniter']:0;
  61. //兑换错误几次
  62. $data['virtcard_flush_error_timers'] = isset($data['virtcard_flush_error_timers']) ? $data['virtcard_flush_error_timers']:0;
  63. //冻结几小时
  64. $data['virtcard_flush_error_timers'] = isset($data['virtcard_flush_error_timers']) ? $data['virtcard_flush_error_timers']:0;
  65. //礼品卡首页入口封面
  66. $data['virtualcard_index_coming_img'] = isset($data['virtualcard_index_coming_img']) ? $data['virtualcard_index_coming_img']:'';
  67. $data['virtcard_share_title'] = isset($data['virtcard_share_title']) ? $data['virtcard_share_title']:'';
  68. $data['virtcard_share_img'] = isset($data['virtcard_share_img']) ? $data['virtcard_share_img']:'';
  69. $data['virtcard_publish'] = isset($data['virtcard_publish']) ? $data['virtcard_publish']:'';
  70. $data['virtcard_top_banner'] = isset($data['virtcard_top_banner']) ? $data['virtcard_top_banner']:'';
  71. D('Seller/Config')->update($data);
  72. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  73. die();
  74. }
  75. $data = D('Seller/Config')->get_all_config();
  76. $this->data = $data;
  77. $this->display();
  78. }
  79. /**
  80. * @author yj
  81. * @desc 兑换码记录
  82. */
  83. public function exchange_code()
  84. {
  85. $_GPC = I('request.');
  86. $condition = ' ';
  87. $pindex = max(1, intval($_GPC['page']));
  88. $psize = 20;
  89. if (!empty($_GPC['keyword'])) {
  90. $_GPC['keyword'] = trim($_GPC['keyword']);
  91. $condition .= ' and code_name like "%'.$_GPC['keyword'].'%"';
  92. }
  93. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX') . "lionfish_comshop_virtualcard_codes
  94. WHERE 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  95. if( !empty($list) )
  96. {
  97. foreach( $list as &$val )
  98. {
  99. if( $val['effect_type'] == 0 )
  100. {
  101. $val['effect_name'] = '永久有效';
  102. }else if( $val['effect_type'] == 1 )
  103. {
  104. $val['effect_name'] = '购买后'.$val['effect_days'].'天有效';
  105. }
  106. $val['money_format'] = round( $val['code_money'], 2);
  107. $has_use_count = D('Seller/VirtualCard')->getCodeUsedCount( $val['id'] );
  108. $un_use_count = D('Seller/VirtualCard')->getCodeUnUseCount( $val['id'] );
  109. $invalid_count = D('Seller/VirtualCard')->getCodeinvalidCount( $val['id'] );
  110. $val['has_use_count'] = $has_use_count;
  111. $val['un_use_count'] = $un_use_count;
  112. $val['invalid_count'] = $invalid_count;
  113. $val['goods_count'] = D('Seller/VirtualCard')->getGoodsVirtualCardCountByCodeId( $val['id'] );
  114. }
  115. }
  116. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_virtualcard_codes WHERE 1 ' . $condition );
  117. $total = $total_arr[0]['count'];
  118. $pager = pagination2($total, $pindex, $psize);
  119. $this->list = $list;
  120. $this->pager = $pager;
  121. $this->_GPC = $_GPC;
  122. include $this->display();
  123. }
  124. /**
  125. * @author y
  126. * @desc 线下兑换码管理
  127. */
  128. public function exchange_offline()
  129. {
  130. $_GPC = I('request.');
  131. $condition = ' ';
  132. $pindex = max(1, intval($_GPC['page']));
  133. $psize = 20;
  134. if (!empty($_GPC['keyword'])) {
  135. $_GPC['keyword'] = trim($_GPC['keyword']);
  136. $condition .= ' and code_name like "%'.$_GPC['keyword'].'%"';
  137. }
  138. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX') . "lionfish_comshop_virtualcard_offlinecodes
  139. WHERE 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  140. if( !empty($list) )
  141. {
  142. foreach( $list as &$val )
  143. {
  144. if( $val['effect_type'] == 0 )
  145. {
  146. $val['effect_name'] = '永久有效';
  147. }else if( $val['effect_type'] == 1 )
  148. {
  149. $val['effect_name'] = date('Y-m-d H:i:s', $val['effect_end_time'] ).'前有效';
  150. }
  151. $val['money_format'] = round( $val['code_money'], 2);
  152. $val['has_use_count'] = M('lionfish_comshop_virtualcard_offlineusercode')->where( array('offlinecode_id' => $val['id'], 'state' => 1 ) )->count();
  153. $val['un_use_count'] = M('lionfish_comshop_virtualcard_offlineusercode')->where( array('offlinecode_id' => $val['id'], 'state' => 0 ) )->count();
  154. }
  155. }
  156. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_virtualcard_offlinecodes WHERE 1 ' . $condition );
  157. $total = $total_arr[0]['count'];
  158. $pager = pagination2($total, $pindex, $psize);
  159. $this->list = $list;
  160. $this->pager = $pager;
  161. $this->_GPC = $_GPC;
  162. include $this->display();
  163. }
  164. public function exchangeofflinerecord()
  165. {
  166. $code_id = I('request.code_id');
  167. $code_info = M('lionfish_comshop_virtualcard_offlinecodes')->where( array('id' => $code_id ) )->find();
  168. $_GPC = I('request.');
  169. $condition = ' and offlinecode_id = '.$code_id ;
  170. $pindex = max(1, intval($_GPC['page']));
  171. $psize = 20;
  172. if (!empty($_GPC['keyword'])) {
  173. $_GPC['keyword'] = trim($_GPC['keyword']);
  174. $condition .= ' and code like "%'.$_GPC['keyword'].'%"';
  175. }
  176. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX') . "lionfish_comshop_virtualcard_offlineusercode
  177. WHERE 1 " . $condition . ' order by state desc,id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  178. if( !empty($list) )
  179. {
  180. foreach( $list as &$val )
  181. {
  182. if( $val['state'] == 1 )
  183. {
  184. //user_id
  185. $mb_info = M('lionfish_comshop_member')->where( array('member_id' => $val['user_id'] ) )->find();
  186. $val['user_name'] = $mb_info['username'];
  187. $val['usedtime'] = date('Y-m-d H:i:s', $val['usedtime'] );
  188. }else{
  189. $val['user_name'] = '';
  190. $val['usedtime'] = '';
  191. }
  192. if( $val['state'] == 0 )
  193. {
  194. $val['state_name'] = '未使用';
  195. }else if( $val['state'] == 1 )
  196. {
  197. $val['state_name'] = '已使用';
  198. $val['usedtime'] = '永久有效';
  199. }
  200. }
  201. }
  202. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_virtualcard_offlineusercode WHERE 1 ' . $condition );
  203. $total = $total_arr[0]['count'];
  204. $pager = pagination2($total, $pindex, $psize);
  205. $this->code_info = $code_info;
  206. $this->list = $list;
  207. $this->pager = $pager;
  208. $this->code_id = $code_id;
  209. $this->_GPC = $_GPC;
  210. include $this->display();
  211. }
  212. public function exportofflinerecord()
  213. {
  214. $code_id = I('request.code_id');
  215. $offlinecode_info = M('lionfish_comshop_virtualcard_offlinecodes')->where( array('id' => $code_id ) )->find();
  216. //code_money
  217. $list = M('lionfish_comshop_virtualcard_offlineusercode')->where( array('offlinecode_id' => $code_id ) )->select();
  218. foreach ($list as &$row) {
  219. $row['code_money'] = $offlinecode_info['code_money'];
  220. if( $row['state'] == 1 )
  221. {
  222. //user_id
  223. $mb_info = M('lionfish_comshop_member')->where( array('member_id' => $row['user_id'] ) )->find();
  224. $row['user_name'] = $mb_info['username'];
  225. $row['usedtime'] = date('Y-m-d H:i:s', $row['usedtime'] );
  226. }else{
  227. $row['user_name'] = '';
  228. $row['usedtime'] = '';
  229. }
  230. if( $row['state'] == 0 )
  231. {
  232. $row['state_name'] = '未使用';
  233. }else if( $row['state'] == 1 )
  234. {
  235. $row['state_name'] = '已使用';
  236. }
  237. $row['addtime'] = date('Y-m-d H:i:s', $row['addtime'] );
  238. }
  239. $columns = array(
  240. array('title' => 'ID', 'field' => 'id', 'width' => 12),
  241. array('title' => '兑换码CODE', 'field' => 'code', 'width' => 12),
  242. array('title' => '面值', 'field' => 'code_money', 'width' => 12),
  243. array('title' => '是否使用', 'field' => 'state_name', 'width' => 12),
  244. array('title' => '使用人', 'field' => 'user_name', 'width' => 12),
  245. array('title' => '使用时间', 'field' => 'usedtime', 'width' => 24),
  246. array('title' => '生成时间', 'field' => 'addtime', 'width' => 24)
  247. );
  248. D('Seller/excel')->export($list, array('title' => '兑换码数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  249. }
  250. public function changeofflinecode()
  251. {
  252. $id = I('request.id');
  253. //ids
  254. if (empty($id)) {
  255. $ids = I('request.ids');
  256. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  257. }
  258. if (empty($id)) {
  259. show_json(0, array('message' => '参数错误'));
  260. }
  261. $type = I('request.type');
  262. $value = I('request.value');
  263. if (!(in_array($type, array('state')))) {
  264. show_json(0, array('message' => '参数错误'));
  265. }
  266. $items = M('lionfish_comshop_virtualcard_offlinecodes')->where( array('id' => array('in', $id)) )->select();
  267. foreach ($items as $item) {
  268. M('lionfish_comshop_virtualcard_offlinecodes')->where( array('id' => $item['id']) )->save( array($type => $value) );
  269. }
  270. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  271. }
  272. public function changecode()
  273. {
  274. $id = I('request.id');
  275. //ids
  276. if (empty($id)) {
  277. $ids = I('request.ids');
  278. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  279. }
  280. if (empty($id)) {
  281. show_json(0, array('message' => '参数错误'));
  282. }
  283. $type = I('request.type');
  284. $value = I('request.value');
  285. if (!(in_array($type, array('state')))) {
  286. show_json(0, array('message' => '参数错误'));
  287. }
  288. $items = M('lionfish_comshop_virtualcard_codes')->where( array('id' => array('in', $id)) )->select();
  289. foreach ($items as $item) {
  290. M('lionfish_comshop_virtualcard_codes')->where( array('id' => $item['id']) )->save( array($type => $value) );
  291. }
  292. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  293. }
  294. public function deleteofflineusercode()
  295. {
  296. M()->startTrans();
  297. $id = I('request.id');
  298. //ids
  299. if (empty($id)) {
  300. $ids = I('request.ids');
  301. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  302. }
  303. if (empty($id)) {
  304. M()->rollback();
  305. show_json(0, array('message' => '参数错误'));
  306. }
  307. M('lionfish_comshop_virtualcard_offlineusercode')->where( array('id' => array('in', $id)) )->delete();
  308. M()->commit();
  309. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  310. }
  311. public function deleteofflinecode()
  312. {
  313. M()->startTrans();
  314. $id = I('request.id');
  315. //ids
  316. if (empty($id)) {
  317. $ids = I('request.ids');
  318. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  319. }
  320. if (empty($id)) {
  321. M()->rollback();
  322. show_json(0, array('message' => '参数错误'));
  323. }
  324. M('lionfish_comshop_virtualcard_offlinecodes')->where( array('id' => array('in', $id)) )->delete();
  325. M('lionfish_comshop_virtualcard_offlineusercode')->where( array('offlinecode_id' => array('in', $id)) )->delete();
  326. M()->commit();
  327. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  328. }
  329. /**
  330. * @author yj
  331. * @desc 删除code
  332. */
  333. public function deletecode()
  334. {
  335. M()->startTrans();
  336. $id = I('request.id');
  337. //ids
  338. if (empty($id)) {
  339. $ids = I('request.ids');
  340. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  341. }
  342. if (empty($id)) {
  343. M()->rollback();
  344. show_json(0, array('message' => '参数错误'));
  345. }
  346. $items = M('lionfish_comshop_virtualcard_codes')->where( array('id' => array('in', $id)) )->select();
  347. foreach ($items as $item) {
  348. $goods_code_info = D('Seller/VirtualCard')->getGoodsVirtualCardInfoByCodeId( $item['id'] );
  349. if( !empty($goods_code_info) )
  350. {
  351. M()->rollback();
  352. show_json(0, array('message' => 'code:'.$item['code_name'].' 已关联商品,无法删除'));
  353. }
  354. M('lionfish_comshop_virtualcard_codes')->where( array('id' => $item['id']) )->delete();
  355. }
  356. M()->commit();
  357. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  358. }
  359. /**
  360. * @author yj
  361. * @desc 添加编辑兑换码
  362. */
  363. public function addCode()
  364. {
  365. $id = I('request.id');
  366. if (!empty($id)) {
  367. $item = M('lionfish_comshop_virtualcard_codes')->where( array('id' => $id) )->find();
  368. $this->item = $item;
  369. }
  370. if (IS_POST) {
  371. $data = I('request.data');
  372. if( empty($data['code_name']) )
  373. {
  374. show_json(0, array('message' => '兑换码名称不能为空' ));
  375. }
  376. if( $data['effect_type'] == 1 && ( empty($data['effect_days']) || $data['effect_days'] < 1 ) )
  377. {
  378. show_json(0, array('message' => '兑换码有效期必须大于1天' ));
  379. }
  380. if( ( empty($data['code_money']) || $data['code_money'] <= 0 ) )
  381. {
  382. show_json(0, array('message' => '兑换面额必须大于0元' ));
  383. }
  384. //show_json(0, array('message' => 'code:'.$item['code_name'].' 已关联商品,无法删除'));
  385. D('Seller/VirtualCard')->updateCode($data );
  386. if( empty($id) )
  387. {
  388. show_json(1 , array('url' => U('Virtualcard/exchange_code') ));
  389. }else{
  390. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  391. }
  392. }
  393. $this->display();
  394. }
  395. /**
  396. * @author yj
  397. * @desc 添加编辑兑换码
  398. */
  399. public function addofflineCode()
  400. {
  401. $id = I('request.id');
  402. if (!empty($id)) {
  403. $item = M('lionfish_comshop_virtualcard_offlinecodes')->where( array('id' => $id) )->find();
  404. $item['effect_end_time'] = date('Y-m-d H:i');
  405. $this->item = $item;
  406. }
  407. if (IS_POST) {
  408. $data = I('request.data');
  409. $data['effect_end_time'] = I('request.effect_end_time');
  410. if( empty($data['code_name']) )
  411. {
  412. show_json(0, array('message' => '线下兑换码名称不能为空' ));
  413. }
  414. if( $data['effect_type'] == 1 && ( empty($data['effect_end_time']) || strtotime($data['effect_end_time'].':00') < time() ) )
  415. {
  416. show_json(0, array('message' => '线下兑换码有效期必须大于当前时间'.strtotime($data['effect_end_time'].':00') ));
  417. }
  418. if( ( empty($data['code_money']) || $data['code_money'] <= 0 ) )
  419. {
  420. show_json(0, array('message' => '线下兑换面额必须大于0元' ));
  421. }
  422. if( intval( $data['code_quantity'] ) <= 0 )
  423. {
  424. show_json(0, array('message' => '生成数量必须大于0张' ));
  425. }
  426. if( intval( $data['code_quantity'] ) > 1000 )
  427. {
  428. show_json(0, array('message' => '生成数量必须小于1000张' ));
  429. }
  430. //show_json(0, array('message' => 'code:'.$item['code_name'].' 已关联商品,无法删除'));
  431. D('Seller/VirtualCard')->updateofflineCode($data );
  432. if( empty($id) )
  433. {
  434. show_json(1 , array('url' => U('Virtualcard/exchange_offline') ));
  435. }else{
  436. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  437. }
  438. }
  439. $this->display();
  440. }
  441. public function orderlist()
  442. {
  443. $_GET['virtualcard_order'] = '1';
  444. $Goods_controller = A('Order');
  445. $Goods_controller->index();
  446. }
  447. public function exchangerecord()
  448. {
  449. $_GPC = I('request.');
  450. $starttime_arr = I('get.time');
  451. $starttime = isset($starttime_arr['start']) ? strtotime($starttime_arr['start']) : strtotime(date('Y-m-d'.' 00:00:00')) - 86400 * 30;
  452. $endtime = isset($starttime_arr['end']) ? strtotime($starttime_arr['end']) : strtotime(date('Y-m-d'.' 23:59:59')) +1;
  453. $this->starttime = $starttime;
  454. $this->endtime = $endtime;
  455. $condition = " and addtime >= {$starttime} and addtime < {$endtime} ";
  456. $pindex = max(1, intval($_GPC['page']));
  457. $psize = 20;
  458. if (!empty($_GPC['keyword'])) {
  459. $_GPC['keyword'] = trim($_GPC['keyword']);
  460. $condition .= ' and code_sn like "%'.$_GPC['keyword'].'%"';
  461. }
  462. $code_id = $_GPC['code_id'];
  463. $this->code_id = $code_id;
  464. if( isset($code_id) && $code_id > 0 )
  465. {
  466. $condition .= " and code_id = {$code_id} ";
  467. }
  468. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX') . "lionfish_comshop_virtualcard_userecord
  469. WHERE 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  470. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_virtualcard_userecord WHERE 1 ' . $condition );
  471. $total = $total_arr[0]['count'];
  472. $pager = pagination2($total, $pindex, $psize);
  473. if( !empty($list) )
  474. {
  475. foreach( $list as $key => $val )
  476. {
  477. $order_virtualcard_info = M('lionfish_comshop_order_virtualcard')->where(['code_sn' => $val['code_sn']])->find();
  478. //buy_user_id
  479. $buy_user_id = $order_virtualcard_info['buy_user_id'];
  480. $buy_user_info = M('lionfish_comshop_member')->where(['member_id' => $buy_user_id ])->find();
  481. $use_user_id = $val['use_user_id'];
  482. $use_user_info = M('lionfish_comshop_member')->where(['member_id' => $use_user_id ])->find();
  483. //use_user_id
  484. $val['buy_user_info'] = $buy_user_info;
  485. $val['use_user_info'] = $use_user_info;
  486. $val['adddate'] = date('Y-m-d H:i:s', $val['addtime'] );
  487. $list[$key] = $val;
  488. }
  489. }
  490. $this->list = $list;
  491. $this->pager = $pager;
  492. $this->_GPC = $_GPC;
  493. include $this->display();
  494. }
  495. }
  496. ?>