123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?php
- /**
- * 预存款管理
- */
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- use think\facade\Db;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Predeposit extends BaseMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/predeposit.lang.php');
- }
- /**
- * 充值添加
- */
- public function recharge_add()
- {
- if (!request()->isPost()) {
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('predeposit');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('recharge_add');
- return View::fetch($this->template_dir . 'pd_recharge_add');
- } else {
- $pdr_amount = abs(floatval(input('post.pdr_amount')));
- if ($pdr_amount <= 0) {
- $this->error(lang('predeposit_recharge_add_pricemin_error'));
- }
- $predeposit_model = model('predeposit');
- $data = array();
- $data['pdr_sn'] = $pay_sn = makePaySn(session('member_id'));
- $data['pdr_member_id'] = session('member_id');
- $data['pdr_member_name'] = session('member_name');
- $data['pdr_amount'] = $pdr_amount;
- $data['pdr_addtime'] = TIMESTAMP;
- $insert = $predeposit_model->addPdRecharge($data);
- if ($insert) {
- //转向到商城支付页面
- $this->redirect((string)url('Buy/pd_pay', ['pay_sn' => $pay_sn]));
- }
- }
- }
- /**
- * 平台充值卡
- */
- public function rechargecard_add()
- {
- if (!request()->isPost()) {
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('predeposit');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('rechargecard_add');
- return View::fetch($this->template_dir . 'rechargecard_add');
- } else {
- $sn = (string) input('post.rc_sn');
- if (!$sn || strlen($sn) > 50) {
- $this->error(lang('platform_recharge_card_number_cannot_empty'));
- exit;
- }
- try {
- $res = model('predeposit')->addRechargecard($sn, $this->member_info);
- if ($res['message']) {
- $this->error($res['message']);
- }
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success(lang('platform_recharge_card_successfully_used'), (string)url('Predeposit/rcb_log_list'));
- }
- }
- /**
- * 充值列表
- */
- public function index()
- {
- $condition = array();
- $condition[] = array('pdr_member_id', '=', session('member_id'));
- $pdr_sn = input('pdr_sn');
- if (!empty($pdr_sn)) {
- $condition[] = array('pdr_sn', '=', $pdr_sn);
- }
- $predeposit_model = model('predeposit');
- $predeposit_list = $predeposit_model->getPdRechargeList($condition, 10, '*', 'pdr_id desc');
- View::assign('predeposit_list', $predeposit_list);
- View::assign('show_page', $predeposit_model->page_info->render());
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('predeposit');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('recharge_list');
- return View::fetch($this->template_dir . 'pd_recharge_list');
- }
- /**
- * 查看充值详细
- *
- */
- public function recharge_show()
- {
- $pdr_id = intval(input('param.id'));
- if ($pdr_id <= 0) {
- $this->error(lang('predeposit_parameter_error'));
- }
- $predeposit_model = model('predeposit');
- $condition = array();
- $condition[] = array('pdr_member_id', '=', session('member_id'));
- $condition[] = array('pdr_id', '=', $pdr_id);
- $condition[] = array('pdr_payment_state', '=', 1);
- $info = $predeposit_model->getPdRechargeInfo($condition);
- if (!$info) {
- $this->error(lang('predeposit_record_error'));
- }
- View::assign('info', $info);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('predeposit');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('recharge_show');
- return View::fetch($this->template_dir . 'recharge_show');
- }
- /**
- * 删除充值记录
- *
- */
- public function recharge_del()
- {
- $pdr_id = intval(input('param.id'));
- if ($pdr_id <= 0) {
- ds_json_encode(10001, lang('predeposit_parameter_error'));
- }
- $predeposit_model = model('predeposit');
- $condition = array();
- $condition[] = array('pdr_member_id', '=', session('member_id'));
- $condition[] = array('pdr_id', '=', $pdr_id);
- $condition[] = array('pdr_payment_state', '=', 0);
- $result = $predeposit_model->delPdRecharge($condition);
- if ($result) {
- ds_json_encode(10000, lang('ds_common_del_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_del_fail'));
- }
- }
- /**
- * 预存款变更日志
- */
- public function pd_log_list()
- {
- $condition = array();
- $condition[] = array('lg_member_id', '=', session('member_id'));
- $predeposit_model = model('predeposit');
- $predeposit_list = $predeposit_model->getPdLogList($condition, 10, '*', 'lg_id desc');
- View::assign('show_page', $predeposit_model->page_info->render());
- View::assign('predeposit_list', $predeposit_list);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('predeposit');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('loglist');
- return View::fetch($this->template_dir . 'pd_log_list');
- }
- /**
- * 充值卡余额变更日志
- */
- public function rcb_log_list()
- {
- $rcblog_model = model('rcblog');
- $rcblog_list = $rcblog_model->getRechargecardBalanceLogList(array('member_id' => session('member_id')), 10, 'rcblog_id desc');
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('predeposit');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('rcb_log_list');
- View::assign('show_page', $rcblog_model->page_info->render());
- View::assign('rcblog_list', $rcblog_list);
- return View::fetch($this->template_dir . 'rcb_log_list');
- }
- /**
- * 申请提现
- */
- public function pd_cash_add()
- {
- if (request()->isPost()) {
- $pdc_amount = abs(floatval(input('post.pdc_amount')));
- $memberbank_id = intval(input('param.memberbank_id'));
- if ($memberbank_id > 0) {
- $memberbank = model('memberbank')->getMemberbankInfo(array('member_id' => session('member_id'), 'memberbank_id' => $memberbank_id));
- if (empty($memberbank)) {
- ds_json_encode(10001, lang('param_error'));
- }
- $pdc_bank_type = $memberbank['memberbank_type'];
- $pdc_bank_name = $memberbank['memberbank_type'] == 'alipay' ? lang('pay_method_alipay') : $memberbank['memberbank_name'];
- $pdc_bank_no = $memberbank['memberbank_no'];
- $pdc_bank_user = $memberbank['memberbank_truename'];
- } elseif ($memberbank_id == -1) { //使用微信
- $member_wxinfo = unserialize($this->member_info['member_wxinfo']);
- if (!empty($member_wxinfo) && is_array($member_wxinfo) && isset($member_wxinfo['member_wxopenid']) && $member_wxinfo['member_wxopenid']) {
- $pdc_bank_type = 'weixin';
- $pdc_bank_name = lang('pay_method_wechat');
- $pdc_bank_no = $member_wxinfo['member_wxopenid'];
- $pdc_bank_user = $member_wxinfo['nickname'];
- } else {
- ds_json_encode(10001, lang('param_error'));
- }
- } else {
- ds_json_encode(10001, lang('param_error'));
- }
- $data = [
- 'pdc_amount' => $pdc_amount,
- 'pdc_bank_type' => $pdc_bank_type,
- 'pdc_bank_name' => $pdc_bank_name,
- 'pdc_bank_no' => $pdc_bank_no,
- 'pdc_bank_user' => $pdc_bank_user,
- 'password' => input('post.password')
- ];
- $predeposit_validate = ds_validate('predeposit');
- if (!$predeposit_validate->scene('pd_cash_add')->check($data)) {
- ds_json_encode(10001, $predeposit_validate->getError());
- }
- $predeposit_model = model('predeposit');
- $member_model = model('member');
- $member_info = $member_model->getMemberInfoByID(session('member_id'));
- //验证支付密码
- if (md5(input('post.password')) != $member_info['member_paypwd']) {
- ds_json_encode(10001, lang('payment_password_error'));
- }
- //验证金额是否足够
- if (floatval($member_info['available_predeposit']) < $pdc_amount) {
- ds_json_encode(10001, lang('predeposit_cash_shortprice_error'));
- }
- //是否超过提现周期
- $last_withdraw = $predeposit_model->getPdcashInfo(array(array('pdc_member_id', '=', $this->member_info['member_id']), array('pdc_payment_state', 'in', [0, 1]), array('pdc_addtime', '>', TIMESTAMP - intval(config('ds_config.member_withdraw_cycle')) * 86400)));
- if ($last_withdraw) {
- ds_json_encode(10001, lang('predeposit_last_withdraw_time_error') . date('Y-m-d', $last_withdraw['member_withdraw_cycle']));
- }
- //是否不小于最低提现金额
- if ($pdc_amount < floatval(config('ds_config.member_withdraw_min'))) {
- ds_json_encode(10001, lang('predeposit_withdraw_min') . config('ds_config.member_withdraw_min') . lang('ds_yuan'));
- }
- //是否不超过最高提现金额
- if ($pdc_amount > floatval(config('ds_config.member_withdraw_max'))) {
- ds_json_encode(10001, lang('predeposit_withdraw_max') . config('ds_config.store_withdraw_max') . lang('ds_yuan'));
- }
- try {
- Db::startTrans();
- $pdc_sn = makePaySn(session('member_id'));
- $data = array();
- $data['pdc_sn'] = $pdc_sn;
- $data['pdc_member_id'] = session('member_id');
- $data['pdc_member_name'] = session('member_name');
- $data['pdc_bank_type'] = $pdc_bank_type;
- $data['pdc_amount'] = $pdc_amount;
- $data['pdc_bank_name'] = $pdc_bank_name;
- $data['pdc_bank_no'] = $pdc_bank_no;
- $data['pdc_bank_user'] = $pdc_bank_user;
- $data['pdc_addtime'] = TIMESTAMP;
- $data['pdc_payment_state'] = 0;
- $insert = $predeposit_model->addPdcash($data);
- if (!$insert) {
- ds_json_encode(10001, lang('predeposit_cash_add_fail'));
- }
- //冻结可用预存款
- $data = array();
- $data['member_id'] = $member_info['member_id'];
- $data['member_name'] = $member_info['member_name'];
- $data['amount'] = $pdc_amount;
- $data['order_sn'] = $pdc_sn;
- $predeposit_model->changePd('cash_apply', $data);
- Db::commit();
- ds_json_encode(10000, lang('predeposit_cash_add_success'));
- } catch (Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- }
- }
- /**
- * 提现列表
- */
- public function pd_cash_list()
- {
- $condition = array();
- $condition[] = array('pdc_member_id', '=', session('member_id'));
- $sn_search = input('post.sn_search');
- if (!empty($sn_search)) {
- $condition[] = array('pdc_sn', '=', $sn_search);
- }
- $paystate_search = input('post.paystate_search');
- if (isset($paystate_search)) {
- $condition[] = array('pdc_payment_state', '=', intval($paystate_search));
- }
- $pdcash_list = Db::name('pdcash')->where($condition)->order('pdc_id desc')->paginate();
- View::assign('pdcash_list', $pdcash_list);
- View::assign('show_page', $pdcash_list->render());
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('predeposit');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('cashlist');
- return View::fetch($this->template_dir . 'pd_cash_list');
- }
- /**
- * 提现记录详细
- */
- public function pd_cash_info()
- {
- $pdc_id = intval(input('param.id'));
- if ($pdc_id <= 0) {
- $this->error(lang('predeposit_parameter_error'), 'home/predeposit/pd_cash_list');
- }
- $predeposit_model = model('predeposit');
- $condition = array();
- $condition[] = array('pdc_member_id', '=', session('member_id'));
- $condition[] = array('pdc_id', '=', $pdc_id);
- $info = $predeposit_model->getPdcashInfo($condition);
- if (empty($info)) {
- $this->error(lang('predeposit_record_error'), 'home/predeposit/pd_cash_list');
- }
- $this->setMemberCurItem('cashinfo');
- $this->setMemberCurMenu('predeposit');
- View::assign('info', $info);
- return View::fetch($this->template_dir . 'pd_cash_info');
- }
- /**
- * 栏目菜单
- */
- function getMemberItemList()
- {
- $item_list = array(
- array(
- 'name' => 'loglist',
- 'text' => lang('detail_list'),
- 'url' => (string)url('Predeposit/pd_log_list'),
- ),
- array(
- 'name' => 'recharge_list',
- 'text' => lang('prepaid_phone_list'),
- 'url' => (string)url('Predeposit/index'),
- ),
- array(
- 'name' => 'cashlist',
- 'text' => lang('withdrawal_list'),
- 'url' => (string)url('Predeposit/pd_cash_list'),
- ),
- array(
- 'name' => 'rcb_log_list',
- 'text' => lang('balance_recharge_card'),
- 'url' => (string)url('Predeposit/rcb_log_list'),
- ),
- );
- if (request()->action() == 'rechargeinfo') {
- $item_list[] = array(
- 'name' => 'rechargeinfo',
- 'text' => lang('ds_member_path_predeposit_rechargeinfo'),
- 'url' => (string)url('Predeposit/rechargeinfo'),
- );
- }
- if (request()->action() == 'recharge_add') {
- $item_list[] = array(
- 'name' => 'recharge_add',
- 'text' => lang('predeposit_online_recharge'),
- 'url' => (string)url('Predeposit/recharge_add'),
- );
- }
- if (request()->action() == 'rechargecard_add') {
- $item_list[] = array(
- 'name' => 'rechargecard_add',
- 'text' => lang('predeposit_recharge_card_recharge'),
- 'url' => (string)url('Predeposit/rechargecard_add'),
- );
- }
- if (request()->action() == 'cashadd') {
- $item_list[] = array(
- 'name' => 'cashadd',
- 'text' => lang('ds_member_path_predeposit_cashadd'),
- 'url' => (string)url('Predeposit/cashadd'),
- );
- }
- if (request()->action() == 'cashinfo') {
- $item_list[] = array(
- 'name' => 'cashinfo',
- 'text' => lang('ds_member_path_predeposit_cashinfo'),
- 'url' => (string)url('Predeposit/cashinfo'),
- );
- }
- return $item_list;
- }
- }
|