123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <?php
- /**
- * 预存款管理
- */
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- use app\common\model\Storemoneylog;
- use think\facade\Db;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Sellermoney extends BaseSeller
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellermoney.lang.php');
- }
- /**
- * 预存款变更日志
- */
- public function index()
- {
- $condition = array(array('store_id', '=', session('store_id')));
- $query_start_date = input('param.query_start_date');
- $query_end_date = input('param.query_end_date');
- $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
- $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
- $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
- $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
- if ($start_unixtime) {
- $condition[] = array('storemoneylog_add_time', '>=', $start_unixtime);
- }
- if ($end_unixtime) {
- $condition[] = array('storemoneylog_add_time', '<=', $end_unixtime);
- }
- $storemoneylog_desc = input('param.storemoneylog_desc');
- if ($storemoneylog_desc) {
- $condition[] = array('storemoneylog_desc', 'like', '%' . $storemoneylog_desc . '%');
- }
- $storemoneylog_model = model('storemoneylog');
- $list_log = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
- View::assign('show_page', $storemoneylog_model->page_info->render());
- View::assign('list_log', $list_log);
- /* 设置买家当前菜单 */
- $this->setSellerCurMenu('seller_money');;
- /* 设置买家当前栏目 */
- $this->setSellerCurItem('index');
- $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
- View::assign('store_info', $store_info);
- return View::fetch($this->template_dir . 'index');
- }
- /**
- * 会员余额充值店铺资金
- */
- public function add()
- {
- $member_info = model('member')->getMemberInfoByID(session('member_id'));
- if (request()->isPost()) {
- $amount = floatval(input('post.amount'));
- $storemoneylog_model = model('storemoneylog');
- $predeposit_model = model('predeposit');
- if ($amount > floatval($member_info['available_predeposit'])) {
- ds_json_encode(10001, lang('sellermoney_rechargew_money_max') . $member_info['available_predeposit'] . lang('currency_zh'));
- }
- $storedata = array(
- 'store_id' => $this->store_info['store_id'],
- 'store_name' => $this->store_info['store_name'],
- 'storemoneylog_type' => Storemoneylog::TYPE_MEMBER_IN,
- 'storemoneylog_state' => Storemoneylog::STATE_VALID,
- 'storemoneylog_add_time' => TIMESTAMP,
- 'store_avaliable_money' => $amount,
- 'storemoneylog_desc' => lang('sellermoney_member_money') . lang('sellermoney_rechargew') . ',' . lang('sellermoney_money') . ':' . $amount,
- );
- $order_sn = makePaySn($member_info['member_id']);
- $memberdata = array(
- 'member_id' => $member_info['member_id'],
- 'amount' => $amount,
- 'member_name' => $member_info['member_name'],
- 'order_sn' => $order_sn,
- );
- try {
- Db::startTrans();
- $storemoneylog_model->changeStoremoney($storedata);
- $predeposit_model->changePd('store_rechargew_pay', $memberdata);
- Db::commit();
- $this->recordSellerlog(lang('sellermoney_rechargew_money'));
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } catch (\Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- } else {
- View::assign('member_info', $member_info);
- return View::fetch($this->template_dir . 'add');
- }
- }
- /**
- * 店铺资金提现到会员余额
- */
- public function withdraw_member()
- {
- $member_info = model('member')->getMemberInfoByID(session('member_id'));
- if (request()->isPost()) {
- $amount = floatval(input('post.amount'));
- $storemoneylog_model = model('storemoneylog');
- $predeposit_model = model('predeposit');
- if ($amount > floatval($this->store_info['store_avaliable_money'])) {
- ds_json_encode(10001, lang('sellermoney_withdraw_money_max') . $this->store_info['store_avaliable_money'] . lang('currency_zh'));
- }
- $storedata = array(
- 'store_id' => $this->store_info['store_id'],
- 'store_name' => $this->store_info['store_name'],
- 'storemoneylog_type' => Storemoneylog::TYPE_MEMBER_OUT,
- 'storemoneylog_state' => Storemoneylog::STATE_VALID,
- 'storemoneylog_add_time' => TIMESTAMP,
- 'store_avaliable_money' => -$amount,
- 'storemoneylog_desc' => lang('sellermoney_withdraw_member') . ',' . lang('sellermoney_money') . ':' . $amount,
- );
- $order_sn = makePaySn($member_info['member_id']);
- $memberdata = array(
- 'member_id' => $member_info['member_id'],
- 'amount' => $amount,
- 'member_name' => $member_info['member_name'],
- 'order_sn' => $order_sn,
- );
- try {
- Db::startTrans();
- $storemoneylog_model->changeStoremoney($storedata);
- $predeposit_model->changePd('store_withdraw', $memberdata);
- Db::commit();
- $this->recordSellerlog(lang('sellermoney_apply_withdraw'));
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } catch (\Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- } else {
- View::assign('store_avaliable_money', $this->store_info['store_avaliable_money']);
- return View::fetch($this->template_dir . 'member');
- }
- }
- /**
- * 申请提现
- */
- public function withdraw_add()
- {
- $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
- if (request()->isPost()) {
- $data = [
- 'pdc_amount' => floatval(input('post.pdc_amount')),
- ];
- $sellermoney_validate = ds_validate('sellermoney');
- if (!$sellermoney_validate->scene('withdraw_add')->check($data)) {
- ds_json_encode(10001, $sellermoney_validate->getError());
- }
- $pdc_amount = $data['pdc_amount'];
- $storemoneylog_model = model('storemoneylog');
- //是否超过提现周期
- $last_withdraw = $storemoneylog_model->getStoremoneylogInfo(array(array('store_id', '=', $this->store_info['store_id']), array('storemoneylog_state', 'in', [Storemoneylog::STATE_WAIT, Storemoneylog::STATE_AGREE]), array('storemoneylog_type', '=', Storemoneylog::TYPE_WITHDRAW), array('storemoneylog_add_time', '>', TIMESTAMP - intval(config('ds_config.store_withdraw_cycle')) * 86400)), 'storemoneylog_add_time');
- if ($last_withdraw) {
- ds_json_encode(10001, lang('sellermoney_last_withdraw_time_error') . date('Y-m-d', $last_withdraw['storemoneylog_add_time']));
- }
- //是否不小于最低提现金额
- if ($pdc_amount < floatval(config('ds_config.store_withdraw_min'))) {
- ds_json_encode(10001, lang('sellermoney_withdraw_min') . config('ds_config.store_withdraw_min') . lang('ds_yuan'));
- }
- //是否不超过最高提现金额
- if ($pdc_amount > floatval(config('ds_config.store_withdraw_max'))) {
- ds_json_encode(10001, lang('sellermoney_withdraw_max') . config('ds_config.store_withdraw_max') . lang('ds_yuan'));
- }
- $data = array(
- 'store_id' => $this->store_info['store_id'],
- 'store_name' => $this->store_info['store_name'],
- 'storemoneylog_type' => Storemoneylog::TYPE_WITHDRAW,
- 'storemoneylog_state' => Storemoneylog::STATE_WAIT,
- 'storemoneylog_add_time' => TIMESTAMP,
- );
- $data['store_avaliable_money'] = -$pdc_amount;
- $data['store_freeze_money'] = $pdc_amount;
- $storejoinin_info = Db::name('storejoinin')->where(array('member_id' => $this->store_info['member_id']))->field('settlement_bank_account_name,settlement_bank_account_number,settlement_bank_name,settlement_bank_address')->find();
- $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $this->store_info['member_id']));
- if ($joinin_detail['business_licence_address'] != '') {
- $sml_desc = lang('sellermoney_bank_user') . ':' . $storejoinin_info['settlement_bank_account_name'] . ',' . lang('sellermoney_bank_number') . ':' . $storejoinin_info['settlement_bank_account_number'] . ',' . lang('sellermoney_bank_sub_name') . ':' . $storejoinin_info['settlement_bank_name'] . ',' . lang('sellermoney_bank_name') . ':' . $storejoinin_info['settlement_bank_address'];
- } else {
- $sml_desc = lang('sellermoney_alipay_name') . ':' . $storejoinin_info['settlement_bank_account_name'] . ',' . lang('sellermoney_alipay_number') . ':' . $storejoinin_info['settlement_bank_account_number'];
- }
- $data['storemoneylog_desc'] = $sml_desc;
- try {
- Db::startTrans();
- $storemoneylog_model->changeStoremoney($data);
- Db::commit();
- $this->recordSellerlog(lang('sellermoney_apply_withdraw'));
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } catch (\Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- } else {
- View::assign('store_withdraw_cycle', config('ds_config.store_withdraw_cycle'));
- View::assign('store_withdraw_min', config('ds_config.store_withdraw_min'));
- View::assign('store_withdraw_max', config('ds_config.store_withdraw_max'));
- View::assign('store_info', $store_info);
- return View::fetch($this->template_dir . 'withdraw_add');
- }
- }
- /**
- * 提现列表
- */
- public function withdraw_list()
- {
- $condition = array();
- $condition[] = array('store_id', '=', session('store_id'));
- $condition[] = array('storemoneylog_type', '=', Storemoneylog::TYPE_WITHDRAW);
- $paystate_search = input('param.paystate_search');
- if (isset($paystate_search) && $paystate_search !== '') {
- $condition[] = array('storemoneylog_state', '=', intval($paystate_search));
- }
- $storemoneylog_model = model('storemoneylog');
- $withdraw_list = $storemoneylog_model->getStoremoneylogList($condition, 10, '*', 'storemoneylog_id desc');
- View::assign('show_page', $storemoneylog_model->page_info->render());
- View::assign('withdraw_list', $withdraw_list);
- /* 设置买家当前菜单 */
- $this->setSellerCurMenu('seller_money');;
- /* 设置买家当前栏目 */
- $this->setSellerCurItem('withdraw_list');
- $store_info = Db::name('store')->where(array('store_id' => session('store_id')))->field('store_avaliable_money,store_freeze_money')->find();
- View::assign('store_info', $store_info);
- return View::fetch($this->template_dir . 'withdraw_list');
- }
- /**
- * 栏目菜单
- */
- function getSellerItemList()
- {
- $item_list = array(
- array(
- 'name' => 'index',
- 'text' => lang('sellermoney_log_list'),
- 'url' => (string) url('Sellermoney/index'),
- ),
- array(
- 'name' => 'withdraw_list',
- 'text' => lang('sellermoney_withdraw_list'),
- 'url' => (string) url('Sellermoney/withdraw_list'),
- ),
- );
- return $item_list;
- }
- }
|