VirtualcardController.class.php 21 KB

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