predeposit.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. <?php
  2. /**
  3. * 预存款管理
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class predepositControl extends SystemControl{
  7. const EXPORT_SIZE = 1000;
  8. public function __construct(){
  9. parent::__construct();
  10. Language::read('predeposit');
  11. }
  12. /**
  13. * 充值列表
  14. */
  15. public function predepositOp(){
  16. $condition = array();
  17. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_date']);
  18. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_date']);
  19. $start_unixtime = $if_start_date ? strtotime($_GET['query_start_date']) : null;
  20. $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']): null;
  21. if ($start_unixtime || $end_unixtime) {
  22. $condition['pdr_add_time'] = array('time',array($start_unixtime,$end_unixtime));
  23. }
  24. if (!empty($_GET['mname'])){
  25. $condition['pdr_member_name'] = $_GET['mname'];
  26. }
  27. if ($_GET['paystate_search'] != ''){
  28. $condition['pdr_payment_state'] = $_GET['paystate_search'];
  29. }
  30. $model_pd = Model('predeposit');
  31. $recharge_list = $model_pd->getPdRechargeList($condition,20,'*','pdr_id desc');
  32. //信息输出
  33. Tpl::output('list',$recharge_list);
  34. Tpl::output('show_page',$model_pd->showpage());
  35. Tpl::showpage('pd.list');
  36. }
  37. /**
  38. * 充值编辑(更改成收到款)
  39. */
  40. public function recharge_editOp(){
  41. $id = intval($_GET['id']);
  42. if ($id <= 0){
  43. showMessage(Language::get('admin_predeposit_parameter_error'),'index.php?act=predeposit&op=predeposit','','error');
  44. }
  45. //查询充值信息
  46. $model_pd = Model('predeposit');
  47. $condition = array();
  48. $condition['pdr_id'] = $id;
  49. $condition['pdr_payment_state'] = 0;
  50. $info = $model_pd->getPdRechargeInfo($condition);
  51. if (empty($info)){
  52. showMessage(Language::get('admin_predeposit_record_error'),'index.php?act=predeposit&op=predeposit','','error');
  53. }
  54. if (!chksubmit()) {
  55. //显示支付接口列表
  56. $payment_list = Model('payment')->getPaymentOpenList();
  57. //去掉预存款和货到付款
  58. foreach ($payment_list as $key => $value){
  59. if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') {
  60. unset($payment_list[$key]);
  61. }
  62. }
  63. Tpl::output('payment_list',$payment_list);
  64. Tpl::output('info',$info);
  65. Tpl::showpage('pd.edit');
  66. exit();
  67. }
  68. //取支付方式信息
  69. $model_payment = Model('payment');
  70. $condition = array();
  71. $condition['payment_code'] = $_POST['payment_code'];
  72. $payment_info = $model_payment->getPaymentOpenInfo($condition);
  73. if(!$payment_info || $payment_info['payment_code'] == 'offline' || $payment_info['payment_code'] == 'offline') {
  74. showMessage(L('payment_index_sys_not_support'),'','html','error');
  75. }
  76. $condition = array();
  77. $condition['pdr_sn'] = $info['pdr_sn'];
  78. $condition['pdr_payment_state'] = 0;
  79. $update = array();
  80. $update['pdr_payment_state'] = 1;
  81. $update['pdr_payment_time'] = strtotime($_POST['payment_time']);
  82. $update['pdr_payment_code'] = $payment_info['payment_code'];
  83. $update['pdr_payment_name'] = $payment_info['payment_name'];
  84. $update['pdr_trade_sn'] = $_POST['trade_no'];
  85. $update['pdr_admin'] = $this->admin_info['name'];
  86. $log_msg = L('admin_predeposit_recharge_edit_state').','.L('admin_predeposit_sn').':'.$info['pdr_sn'];
  87. try {
  88. $model_pd->beginTransaction();
  89. //更改充值状态
  90. $state = $model_pd->editPdRecharge($update,$condition);
  91. if (!$state) {
  92. throw Exception(Language::get('predeposit_payment_pay_fail'));
  93. }
  94. //变更会员预存款
  95. $data = array();
  96. $data['member_id'] = $info['pdr_member_id'];
  97. $data['member_name'] = $info['pdr_member_name'];
  98. $data['amount'] = $info['pdr_amount'];
  99. $data['pdr_sn'] = $info['pdr_sn'];
  100. $data['admin_name'] = $this->admin_info['name'];
  101. $model_pd->changePd('recharge',$data);
  102. $model_pd->commit();
  103. $this->log($log_msg,1);
  104. showMessage(Language::get('admin_predeposit_recharge_edit_success'),'index.php?act=predeposit&op=predeposit');
  105. } catch (Exception $e) {
  106. $model_pd->rollback();
  107. $this->log($log_msg,0);
  108. showMessage($e->getMessage(),'index.php?act=predeposit&op=predeposit','html','error');
  109. }
  110. }
  111. /**
  112. * 充值查看
  113. */
  114. public function recharge_infoOp(){
  115. $id = intval($_GET['id']);
  116. if ($id <= 0){
  117. showMessage(Language::get('admin_predeposit_parameter_error'),'index.php?act=predeposit&op=predeposit','','error');
  118. }
  119. //查询充值信息
  120. $model_pd = Model('predeposit');
  121. $condition = array();
  122. $condition['pdr_id'] = $id;
  123. $info = $model_pd->getPdRechargeInfo($condition);
  124. if (empty($info)){
  125. showMessage(Language::get('admin_predeposit_record_error'),'index.php?act=predeposit&op=predeposit','','error');
  126. }
  127. Tpl::output('info',$info);
  128. Tpl::showpage('pd.info');
  129. }
  130. /**
  131. * 充值删除
  132. */
  133. public function recharge_delOp(){
  134. $pdr_id = intval($_GET["id"]);
  135. if ($pdr_id <= 0){
  136. showMessage(Language::get('admin_predeposit_parameter_error'),'index.php?act=predeposit&op=predeposit','','error');
  137. }
  138. $model_pd = Model('predeposit');
  139. $condition = array();
  140. $condition['pdr_id'] = "$pdr_id";
  141. $condition['pdr_payment_state'] = 0;
  142. $result = $model_pd->delPdRecharge($condition);
  143. if ($result){
  144. showMessage(Language::get('admin_predeposit_recharge_del_success'),'index.php?act=predeposit&op=predeposit');
  145. }else {
  146. showMessage(Language::get('admin_predeposit_recharge_del_fail'),'index.php?act=predeposit&op=predeposit','','error');
  147. }
  148. }
  149. /**
  150. * 预存款日志
  151. */
  152. public function pd_log_listOp(){
  153. $condition = array();
  154. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['stime']);
  155. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['etime']);
  156. $start_unixtime = $if_start_date ? strtotime($_GET['stime']) : null;
  157. $end_unixtime = $if_end_date ? strtotime($_GET['etime']): null;
  158. if ($start_unixtime || $end_unixtime) {
  159. $condition['lg_add_time'] = array('time',array($start_unixtime,$end_unixtime));
  160. }
  161. if (!empty($_GET['mname'])){
  162. $condition['lg_member_name'] = $_GET['mname'];
  163. }
  164. if (!empty($_GET['aname'])){
  165. $condition['lg_admin_name'] = $_GET['aname'];
  166. }
  167. $model_pd = Model('predeposit');
  168. $list_log = $model_pd->getPdLogList($condition,20,'*','lg_id desc');
  169. Tpl::output('show_page',$model_pd->showpage());
  170. Tpl::output('list_log',$list_log);
  171. Tpl::showpage('pd_log.list');
  172. }
  173. /**
  174. * 提现列表
  175. */
  176. public function pd_cash_listOp(){
  177. $condition = array();
  178. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['stime']);
  179. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['etime']);
  180. $start_unixtime = $if_start_date ? strtotime($_GET['stime']) : null;
  181. $end_unixtime = $if_end_date ? strtotime($_GET['etime']): null;
  182. if ($start_unixtime || $end_unixtime) {
  183. $condition['pdc_add_time'] = array('time',array($start_unixtime,$end_unixtime));
  184. }
  185. if (!empty($_GET['mname'])){
  186. $condition['pdc_member_name'] = $_GET['mname'];
  187. }
  188. if (!empty($_GET['pdc_bank_user'])){
  189. $condition['pdc_bank_user'] = $_GET['pdc_bank_user'];
  190. }
  191. if ($_GET['paystate_search'] != ''){
  192. $condition['pdc_payment_state'] = $_GET['paystate_search'];
  193. }
  194. $model_pd = Model('predeposit');
  195. $cash_list = $model_pd->getPdCashList($condition,20,'*','pdc_payment_state asc,pdc_id asc');
  196. Tpl::output('list',$cash_list);
  197. Tpl::output('show_page',$model_pd->showpage());
  198. Tpl::showpage('pd_cash.list');
  199. }
  200. /**
  201. * 删除提现记录
  202. */
  203. public function pd_cash_delOp(){
  204. $pdc_id = intval($_GET["id"]);
  205. if ($pdc_id <= 0){
  206. showMessage(Language::get('admin_predeposit_parameter_error'),'index.php?act=predeposit&op=pd_cash_list','','error');
  207. }
  208. $model_pd = Model('predeposit');
  209. $condition = array();
  210. $condition['pdc_id'] = $pdc_id;
  211. $condition['pdc_payment_state'] = 0;
  212. $info = $model_pd->getPdCashInfo($condition);
  213. if (!$info) {
  214. showMessage(Language::get('admin_predeposit_parameter_error'),'index.php?act=predeposit&op=pd_cash_list','','error');
  215. }
  216. try {
  217. $result = $model_pd->delPdCash($condition);
  218. if (!$result) {
  219. throw new Exception(Language::get('admin_predeposit_cash_del_fail'));
  220. }
  221. //退还冻结的预存款
  222. $model_member = Model('member');
  223. $member_info = $model_member->getMemberInfo(array('member_id'=>$info['pdc_member_id']));
  224. //扣除冻结的预存款
  225. $admininfo = $this->getAdminInfo();
  226. $data = array();
  227. $data['member_id'] = $member_info['member_id'];
  228. $data['member_name'] = $member_info['member_name'];
  229. $data['amount'] = $info['pdc_amount'];
  230. $data['order_sn'] = $info['pdc_sn'];
  231. $data['admin_name'] = $admininfo['name'];
  232. $model_pd->changePd('cash_del',$data);
  233. $model_pd->commit();
  234. showMessage(Language::get('admin_predeposit_cash_del_success'),'index.php?act=predeposit&op=pd_cash_list');
  235. } catch (Exception $e) {
  236. $model_pd->commit();
  237. showMessage($e->getMessage(),'index.php?act=predeposit&op=pd_cash_list','html','error');
  238. }
  239. }
  240. /**
  241. * 更改提现为支付状态
  242. */
  243. public function pd_cash_payOp(){
  244. $id = intval($_GET['id']);
  245. if ($id <= 0){
  246. showMessage(Language::get('admin_predeposit_parameter_error'),'index.php?act=predeposit&op=pd_cash_list','','error');
  247. }
  248. $model_pd = Model('predeposit');
  249. $condition = array();
  250. $condition['pdc_id'] = $id;
  251. $condition['pdc_payment_state'] = 0;
  252. $info = $model_pd->getPdCashInfo($condition);
  253. if (!is_array($info) || count($info)<0){
  254. showMessage(Language::get('admin_predeposit_record_error'),'index.php?act=predeposit&op=pd_cash_list','','error');
  255. }
  256. //查询用户信息
  257. $model_member = Model('member');
  258. $member_info = $model_member->getMemberInfo(array('member_id'=>$info['pdc_member_id']));
  259. $update = array();
  260. $admininfo = $this->getAdminInfo();
  261. $update['pdc_payment_state'] = 1;
  262. $update['pdc_payment_admin'] = $admininfo['name'];
  263. $update['pdc_payment_time'] = time();
  264. $log_msg = L('admin_predeposit_cash_edit_state').','.L('admin_predeposit_cs_sn').':'.$info['pdc_sn'];
  265. try {
  266. $model_pd->beginTransaction();
  267. $result = $model_pd->editPdCash($update,$condition);
  268. if (!$result) {
  269. throw new Exception(Language::get('admin_predeposit_cash_edit_fail'));
  270. }
  271. //扣除冻结的预存款
  272. $data = array();
  273. $data['member_id'] = $member_info['member_id'];
  274. $data['member_name'] = $member_info['member_name'];
  275. $data['amount'] = $info['pdc_amount'];
  276. $data['order_sn'] = $info['pdc_sn'];
  277. $data['admin_name'] = $admininfo['name'];
  278. $model_pd->changePd('cash_pay',$data);
  279. $model_pd->commit();
  280. $this->log($log_msg,1);
  281. showMessage(Language::get('admin_predeposit_cash_edit_success'),'index.php?act=predeposit&op=pd_cash_list');
  282. } catch (Exception $e) {
  283. $model_pd->rollback();
  284. $this->log($log_msg,0);
  285. showMessage($e->getMessage(),'index.php?act=predeposit&op=pd_cash_list','html','error');
  286. }
  287. }
  288. /**
  289. * 查看提现信息
  290. */
  291. public function pd_cash_viewOp(){
  292. $id = intval($_GET['id']);
  293. if ($id <= 0){
  294. showMessage(Language::get('admin_predeposit_parameter_error'),'index.php?act=predeposit&op=pd_cash_list','','error');
  295. }
  296. $model_pd = Model('predeposit');
  297. $condition = array();
  298. $condition['pdc_id'] = $id;
  299. $info = $model_pd->getPdCashInfo($condition);
  300. if (!is_array($info) || count($info)<0){
  301. showMessage(Language::get('admin_predeposit_record_error'),'index.php?act=predeposit&op=pd_cash_list','','error');
  302. }
  303. Tpl::output('info',$info);
  304. Tpl::showpage('pd_cash.view');
  305. }
  306. /**
  307. * 导出预存款充值记录
  308. *
  309. */
  310. public function export_step1Op(){
  311. $condition = array();
  312. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_date']);
  313. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_date']);
  314. $start_unixtime = $if_start_date ? strtotime($_GET['query_start_date']) : null;
  315. $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']): null;
  316. if ($start_unixtime || $end_unixtime) {
  317. $condition['pdr_add_time'] = array('time',array($start_unixtime,$end_unixtime));
  318. }
  319. if (!empty($_GET['mname'])){
  320. $condition['pdr_member_name'] = $_GET['mname'];
  321. }
  322. if ($_GET['paystate_search'] != ''){
  323. $condition['pdr_payment_state'] = $_GET['paystate_search'];
  324. }
  325. $model_pd = Model('predeposit');
  326. if (!is_numeric($_GET['curpage'])){
  327. $count = $model_pd->getPdRechargeCount($condition);
  328. $array = array();
  329. if ($count > self::EXPORT_SIZE ){ //显示下载链接
  330. $page = ceil($count/self::EXPORT_SIZE);
  331. for ($i=1;$i<=$page;$i++){
  332. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  333. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  334. $array[$i] = $limit1.' ~ '.$limit2 ;
  335. }
  336. Tpl::output('list',$array);
  337. Tpl::output('murl','index.php?act=predeposit&op=predeposit');
  338. Tpl::showpage('export.excel');
  339. }else{ //如果数量小,直接下载
  340. $data = $model_pd->getPdRechargeList($condition,'','*','pdr_id desc',self::EXPORT_SIZE);
  341. $rechargepaystate = array(0=>'未支付',1=>'已支付');
  342. foreach ($data as $k=>$v) {
  343. $data[$k]['pdr_payment_state'] = $rechargepaystate[$v['pdr_payment_state']];
  344. }
  345. $this->createExcel($data);
  346. }
  347. }else{ //下载
  348. $limit1 = ($_GET['curpage']-1) * self::EXPORT_SIZE;
  349. $limit2 = self::EXPORT_SIZE;
  350. $data = $model_pd->getPdRechargeList($condition,'','*','pdr_id desc',"{$limit1},{$limit2}");
  351. $rechargepaystate = array(0=>'未支付',1=>'已支付');
  352. foreach ($data as $k=>$v) {
  353. $data[$k]['pdr_payment_state'] = $rechargepaystate[$v['pdr_payment_state']];
  354. }
  355. $this->createExcel($data);
  356. }
  357. }
  358. /**
  359. * 生成导出预存款充值excel
  360. *
  361. * @param array $data
  362. */
  363. private function createExcel($data = array()){
  364. Language::read('export');
  365. import('libraries.excel');
  366. $excel_obj = new Excel();
  367. $excel_data = array();
  368. //设置样式
  369. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  370. //header
  371. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_no'));
  372. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_member'));
  373. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_ctime'));
  374. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_ptime'));
  375. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_pay'));
  376. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_money'));
  377. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_paystate'));
  378. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_yc_memberid'));
  379. foreach ((array)$data as $k=>$v){
  380. $tmp = array();
  381. $tmp[] = array('data'=>'NC'.$v['pdr_sn']);
  382. $tmp[] = array('data'=>$v['pdr_member_name']);
  383. $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['pdr_add_time']));
  384. if (intval($v['pdr_payment_time'])) {
  385. if (date('His',$v['pdr_payment_time']) == 0) {
  386. $tmp[] = array('data'=>date('Y-m-d',$v['pdr_payment_time']));
  387. } else {
  388. $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['pdr_payment_time']));
  389. }
  390. } else {
  391. $tmp[] = array('data'=>'');
  392. }
  393. $tmp[] = array('data'=>$v['pdr_payment_name']);
  394. $tmp[] = array('format'=>'Number','data'=>ncPriceFormat($v['pdr_amount']));
  395. $tmp[] = array('data'=>$v['pdr_payment_state']);
  396. $tmp[] = array('data'=>$v['pdr_member_id']);
  397. $excel_data[] = $tmp;
  398. }
  399. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  400. $excel_obj->addArray($excel_data);
  401. $excel_obj->addWorksheet($excel_obj->charset(L('exp_yc_yckcz'),CHARSET));
  402. $excel_obj->generateXML($excel_obj->charset(L('exp_yc_yckcz'),CHARSET).$_GET['curpage'].'-'.date('Y-m-d-H',time()));
  403. }
  404. /**
  405. * 导出预存款提现记录
  406. *
  407. */
  408. public function export_cash_step1Op(){
  409. $condition = array();
  410. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['stime']);
  411. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['etime']);
  412. $start_unixtime = $if_start_date ? strtotime($_GET['stime']) : null;
  413. $end_unixtime = $if_end_date ? strtotime($_GET['etime']): null;
  414. if ($start_unixtime || $end_unixtime) {
  415. $condition['pdc_add_time'] = array('time',array($start_unixtime,$end_unixtime));
  416. }
  417. if (!empty($_GET['mname'])){
  418. $condition['pdc_member_name'] = $_GET['mname'];
  419. }
  420. if (!empty($_GET['pdc_bank_user'])){
  421. $condition['pdc_bank_user'] = $_GET['pdc_bank_user'];
  422. }
  423. if ($_GET['paystate_search'] != ''){
  424. $condition['pdc_payment_state'] = $_GET['paystate_search'];
  425. }
  426. $model_pd = Model('predeposit');
  427. if (!is_numeric($_GET['curpage'])){
  428. $count = $model_pd->getPdCashCount($condition);
  429. $array = array();
  430. if ($count > self::EXPORT_SIZE ){ //显示下载链接
  431. $page = ceil($count/self::EXPORT_SIZE);
  432. for ($i=1;$i<=$page;$i++){
  433. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  434. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  435. $array[$i] = $limit1.' ~ '.$limit2 ;
  436. }
  437. Tpl::output('list',$array);
  438. Tpl::output('murl','index.php?act=predeposit&op=pd_cash_list');
  439. Tpl::showpage('export.excel');
  440. }else{ //如果数量小,直接下载
  441. $data = $model_pd->getPdCashList($condition,'','*','pdc_id desc',self::EXPORT_SIZE);
  442. $cashpaystate = array(0=>'未支付',1=>'已支付');
  443. foreach ($data as $k=>$v) {
  444. $data[$k]['pdc_payment_state'] = $cashpaystate[$v['pdc_payment_state']];
  445. }
  446. $this->createCashExcel($data);
  447. }
  448. }else{ //下载
  449. $limit1 = ($_GET['curpage']-1) * self::EXPORT_SIZE;
  450. $limit2 = self::EXPORT_SIZE;
  451. $data = $model_pd->getPdCashList($condition,'','*','pdc_id desc',"{$limit1},{$limit2}");
  452. $cashpaystate = array(0=>'未支付',1=>'已支付');
  453. foreach ($data as $k=>$v) {
  454. $data[$k]['pdc_payment_state'] = $cashpaystate[$v['pdc_payment_state']];
  455. }
  456. $this->createCashExcel($data);
  457. }
  458. }
  459. /**
  460. * 生成导出预存款提现excel
  461. *
  462. * @param array $data
  463. */
  464. private function createCashExcel($data = array()){
  465. Language::read('export');
  466. import('libraries.excel');
  467. $excel_obj = new Excel();
  468. $excel_data = array();
  469. //设置样式
  470. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  471. //header
  472. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_tx_no'));
  473. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_tx_member'));
  474. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_tx_money'));
  475. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_tx_ctime'));
  476. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_tx_state'));
  477. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_tx_memberid'));
  478. foreach ((array)$data as $k=>$v){
  479. $tmp = array();
  480. $tmp[] = array('data'=>'NC'.$v['pdc_sn']);
  481. $tmp[] = array('data'=>$v['pdc_member_name']);
  482. $tmp[] = array('format'=>'Number','data'=>ncPriceFormat($v['pdc_amount']));
  483. $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['pdc_add_time']));
  484. $tmp[] = array('data'=>$v['pdc_payment_state']);
  485. $tmp[] = array('data'=>$v['pdc_member_id']);
  486. $excel_data[] = $tmp;
  487. }
  488. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  489. $excel_obj->addArray($excel_data);
  490. $excel_obj->addWorksheet($excel_obj->charset(L('exp_tx_title'),CHARSET));
  491. $excel_obj->generateXML($excel_obj->charset(L('exp_tx_title'),CHARSET).$_GET['curpage'].'-'.date('Y-m-d-H',time()));
  492. }
  493. /**
  494. * 预存款明细信息导出
  495. */
  496. public function export_mx_step1Op(){
  497. $condition = array();
  498. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['stime']);
  499. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['etime']);
  500. $start_unixtime = $if_start_date ? strtotime($_GET['stime']) : null;
  501. $end_unixtime = $if_end_date ? strtotime($_GET['etime']): null;
  502. if ($start_unixtime || $end_unixtime) {
  503. $condition['lg_add_time'] = array('time',array($start_unixtime,$end_unixtime));
  504. }
  505. if (!empty($_GET['mname'])){
  506. $condition['lg_member_name'] = $_GET['mname'];
  507. }
  508. if (!empty($_GET['aname'])){
  509. $condition['lg_admin_name'] = $_GET['aname'];
  510. }
  511. $model_pd = Model('predeposit');
  512. if (!is_numeric($_GET['curpage'])){
  513. $count = $model_pd->getPdLogCount($condition);
  514. $array = array();
  515. if ($count > self::EXPORT_SIZE ){ //显示下载链接
  516. $page = ceil($count/self::EXPORT_SIZE);
  517. for ($i=1;$i<=$page;$i++){
  518. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  519. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  520. $array[$i] = $limit1.' ~ '.$limit2 ;
  521. }
  522. Tpl::output('list',$array);
  523. Tpl::output('murl','index.php?act=predeposit&op=pd_log_list');
  524. Tpl::showpage('export.excel');
  525. }else{ //如果数量小,直接下载
  526. $data = $model_pd->getPdLogList($condition,'','*','lg_id desc',self::EXPORT_SIZE);
  527. $this->createmxExcel($data);
  528. }
  529. }else{ //下载
  530. $limit1 = ($_GET['curpage']-1) * self::EXPORT_SIZE;
  531. $limit2 = self::EXPORT_SIZE;
  532. $data = $model_pd->getPdLogList($condition,'','*','lg_id desc',"{$limit1},{$limit2}");
  533. $this->createmxExcel($data);
  534. }
  535. }
  536. /**
  537. * 导出预存款明细excel
  538. *
  539. * @param array $data
  540. */
  541. private function createmxExcel($data = array()){
  542. Language::read('export');
  543. import('libraries.excel');
  544. $excel_obj = new Excel();
  545. $excel_data = array();
  546. //设置样式
  547. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  548. //header
  549. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_mx_member'));
  550. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_mx_ctime'));
  551. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_mx_av_money'));
  552. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_mx_freeze_money'));
  553. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_mx_system'));
  554. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_mx_mshu'));
  555. foreach ((array)$data as $k=>$v){
  556. $tmp = array();
  557. $tmp[] = array('data'=>$v['lg_member_name']);
  558. $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['lg_add_time']));
  559. if (floatval($v['lg_av_amount']) == 0){
  560. $tmp[] = array('data'=>'');
  561. } else {
  562. $tmp[] = array('format'=>'Number','data'=>ncPriceFormat($v['lg_av_amount']));
  563. }
  564. if (floatval($v['lg_freeze_amount']) == 0){
  565. $tmp[] = array('data'=>'');
  566. } else {
  567. $tmp[] = array('format'=>'Number','data'=>ncPriceFormat($v['lg_freeze_amount']));
  568. }
  569. $tmp[] = array('data'=>$v['lg_admin_name']);
  570. $tmp[] = array('data'=>$v['lg_desc']);
  571. $excel_data[] = $tmp;
  572. }
  573. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  574. $excel_obj->addArray($excel_data);
  575. $excel_obj->addWorksheet($excel_obj->charset(L('exp_mx_rz'),CHARSET));
  576. $excel_obj->generateXML($excel_obj->charset(L('exp_mx_rz'),CHARSET).$_GET['curpage'].'-'.date('Y-m-d-H',time()));
  577. }
  578. //zmr>v20
  579. //显示添加余额页面
  580. public function predeposit_addOp(){
  581. if (chksubmit()){
  582. $this->add_money();
  583. }
  584. else
  585. {
  586. $model_pd = Model('predeposit');
  587. //信息输出
  588. Tpl::output('show_page',$model_pd->showpage());
  589. Tpl::showpage('predeposit.add');
  590. }
  591. }
  592. /**
  593. * 添加余额
  594. */
  595. public function add_money(){
  596. $obj_validate = new Validator();
  597. $obj_validate->validateparam = array(
  598. array("input"=>$_POST["member_id"], "require"=>"true", "message"=>Language::get('admin_points_member_error_again')),
  599. array("input"=>$_POST["pointsnum"], "require"=>"true",'validator'=>'Compare','operator'=>' >= ','to'=>1,"message"=>Language::get('admin_points_points_min_error'))
  600. );
  601. $error = $obj_validate->validate();
  602. if ($error != ''){
  603. showMessage($error,'','','error');
  604. }
  605. $money = abs(floatval($_POST['pointsnum']));
  606. $memo=trim($_POST['pointsdesc']);
  607. if ($money <= 0) {
  608. showMessage('输入的金额必需大于0','','html','error');
  609. }
  610. //查询会员信息
  611. $obj_member = Model('member');
  612. $member_id = intval($_POST['member_id']);
  613. $member_info = $obj_member->getMemberInfo(array('member_id'=>$member_id));
  614. if (!is_array($member_info) || count($member_info)<=0){
  615. showMessage(Language::get('admin_points_userrecord_error'),'index.php?act=predeposit&op=predeposit_add','','error');
  616. }
  617. $available_predeposit=floatval($member_info['available_predeposit']);
  618. $freeze_predeposit=floatval($member_info['freeze_predeposit']);
  619. if ($_POST['operatetype'] == 2 && $money > $available_predeposit){
  620. showMessage(('预存款不足,会员当前预存款').$available_predeposit,'index.php?act=predeposit&op=predeposit_add','','error');
  621. }
  622. if ($_POST['operatetype'] == 3 && $money > $available_predeposit){
  623. showMessage(('可冻结预存款不足,会员当前预存款').$available_predeposit,'index.php?act=predeposit&op=predeposit_add','','error');
  624. }
  625. if ($_POST['operatetype'] == 4 && $money > $freeze_predeposit){
  626. showMessage(('可恢复冻结预存款不足,会员当前冻结预存款').$freeze_predeposit,'index.php?act=predeposit&op=predeposit_add','','error');
  627. }
  628. $model_pd = Model('predeposit');
  629. $order_sn = $model_pd->makeSn();
  630. $admininfo = $this->getAdminInfo();
  631. $log_msg = "管理员【".$admininfo['admin_name']."】操作会员【".$member_info['member_name']."】预存款,金额为".$money.",编号为".$order_sn;
  632. $admin_act="sys_add_money";
  633. switch ($_POST['operatetype'])
  634. {
  635. case 1:
  636. $admin_act="sys_add_money";
  637. $log_msg = "管理员【".$admininfo['admin_name']."】操作会员【".$member_info['member_name']."】预存款【增加】,金额为".$money.",编号为".$order_sn;
  638. break;
  639. case 2:
  640. $admin_act="sys_del_money";
  641. $log_msg = "管理员【".$admininfo['admin_name']."】操作会员【".$member_info['member_name']."】预存款【减少】,金额为".$money.",编号为".$order_sn;
  642. break;
  643. case 3:
  644. $admin_act="sys_freeze_money";
  645. $log_msg = "管理员【".$admininfo['admin_name']."】操作会员【".$member_info['member_name']."】预存款【冻结】,金额为".$money.",编号为".$order_sn;
  646. break;
  647. case 4:
  648. $admin_act="sys_unfreeze_money";
  649. $log_msg = "管理员【".$admininfo['admin_name']."】操作会员【".$member_info['member_name']."】预存款【解冻】,金额为".$money.",编号为".$order_sn;
  650. break;
  651. default:
  652. showMessage('操作失败','index.php?act=predeposit&op=pd_log_list');
  653. break;
  654. }
  655. try {
  656. $model_pd->beginTransaction();
  657. //扣除冻结的预存款
  658. $data = array();
  659. $data['member_id'] = $member_info['member_id'];
  660. $data['member_name'] = $member_info['member_name'];
  661. $data['amount'] = $money;
  662. $data['order_sn'] = $order_sn;
  663. $data['admin_name'] = $admininfo['name'];
  664. $data['pdr_sn'] = $order_sn;
  665. $data['lg_desc'] = $memo;
  666. $model_pd->changePd($admin_act,$data);
  667. $model_pd->commit();
  668. $this->log($log_msg,1);
  669. showMessage('操作成功','index.php?act=predeposit&op=pd_log_list');
  670. } catch (Exception $e) {
  671. $model_pd->rollback();
  672. $this->log($log_msg,0);
  673. showMessage($e->getMessage(),'index.php?act=predeposit&op=pd_log_list','html','error');
  674. }
  675. }
  676. //取得会员信息
  677. public function checkmemberOp(){
  678. $name = trim($_GET['name']);
  679. if (!$name){
  680. echo ''; die;
  681. }
  682. /**
  683. * 转码
  684. */
  685. if(strtoupper(CHARSET) == 'GBK'){
  686. $name = Language::getGBK($name);
  687. }
  688. $obj_member = Model('member');
  689. $member_info = $obj_member->getMemberInfo(array('member_name'=>$name));
  690. if (is_array($member_info) && count($member_info)>0){
  691. if(strtoupper(CHARSET) == 'GBK'){
  692. $member_info['member_name'] = Language::getUTF8($member_info['member_name']);
  693. }
  694. echo json_encode(array('id'=>$member_info['member_id'],'name'=>$member_info['member_name'],'available_predeposit'=>$member_info['available_predeposit'],'freeze_predeposit'=>$member_info['freeze_predeposit']));
  695. }else {
  696. echo ''; die;
  697. }
  698. }
  699. }