Predeposit.php 40 KB

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