Predeposit.php 40 KB

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