Predeposit.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Predeposit extends AdminControl {
  18. const EXPORT_SIZE = 1000;
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/predeposit.lang.php');
  22. }
  23. /*
  24. * 充值明细
  25. */
  26. public function pdrecharge_list() {
  27. $condition = array();
  28. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_date'));
  29. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_date'));
  30. $start_unixtime = $if_start_date ? strtotime(input('param.query_start_date')) : null;
  31. $end_unixtime = $if_end_date ? strtotime(input('param.query_end_date')) : null;
  32. if ($start_unixtime) {
  33. $condition[]=array('pdr_addtime','>=', $start_unixtime);
  34. }
  35. if ($end_unixtime) {
  36. $end_unixtime=$end_unixtime+86399;
  37. $condition[]=array('pdr_addtime','<=', $end_unixtime);
  38. }
  39. if (input('param.mname') != '') {
  40. $condition[]=array('pdr_member_name','like', "%" . input('param.mname') . "%");
  41. }
  42. if (input('param.paystate_search') != '') {
  43. $condition[]=array('pdr_payment_state','=',input('param.paystate_search'));
  44. }
  45. $predeposit_model = model('predeposit');
  46. $recharge_list = $predeposit_model->getPdRechargeList($condition, 20, '*', 'pdr_id desc');
  47. View::assign('recharge_list', $recharge_list);
  48. View::assign('show_page', $predeposit_model->page_info->render());
  49. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  50. $this->setAdminCurItem('pdrecharge_list');
  51. return View::fetch();
  52. }
  53. /**
  54. * 充值编辑(更改成收到款)
  55. */
  56. public function recharge_edit() {
  57. $id = intval(input('param.id'));
  58. if ($id <= 0) {
  59. $this->error(lang('admin_predeposit_parameter_error'), 'Predeposit/pdrecharge_list');
  60. }
  61. //查询充值信息
  62. $predeposit_model = model('predeposit');
  63. $condition = array();
  64. $condition[] = array('pdr_id','=',$id);
  65. $condition[] = array('pdr_payment_state','=',0);
  66. $info = $predeposit_model->getPdRechargeInfo($condition);
  67. if (empty($info)) {
  68. $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdrecharge_list');
  69. }
  70. if (!request()->isPost()) {
  71. //显示支付接口列表
  72. $payment_list = model('payment')->getPaymentOpenList();
  73. //去掉预存款和货到付款
  74. foreach ($payment_list as $key => $value) {
  75. if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') {
  76. unset($payment_list[$key]);
  77. }
  78. }
  79. View::assign('payment_list', $payment_list);
  80. View::assign('info', $info);
  81. return View::fetch('recharge_edit');
  82. }
  83. //取支付方式信息
  84. $payment_model = model('payment');
  85. $condition = array();
  86. $condition[]=array('payment_code','=',input('post.payment_code'));
  87. $payment_info = $payment_model->getPaymentOpenInfo($condition);
  88. if (!$payment_info || $payment_info['payment_code'] == 'offline' || $payment_info['payment_code'] == 'offline') {
  89. $this->error(lang('payment_index_sys_not_support'));
  90. }
  91. $condition = array();
  92. $condition[] = array('pdr_sn','=',$info['pdr_sn']);
  93. $condition[] = array('pdr_payment_state','=',0);
  94. $update = array();
  95. $update['pdr_payment_state'] = 1;
  96. $update['pdr_paymenttime'] = strtotime(input('post.payment_time'));
  97. $update['pdr_payment_code'] = $payment_info['payment_code'];
  98. $update['pdr_trade_sn'] = input('post.trade_no');
  99. $update['pdr_admin'] = $this->admin_info['admin_name'];
  100. $log_msg = lang('admin_predeposit_recharge_edit_state') . ',' . lang('admin_predeposit_sn') . ':' . $info['pdr_sn'];
  101. Db::startTrans();
  102. try {
  103. //更改充值状态
  104. $state = $predeposit_model->editPdRecharge($update, $condition);
  105. if (!$state) {
  106. throw Exception(lang('predeposit_payment_pay_fail'));
  107. }
  108. //变更会员预存款
  109. $data = array();
  110. $data['member_id'] = $info['pdr_member_id'];
  111. $data['member_name'] = $info['pdr_member_name'];
  112. $data['amount'] = $info['pdr_amount'];
  113. $data['pdr_sn'] = $info['pdr_sn'];
  114. $data['admin_name'] = $this->admin_info['admin_name'];
  115. $predeposit_model->changePd('recharge', $data);
  116. Db::commit();
  117. $this->log($log_msg, 1);
  118. dsLayerOpenSuccess(lang('admin_predeposit_recharge_edit_success'));
  119. } catch (Exception $e) {
  120. Db::rollback();
  121. $this->log($log_msg, 0);
  122. $this->error($e->getMessage(), 'Predeposit/pdrecharge_list');
  123. }
  124. }
  125. /**
  126. * 充值查看
  127. */
  128. public function recharge_info() {
  129. $id = intval(input('param.id'));
  130. if ($id <= 0) {
  131. $this->error(lang('admin_predeposit_parameter_error'), 'Predeposit/pdrecharge_list');
  132. }
  133. //查询充值信息
  134. $predeposit_model = model('predeposit');
  135. $condition = array();
  136. $condition[] = array('pdr_id','=',$id);
  137. $info = $predeposit_model->getPdRechargeInfo($condition);
  138. if (empty($info)) {
  139. $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdrecharge_list');
  140. }
  141. View::assign('info', $info);
  142. return View::fetch('recharge_info');
  143. }
  144. /**
  145. * 充值删除
  146. */
  147. public function recharge_del() {
  148. $pdr_id = input('param.pdr_id');
  149. $pdr_id_array = ds_delete_param($pdr_id);
  150. if($pdr_id_array === FALSE){
  151. ds_json_encode('10001', lang('param_error'));
  152. }
  153. $predeposit_model = model('predeposit');
  154. $condition = array();
  155. $condition[] = array('pdr_id','in', $pdr_id_array);
  156. $condition[] = array('pdr_payment_state','=',0);
  157. $result = $predeposit_model->delPdRecharge($condition);
  158. if ($result) {
  159. ds_json_encode('10000', lang('ds_common_del_succ'));
  160. } else {
  161. ds_json_encode('10001', lang('ds_common_del_fail'));
  162. }
  163. }
  164. /*
  165. * 预存款明细
  166. */
  167. public function pdlog_list() {
  168. $condition = array();
  169. $stime = input('get.stime');
  170. $etime = input('get.etime');
  171. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  172. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  173. $start_unixtime = $if_start_date ? strtotime($stime) : null;
  174. $end_unixtime = $if_end_date ? strtotime($etime) : null;
  175. if ($start_unixtime) {
  176. $condition[]=array('lg_addtime','>=', $start_unixtime);
  177. }
  178. if ($end_unixtime) {
  179. $end_unixtime=$end_unixtime+86399;
  180. $condition[]=array('lg_addtime','<=', $end_unixtime);
  181. }
  182. $mname = input('get.mname');
  183. if (!empty($mname)) {
  184. $condition[] = array('lg_member_name','=',$mname);
  185. }
  186. $aname = input('get.aname');
  187. if (!empty($aname)) {
  188. $condition[] = array('lg_admin_name','=',$aname);
  189. }
  190. $predeposit_model = model('predeposit');
  191. $list_log = $predeposit_model->getPdLogList($condition, 10, '*', 'lg_id desc');
  192. View::assign('show_page', $predeposit_model->page_info->render());
  193. View::assign('list_log', $list_log);
  194. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  195. $this->setAdminCurItem('pdlog_list');
  196. return View::fetch();
  197. }
  198. /*
  199. * 提现设置
  200. */
  201. public function pdcash_set(){
  202. $config_model = model('config');
  203. if(!request()->isPost()){
  204. $list_setting = rkcache('config', true);
  205. View::assign('list_setting',$list_setting);
  206. $this->setAdminCurItem('pdcash_set');
  207. return View::fetch();
  208. }else{
  209. $update_array=array(
  210. 'member_withdraw_min'=>abs(round(input('post.member_withdraw_min'),2)),
  211. 'member_withdraw_max'=>abs(round(input('post.member_withdraw_max'),2)),
  212. 'member_withdraw_cycle'=>abs(intval(input('post.member_withdraw_cycle'))),
  213. );
  214. $result = $config_model->editConfig($update_array);
  215. if ($result) {
  216. $this->log(lang('ds_update').lang('admin_predeposit_cashset'),1);
  217. $this->success(lang('ds_common_op_succ'), 'Predeposit/pdcash_set');
  218. }else{
  219. $this->log(lang('ds_update').lang('admin_predeposit_cashset'),0);
  220. }
  221. }
  222. }
  223. /*
  224. * 提现列表
  225. */
  226. public function pdcash_list() {
  227. $condition = array();
  228. $stime = input('get.stime');
  229. $etime = input('get.etime');
  230. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  231. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  232. $start_unixtime = $if_start_date ? strtotime($stime) : null;
  233. $end_unixtime = $if_end_date ? strtotime($etime) : null;
  234. if ($start_unixtime) {
  235. $condition[]=array('pdc_addtime','>=', $start_unixtime);
  236. }
  237. if ($end_unixtime) {
  238. $end_unixtime=$end_unixtime+86399;
  239. $condition[]=array('pdc_addtime','<=', $end_unixtime);
  240. }
  241. $mname = input('get.mname');
  242. if (!empty($mname)) {
  243. $condition[]=array('pdc_member_name','like', "%" . $mname . "%");
  244. }
  245. $pdc_bank_user = input('get.pdc_bank_user');
  246. if (!empty($pdc_bank_user)) {
  247. $condition[]=array('pdc_bank_user','like', "%" . $pdc_bank_user . "%");
  248. }
  249. $paystate_search = input('get.paystate_search');
  250. if ($paystate_search != '') {
  251. $condition[]=array('pdc_payment_state','=',$paystate_search);
  252. }
  253. $predeposit_model = model('predeposit');
  254. $predeposit_list = $predeposit_model->getPdcashList($condition, 20, '*', 'pdc_payment_state asc,pdc_id asc');
  255. View::assign('predeposit_list', $predeposit_list);
  256. View::assign('show_page', $predeposit_model->page_info->render());
  257. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  258. $this->setAdminCurItem('pdcash_list');
  259. return View::fetch('pdcash_list');
  260. }
  261. /**
  262. * 删除提现记录
  263. */
  264. public function pdcash_del() {
  265. $pdc_id = intval(input('param.pdc_id'));
  266. if ($pdc_id <= 0) {
  267. ds_json_encode(10001, lang('param_error'));
  268. }
  269. $predeposit_model = model('predeposit');
  270. $condition = array();
  271. $condition[] = array('pdc_id','=',$pdc_id);
  272. $condition[] = array('pdc_payment_state','=',0);
  273. $info = $predeposit_model->getPdcashInfo($condition);
  274. if (!$info) {
  275. ds_json_encode(10001, lang('admin_predeposit_parameter_error'));
  276. }
  277. try {
  278. $result = $predeposit_model->delPdcash($condition);
  279. if (!$result) {
  280. ds_json_encode(10001, lang('admin_predeposit_cash_del_fail'));
  281. }
  282. //退还冻结的预存款
  283. $member_model = model('member');
  284. $member_info = $member_model->getMemberInfo(array('member_id' => $info['pdc_member_id']));
  285. //扣除冻结的预存款
  286. $admininfo = $this->getAdminInfo();
  287. $data = array();
  288. $data['member_id'] = $member_info['member_id'];
  289. $data['member_name'] = $member_info['member_name'];
  290. $data['amount'] = $info['pdc_amount'];
  291. $data['order_sn'] = $info['pdc_sn'];
  292. $data['admin_name'] = $admininfo['admin_name'];
  293. $predeposit_model->changePd('cash_del', $data);
  294. $predeposit_model->commit();
  295. ds_json_encode(10000, lang('admin_predeposit_cash_del_success'));
  296. } catch (Exception $e) {
  297. $predeposit_model->commit();
  298. ds_json_encode(10001, lang($e->getMessage()));
  299. }
  300. }
  301. /**
  302. * 更改提现为支付状态
  303. */
  304. public function pdcash_pay() {
  305. $id = intval(input('param.id'));
  306. if ($id <= 0) {
  307. $this->error(lang('admin_predeposit_parameter_error'),'Predeposit/pdcash_list');
  308. }
  309. $predeposit_model = model('predeposit');
  310. $condition = array();
  311. $condition[] = array('pdc_id','=',$id);
  312. $condition[] = array('pdc_payment_state','=',0);
  313. $info = $predeposit_model->getPdcashInfo($condition);
  314. if (!is_array($info) || count($info) < 0) {
  315. $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdcash_list');
  316. }
  317. //查询用户信息
  318. $member_model = model('member');
  319. $member_info = $member_model->getMemberInfo(array('member_id' => $info['pdc_member_id']));
  320. $update = array();
  321. $admininfo = $this->getAdminInfo();
  322. $update['pdc_payment_state'] = 1;
  323. $update['pdc_payment_admin'] = $admininfo['admin_name'];
  324. $update['pdc_payment_time'] = TIMESTAMP;
  325. $log_msg = lang('admin_predeposit_cash_edit_state') . ',' . lang('admin_predeposit_cs_sn') . ':' . $info['pdc_sn'];
  326. Db::startTrans();
  327. try {
  328. $result = $predeposit_model->editPdcash($update, $condition);
  329. if (!$result) {
  330. $this->error(lang('admin_predeposit_cash_edit_fail'));
  331. }
  332. //扣除冻结的预存款
  333. $data = array();
  334. $data['member_id'] = $member_info['member_id'];
  335. $data['member_name'] = $member_info['member_name'];
  336. $data['amount'] = $info['pdc_amount'];
  337. $data['order_sn'] = $info['pdc_sn'];
  338. $data['admin_name'] = $admininfo['admin_name'];
  339. $predeposit_model->changePd('cash_pay', $data);
  340. if($info['pdc_bank_type']=='alipay'){//如果是支付宝且开启了支付宝提现
  341. $logic_payment = model('payment', 'logic');
  342. $payment_code='alipay';
  343. $result = $logic_payment->getPaymentInfo($payment_code);
  344. if ($result['code']) {
  345. $payment_info = $result['data'];
  346. if($payment_info['payment_config']['alipay_trade_transfer_state'] == 1){
  347. $payment_api = new $payment_code($payment_info);
  348. $result = $payment_api->fund_transfer($info);
  349. if (!$result['code']) {
  350. throw new \think\Exception($result['msg'], 10006);
  351. }
  352. $result = $predeposit_model->editPdcash(array('pdc_payment_code'=>$payment_code,'pdc_trade_sn'=>$result['data']['pdc_trade_sn']), array('pdc_id'=>$id));
  353. if (!$result) {
  354. throw new \think\Exception(lang('admin_predeposit_cash_edit_fail'), 10006);
  355. }
  356. }
  357. }
  358. }elseif($info['pdc_bank_type']=='weixin'){//如果是微信且开启了微信提现
  359. $logic_payment = model('payment', 'logic');
  360. $payment_code='wxpay_native';
  361. $result = $logic_payment->getPaymentInfo($payment_code);
  362. if ($result['code']) {
  363. $payment_info = $result['data'];
  364. if($payment_info['payment_config']['wx_trade_transfer_state'] == 1){
  365. $payment_api = new $payment_code($payment_info);
  366. $result = $payment_api->fund_transfer($info);
  367. if (!$result['code']) {
  368. throw new \think\Exception($result['msg'], 10006);
  369. }
  370. $result = $predeposit_model->editPdcash(array('pdc_payment_code'=>$payment_code,'pdc_trade_sn'=>$result['data']['pdc_trade_sn']), array('pdc_id'=>$id));
  371. if (!$result) {
  372. throw new \think\Exception(lang('admin_predeposit_cash_edit_fail'), 10006);
  373. }
  374. }
  375. }
  376. }
  377. Db::commit();
  378. $this->log($log_msg, 1);
  379. dsLayerOpenSuccess(lang('admin_predeposit_cash_edit_success'));
  380. } catch (\Exception $e) {
  381. Db::rollback();
  382. $this->log($log_msg, 0);
  383. $this->error($e->getMessage(), 'Predeposit/pdcash_list');
  384. }
  385. }
  386. /**
  387. * 查看提现信息
  388. */
  389. public function pdcash_view() {
  390. $id = intval(input('param.id'));
  391. if ($id <= 0) {
  392. $this->error(lang('admin_predeposit_parameter_error'), 'Predeposit/pdcash_list');
  393. }
  394. $predeposit_model = model('predeposit');
  395. $condition = array();
  396. $condition[] = array('pdc_id','=',$id);
  397. $info = $predeposit_model->getPdcashInfo($condition);
  398. if (!is_array($info) || count($info) < 0) {
  399. $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdcash_list');
  400. }
  401. View::assign('info', $info);
  402. return View::fetch();
  403. }
  404. /*
  405. * 调节预存款
  406. */
  407. public function pd_add() {
  408. if (!(request()->isPost())) {
  409. $member_id = intval(input('get.member_id'));
  410. if($member_id>0){
  411. $condition = array();
  412. $condition[] = array('member_id','=',$member_id);
  413. $member = model('member')->getMemberInfo($condition);
  414. if(!empty($member)){
  415. View::assign('member_info',$member);
  416. }
  417. }
  418. return View::fetch();
  419. } else {
  420. $data = array(
  421. 'member_id' => input('post.member_id'),
  422. 'amount' => input('post.amount'),
  423. 'operatetype' => input('post.operatetype'),
  424. 'lg_desc' => input('post.lg_desc'),
  425. );
  426. $predeposit_validate = ds_validate('predeposit');
  427. if (!$predeposit_validate->scene('pd_add')->check($data)) {
  428. $this->error($predeposit_validate->getError());
  429. }
  430. $money = abs(floatval(input('post.amount')));
  431. $memo = trim(input('post.lg_desc'));
  432. if ($money <= 0) {
  433. $this->error(lang('amount_min'));
  434. }
  435. //查询会员信息
  436. $member_mod = model('member');
  437. $member_id = intval(input('post.member_id'));
  438. $operatetype = input('post.operatetype');
  439. $member_info = $member_mod->getMemberInfo(array('member_id' => $member_id));
  440. if (!is_array($member_info) || count($member_info) <= 0) {
  441. $this->error(lang('user_not_exist'), 'Predeposit/pd_add');
  442. }
  443. $available_predeposit = floatval($member_info['available_predeposit']);
  444. $freeze_predeposit = floatval($member_info['freeze_predeposit']);
  445. if ($operatetype == 2 && $money > $available_predeposit) {
  446. $this->error(lang('avaliable_predeposit_not_enough') . $available_predeposit, 'Predeposit/pd_add');
  447. }
  448. if ($operatetype == 3 && $money > $available_predeposit) {
  449. $this->error(lang('freezen_predeposit_not_enough') . $available_predeposit, 'Predeposit/pd_add');
  450. }
  451. if ($operatetype == 4 && $money > $freeze_predeposit) {
  452. $this->error(lang('recover_freezen_predeposit_not_enough') . $freeze_predeposit, 'Predeposit/pd_add');
  453. }
  454. $predeposit_model = model('predeposit');
  455. #生成对应订单号
  456. $order_sn = makePaySn($member_id);
  457. $admininfo = $this->getAdminInfo();
  458. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
  459. $admin_act = "sys_add_money";
  460. switch ($operatetype) {
  461. case 1:
  462. $admin_act = "sys_add_money";
  463. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
  464. break;
  465. case 2:
  466. $admin_act = "sys_del_money";
  467. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
  468. break;
  469. case 3:
  470. $admin_act = "sys_freeze_money";
  471. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【冻结】,金额为" . $money . ",编号为" . $order_sn;
  472. break;
  473. case 4:
  474. $admin_act = "sys_unfreeze_money";
  475. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【解冻】,金额为" . $money . ",编号为" . $order_sn;
  476. break;
  477. default:
  478. $this->error(lang('ds_common_op_fail'), 'Predeposit/pdlog_list');
  479. break;
  480. }
  481. try {
  482. Db::startTrans();
  483. //扣除冻结的预存款
  484. $data = array();
  485. $data['member_id'] = $member_info['member_id'];
  486. $data['member_name'] = $member_info['member_name'];
  487. $data['amount'] = $money;
  488. $data['order_sn'] = $order_sn;
  489. $data['admin_name'] = $admininfo['admin_name'];
  490. $data['pdr_sn'] = $order_sn;
  491. $data['lg_desc'] = $memo;
  492. $predeposit_model->changePd($admin_act, $data);
  493. Db::commit();
  494. $this->log($log_msg, 1);
  495. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  496. } catch (Exception $e) {
  497. Db::rollback();
  498. $this->log($log_msg, 0);
  499. $this->error($e->getMessage(), 'Predeposit/pdlog_list');
  500. }
  501. }
  502. }
  503. //取得会员信息
  504. public function checkmember() {
  505. $name = input('post.name');
  506. if (!$name) {
  507. exit(json_encode(array('id' => 0)));
  508. die;
  509. }
  510. $obj_member = model('member');
  511. $member_info = $obj_member->getMemberInfo(array('member_name' => $name));
  512. if (is_array($member_info) && count($member_info) > 0) {
  513. exit(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'])));
  514. } else {
  515. exit(json_encode(array('id' => 0)));
  516. }
  517. }
  518. /**
  519. * 导出预存款充值记录
  520. *
  521. */
  522. public function export_step1() {
  523. $condition = array();
  524. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_date'));
  525. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_date'));
  526. $start_unixtime = $if_start_date ? strtotime(input('param.query_start_date')) : null;
  527. $end_unixtime = $if_end_date ? strtotime(input('param.query_end_date')) : null;
  528. if ($start_unixtime) {
  529. $condition[] = array('pdr_addtime','>=', $start_unixtime);
  530. }
  531. if ($end_unixtime) {
  532. $end_unixtime=$end_unixtime+86399;
  533. $condition[] = array('pdr_addtime','<=', $end_unixtime);
  534. }
  535. if (input('param.mname') != '') {
  536. $condition[]=array('pdr_member_name','like', "%" . input('param.mname') . "%");
  537. }
  538. if (input('param.paystate_search') != '') {
  539. $condition[]=array('pdr_payment_state','=',input('param.paystate_search'));
  540. }
  541. $predeposit_model = model('predeposit');
  542. if (!is_numeric(input('param.page'))) {
  543. $count = $predeposit_model->getPdRechargeCount($condition);
  544. $array = array();
  545. if ($count > self::EXPORT_SIZE) { //显示下载链接
  546. $page = ceil($count / self::EXPORT_SIZE);
  547. for ($i = 1; $i <= $page; $i++) {
  548. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  549. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  550. $array[$i] = $limit1 . ' ~ ' . $limit2;
  551. }
  552. View::assign('export_list', $array);
  553. return View::fetch('/public/excel');
  554. } else { //如果数量小,直接下载
  555. $data = $predeposit_model->getPdRechargeList($condition, '', '*', 'pdr_id desc', self::EXPORT_SIZE);
  556. $rechargepaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
  557. foreach ($data as $k => $v) {
  558. $data[$k]['pdr_payment_state'] = $rechargepaystate[$v['pdr_payment_state']];
  559. }
  560. $this->createExcel($data);
  561. }
  562. } else { //下载
  563. $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
  564. $limit2 = self::EXPORT_SIZE;
  565. $data = $predeposit_model->getPdRechargeList($condition, $limit2, '*', 'pdr_id desc');
  566. $rechargepaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
  567. foreach ($data as $k => $v) {
  568. $data[$k]['pdr_payment_state'] = $rechargepaystate[$v['pdr_payment_state']];
  569. }
  570. $this->createExcel($data);
  571. }
  572. }
  573. /**
  574. * 生成导出预存款充值excel
  575. *
  576. * @param array $data
  577. */
  578. private function createExcel($data = array()) {
  579. Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
  580. $excel_obj = new \excel\Excel();
  581. $excel_data = array();
  582. //设置样式
  583. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  584. //header
  585. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_no'));
  586. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_member'));
  587. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_ctime'));
  588. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_ptime'));
  589. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_pay'));
  590. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_money'));
  591. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_paystate'));
  592. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_memberid'));
  593. foreach ((array) $data as $k => $v) {
  594. $tmp = array();
  595. $tmp[] = array('data' => $v['pdr_sn']);
  596. $tmp[] = array('data' => $v['pdr_member_name']);
  597. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pdr_addtime']));
  598. if (intval($v['pdr_paymenttime'])) {
  599. if (date('His', $v['pdr_paymenttime']) == 0) {
  600. $tmp[] = array('data' => date('Y-m-d', $v['pdr_paymenttime']));
  601. } else {
  602. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pdr_paymenttime']));
  603. }
  604. } else {
  605. $tmp[] = array('data' => '');
  606. }
  607. $tmp[] = array('data' => $v['pdr_payment_code']);
  608. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pdr_amount']));
  609. $tmp[] = array('data' => $v['pdr_payment_state']);
  610. $tmp[] = array('data' => $v['pdr_member_id']);
  611. $excel_data[] = $tmp;
  612. }
  613. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  614. $excel_obj->addArray($excel_data);
  615. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_yc_yckcz'), CHARSET));
  616. $excel_obj->generateXML($excel_obj->charset(lang('exp_yc_yckcz'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  617. }
  618. /**
  619. * 导出预存款提现记录
  620. *
  621. */
  622. public function export_cash_step1() {
  623. $condition = array();
  624. $stime = input('get.stime');
  625. $etime = input('get.etime');
  626. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  627. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  628. $start_unixtime = $if_start_date ? strtotime($stime) : null;
  629. $end_unixtime = $if_end_date ? strtotime($etime) : null;
  630. if ($start_unixtime) {
  631. $condition[] = array('pdc_addtime','>=', $start_unixtime);
  632. }
  633. if ($end_unixtime) {
  634. $end_unixtime=$end_unixtime+86399;
  635. $condition[] = array('pdc_addtime','<=', $end_unixtime);
  636. }
  637. $mname = input('get.mname');
  638. if (!empty($mname)) {
  639. $condition[]=array('pdc_member_name','like', "%" . $mname . "%");
  640. }
  641. $pdc_bank_user = input('get.pdc_bank_user');
  642. if (!empty($pdc_bank_user)) {
  643. $condition[]=array('pdc_bank_user','like', "%" . $pdc_bank_user . "%");
  644. }
  645. $paystate_search = input('get.paystate_search');
  646. if ($paystate_search != '') {
  647. $condition[]=array('pdc_payment_state','=',$paystate_search);
  648. }
  649. $predeposit_model = Model('predeposit');
  650. if (!is_numeric(input('param.page'))) {
  651. $count = $predeposit_model->getPdCashCount($condition);
  652. $array = array();
  653. if ($count > self::EXPORT_SIZE) { //显示下载链接
  654. $page = ceil($count / self::EXPORT_SIZE);
  655. for ($i = 1; $i <= $page; $i++) {
  656. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  657. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  658. $array[$i] = $limit1 . ' ~ ' . $limit2;
  659. }
  660. View::assign('export_list', $array);
  661. return View::fetch('/public/excel');
  662. } else { //如果数量小,直接下载
  663. $data = $predeposit_model->getPdCashList($condition, '', '*', 'pdc_id desc', self::EXPORT_SIZE);
  664. $cashpaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
  665. foreach ($data as $k => $v) {
  666. $data[$k]['pdc_payment_state'] = $cashpaystate[$v['pdc_payment_state']];
  667. }
  668. $this->createCashExcel($data);
  669. }
  670. } else { //下载
  671. $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
  672. $limit2 = self::EXPORT_SIZE;
  673. $data = $predeposit_model->getPdCashList($condition, $limit2, '*', 'pdc_id desc');
  674. $cashpaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
  675. foreach ($data as $k => $v) {
  676. $data[$k]['pdc_payment_state'] = $cashpaystate[$v['pdc_payment_state']];
  677. }
  678. $this->createCashExcel($data);
  679. }
  680. }
  681. /**
  682. * 生成导出预存款提现excel
  683. *
  684. * @param array $data
  685. */
  686. private function createCashExcel($data = array()) {
  687. Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
  688. $excel_obj = new \excel\Excel();
  689. $excel_data = array();
  690. //设置样式
  691. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  692. //header
  693. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_no'));
  694. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_member'));
  695. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_money'));
  696. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_ctime'));
  697. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_state'));
  698. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_memberid'));
  699. foreach ((array) $data as $k => $v) {
  700. $tmp = array();
  701. $tmp[] = array('data' => $v['pdc_sn']);
  702. $tmp[] = array('data' => $v['pdc_member_name']);
  703. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pdc_amount']));
  704. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pdc_addtime']));
  705. $tmp[] = array('data' => $v['pdc_payment_state']);
  706. $tmp[] = array('data' => $v['pdc_member_id']);
  707. $excel_data[] = $tmp;
  708. }
  709. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  710. $excel_obj->addArray($excel_data);
  711. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_tx_title'), CHARSET));
  712. $excel_obj->generateXML($excel_obj->charset(lang('exp_tx_title'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  713. }
  714. /**
  715. * 预存款明细信息导出
  716. */
  717. public function export_mx_step1() {
  718. $condition = array();
  719. $stime = input('get.stime');
  720. $etime = input('get.etime');
  721. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  722. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  723. $start_unixtime = $if_start_date ? strtotime($stime) : null;
  724. $end_unixtime = $if_end_date ? strtotime($etime) : null;
  725. if ($start_unixtime) {
  726. $condition[] = array('lg_addtime','>=',$start_unixtime);
  727. }
  728. if ($end_unixtime) {
  729. $end_unixtime=$end_unixtime+86399;
  730. $condition[] = array('lg_addtime','<=',$end_unixtime);
  731. }
  732. $mname = input('get.mname');
  733. if (!empty($mname)) {
  734. $condition[] = array('lg_member_name','=',$mname);
  735. }
  736. $aname = input('get.aname');
  737. if (!empty($aname)) {
  738. $condition[] = array('lg_admin_name','=',$aname);
  739. }
  740. $predeposit_model = model('predeposit');
  741. if (!is_numeric(input('param.page'))) {
  742. $count = $predeposit_model->getPdLogCount($condition);
  743. $array = array();
  744. if ($count > self::EXPORT_SIZE) { //显示下载链接
  745. $page = ceil($count / self::EXPORT_SIZE);
  746. for ($i = 1; $i <= $page; $i++) {
  747. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  748. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  749. $array[$i] = $limit1 . ' ~ ' . $limit2;
  750. }
  751. View::assign('export_list', $array);
  752. return View::fetch('/public/excel');
  753. } else { //如果数量小,直接下载
  754. $data = $predeposit_model->getPdLogList($condition, '', '*', 'lg_id desc', self::EXPORT_SIZE);
  755. $this->createmxExcel($data);
  756. }
  757. } else { //下载
  758. $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
  759. $limit2 = self::EXPORT_SIZE;
  760. $data = $predeposit_model->getPdLogList($condition, $limit2, '*', 'lg_id desc');
  761. $this->createmxExcel($data);
  762. }
  763. }
  764. /**
  765. * 导出预存款明细excel
  766. *
  767. * @param array $data
  768. */
  769. private function createmxExcel($data = array()) {
  770. Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
  771. $excel_obj = new \excel\Excel();
  772. $excel_data = array();
  773. //设置样式
  774. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  775. //header
  776. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_member'));
  777. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_ctime'));
  778. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_av_money'));
  779. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_freeze_money'));
  780. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_system'));
  781. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_mshu'));
  782. foreach ((array) $data as $k => $v) {
  783. $tmp = array();
  784. $tmp[] = array('data' => $v['lg_member_name']);
  785. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['lg_addtime']));
  786. if (floatval($v['lg_av_amount']) == 0) {
  787. $tmp[] = array('data' => '');
  788. } else {
  789. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['lg_av_amount']));
  790. }
  791. if (floatval($v['lg_freeze_amount']) == 0) {
  792. $tmp[] = array('data' => '');
  793. } else {
  794. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['lg_freeze_amount']));
  795. }
  796. $tmp[] = array('data' => $v['lg_admin_name']);
  797. $tmp[] = array('data' => $v['lg_desc']);
  798. $excel_data[] = $tmp;
  799. }
  800. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  801. $excel_obj->addArray($excel_data);
  802. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_mx_rz'), CHARSET));
  803. $excel_obj->generateXML($excel_obj->charset(lang('exp_mx_rz'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  804. }
  805. /**
  806. * 获取卖家栏目列表,针对控制器下的栏目
  807. */
  808. protected function getAdminItemList() {
  809. $menu_array = array(
  810. array(
  811. 'name' => 'pdrecharge_list',
  812. 'text' => lang('pdrecharge_list'),
  813. 'url' => (string)url('Predeposit/pdrecharge_list')
  814. ),
  815. array(
  816. 'name' => 'pdcash_set',
  817. 'text' => lang('admin_predeposit_cashset'),
  818. 'url' => (string)url('Predeposit/pdcash_set')
  819. ),
  820. array(
  821. 'name' => 'pdcash_list',
  822. 'text' => lang('admin_predeposit_cashmanage'),
  823. 'url' => (string)url('Predeposit/pdcash_list')
  824. ),
  825. array(
  826. 'name' => 'pdlog_list',
  827. 'text' => lang('pdlog_list'),
  828. 'url' => (string)url('Predeposit/pdlog_list')
  829. ),
  830. array(
  831. 'name' => 'pd_add',
  832. 'text' => lang('pd_add'),
  833. 'url' => "javascript:dsLayerOpen('".(string)url('Predeposit/pd_add')."','".lang('pd_add')."')"
  834. ),
  835. );
  836. return $menu_array;
  837. }
  838. }
  839. ?>