123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- <?php
- namespace app\admin\controller\reward;
- use app\common\controller\Backend;
- use app\common\library\Redis;
- use app\main\helper\StringHelper;
- use think\Controller;
- use think\Log;
- use think\Request;
- /**
- * 赏金提现管理
- *
- * @icon fa fa-circle-o
- */
- class Withdraw extends Backend
- {
- /**
- * RewardWithdraw模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('RewardWithdraw');
- $this->view->assign("statusList", $this->model->getStatusList());
- }
- /**
- * 打款管理列表
- */
- public function index()
- {
- $this->assign('group', $this->group);
- $this->assignconfig('group', $this->group);
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- $where = [];
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- // Log::write($where,'congtest');
- }
- if ($this->group == 3) {
- $channels = model('Admin')
- ->join('auth_group_access a', 'a.uid= admin.id')
- ->join('admin_extend d', 'admin.id = d.admin_id')
- ->where('a.group_id', 'eq', 4)
- ->where('d.create_by', 'eq', $this->auth->id)
- ->field('admin.id,admin.nickname,d.pay_method')
- ->select();
- $cNames = [];
- foreach ($channels as $channel) {
- $cNames[$channel->id] = ['nickname' => $channel->nickname, 'dkfs' => $channel->pay_method];
- }
- $daili_id = implode(',', array_keys($cNames));
- /*
- * 统计,sum三个字段
- */
- //提现中
- $state1 = $this->model
- ->join('auth_group_access g', 'g.uid= reward_withdraw.admin_id')
- ->join('admin', 'reward_withdraw.admin_id = admin.id')
- ->where('reward_withdraw.admin_id', 'in', $daili_id)
- ->where($where)
- ->where('reward_withdraw.status', '0')
- ->sum('money');
- //打款中
- $state2 = $this->model
- ->join('auth_group_access g', 'g.uid= reward_withdraw.admin_id')
- ->join('admin', 'reward_withdraw.admin_id = admin.id')
- ->where('reward_withdraw.admin_id', 'in', $daili_id)
- ->where($where)
- ->where('reward_withdraw.status', '1')
- ->sum('money');
- //已打款
- $state3 = $this->model
- ->join('auth_group_access g', 'g.uid= reward_withdraw.admin_id')
- ->join('admin', 'reward_withdraw.admin_id = admin.id')
- ->where('reward_withdraw.admin_id', 'in', $daili_id)
- ->where($where)
- ->where('reward_withdraw.status', '2')
- ->sum('money');
- $this->assignconfig('state1', $state1);
- $this->assignconfig('state2', $state2);
- $this->assignconfig('state3', $state3);
- } else {
- $this->assignconfig('state1', 0);
- $this->assignconfig('state2', 0);
- $this->assignconfig('state3', 0);
- }
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $sort = 'reward_withdraw.id';
- if ($this->group == 3) { //渠道商
- //获取渠道商下面的代理商列表
- $channels = model('Admin')
- ->join('auth_group_access a', 'a.uid= admin.id')
- ->join('admin_extend d', 'admin.id = d.admin_id')
- ->where('a.group_id', 'eq', 4)
- ->where('d.create_by', 'eq', $this->auth->id)
- ->field('admin.id,admin.nickname,d.pay_method')
- ->select();
- $cNames = [];
- foreach ($channels as $channel) {
- $cNames[$channel->id] = ['nickname' => $channel->nickname, 'dkfs' => $channel->pay_method];
- }
- $daili_id = implode(',', array_keys($cNames));
- $total = $this->model
- ->join('auth_group_access g', 'g.uid= reward_withdraw.admin_id')
- ->join('admin', 'reward_withdraw.admin_id = admin.id')
- ->where('reward_withdraw.admin_id', 'in', $daili_id)
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->join('auth_group_access g', 'g.uid= reward_withdraw.admin_id')
- ->join('admin', 'reward_withdraw.admin_id = admin.id')
- ->field('reward_withdraw.*,admin.id admin_id')
- ->where('reward_withdraw.admin_id', 'in', $daili_id)
- ->where($where)
- ->order('reward_withdraw.status asc,reward_withdraw.id desc')
- ->limit($offset, $limit)
- ->select();
- foreach ($list as $key => $val) {
- $list[$key]['admin.nickname'] = empty($cNames[$val->admin_id]['nickname']) ? '' : $cNames[$val->admin_id]['nickname'];
- $list[$key]['dkfs'] = empty($cNames[$val->admin_id]['dkfs']) ? '' : $cNames[$val->admin_id]['dkfs'];
- $list[$key]['reward_withdraw.createtime'] = $val['createtime'];
- }
- $result = array("total" => $total, "rows" => $list, "others" => array('state1' => $state1, 'state2' => $state2, 'state3' => $state3));
- } else { //无权查看数据的用户组
- $result = array("total" => 0, "rows" => []);
- }
- return json($result);
- }
- return $this->view->fetch();
- }
- public function add()
- {
- $t = time();
- $start_time = strtotime(date('Y-m-d 23:30:00'));
- $end_time = strtotime(date('Y-m-d 01:30:00'));
- if ($t >= $start_time || $t <= $end_time) {
- $this->error('每天00:00-01:30与23:30-24:00,不支持提现');
- }
- $isIdCard = 0;
- $reward_money = model('RewardMoney')->where('admin_id', 'eq', $this->auth->id)->find();
- $this->assign('reward_money', $reward_money);
- $no_cash_money = 0;
- if ($this->group == 4) {
- //代理赏金
- $yesterday_reward_collect = model('reward_collect')
- ->where('invite_id', 'eq', $this->auth->id)
- ->where('type', 'eq', '1')
- ->where('flag', 'eq', '1')
- ->where('createdate', 'lt', date('Ymd'))
- ->where('createdate', 'neq', 'null')
- ->field('sum(reward) as reward')
- ->find();
- // Log::write(model('reward_collect')->getLastSql(),'111111');
- $this->assign('reward_all', $yesterday_reward_collect['reward']??0);
- $no_cash_money = ($yesterday_reward_collect['reward']??0) - $reward_money['cash_money'] - $reward_money['count_cash_money'];
- $extends=model('AdminExtend')->where(['admin_id'=>$this->auth->id])->find();
- $cb = $extends->create_by;
- $fAdmin = model('AdminExtend')->where(['admin_id'=>$cb])->find();
- $isIdCard = empty($fAdmin->is_idcard)?0:$fAdmin->is_idcard;
- if(!empty($extends->idcard_no)){
- $isIdCard = 0;
- }
- }
- $no_cash_money = StringHelper::moneyFormat($no_cash_money);
- if ($this->request->isPost()) {
- $timedate = date('Ymd',time());
- $withdrawKey = 'SJ:'.$this->auth->id.':'.$timedate;
- $redis = Redis::instance();
- if($redis->exists($withdrawKey)){
- $this->error('提现过于频繁,请十分钟以后再试');
- }
- if(empty($this->request->post('idcard_no'))) {
- $row = $this->request->post('row/a');
- if ($row) {
- $money = $row['money'];
- if ($money < 100) {
- $this->error('最低提现金额100元');
- }
- //未提现余额 严格校验
- if ($no_cash_money != $money) {
- $this->error('ERROR:提现金额与计算后的提现金额不一致');
- }
- if ($reward_money['no_cash_money'] < $money) {
- $this->error('超出最大可提现金额' . $reward_money['no_cash_money']);
- }
- $save['etime'] = date('Ymd', strtotime('-1 day'));
- $stime = model('reward_withdraw')->where('admin_id', $this->auth->id)->field('etime')->order('id desc')->find();
- if (empty($stime['etime'])) {
- $save['stime'] = null;
- } else {
- $save['stime'] = date('Ymd', strtotime($stime['etime']) + 3600 * 24);
- }
- //$this->error($save['stime']);
- $save['admin_id'] = $this->auth->id;
- $save['money'] = $money;//含手续费
- $save['status'] = 0;
- if (model('reward_withdraw')->save($save)) {
- model('RewardMoney')->where('admin_id', $this->auth->id)->setInc('cash_money', $money);
- model('RewardMoney')->where('admin_id', $this->auth->id)->setDec('no_cash_money', $money);
- $redis->setex($withdrawKey,600,'1'); //redis存10分钟,避免重复提现
- $this->success('提现成功');
- }
- $this->error('提交申请失败');
- }
- }else{
- $idCardNo = trim($this->request->post('idcard_no'));
- $flag = validateIDCard($idCardNo);
- if($flag){
- model('AdminExtend')->update(['idcard_no'=>$idCardNo],['admin_id'=>$this->auth->id]);
- $key = 'AE:'.$this->auth->id;
- $redis->del($key);
- $this->success();
- }else{
- $this->error('身份证号码不合法');
- }
- }
- $this->error('错误');
- }
- $this->assign('isIdcard',$isIdCard);
- $this->assign('group', $this->group);
- $this->assignconfig('group', $this->group);
- $this->view->assign('no_cash_money', $no_cash_money ? $no_cash_money : 0);
- $this->assignconfig('no_cash_money', $no_cash_money ? $no_cash_money : 0);
- return $this->view->fetch();
- }
- /*
- * 我的结算单
- */
- public function my()
- {
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where('reward_withdraw.admin_id', 'eq', $this->auth->id)
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where('reward_withdraw.admin_id', 'eq', $this->auth->id)
- ->where($where)
- ->order('reward_withdraw.status asc,reward_withdraw.id desc')
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- $reward_money = model('RewardMoney')->where('admin_id', 'eq', $this->auth->id)->find();
- $this->assign('reward_money', $reward_money);
- if ($this->group == 4) {
- //代理赏金 按天累加赏金金额
- $yesterday_reward_collect = model('reward_collect')
- ->where('invite_id', 'eq', $this->auth->id)
- ->where('type', 'eq', '1')
- ->where('flag', 'eq', '1')
- ->where('createdate', 'lt', date('Ymd'))
- ->where('createdate', 'neq', 'null')
- ->field('sum(reward) as reward')
- ->find();
- // Log::write(model('reward_collect')->getLastSql(),'111111');
- $this->assign('reward_all', $yesterday_reward_collect['reward']??0);
- $this->assign('no_cash_money', ($yesterday_reward_collect['reward']??0) - $reward_money['cash_money'] - $reward_money['count_cash_money']);
- $today_reward_collect = model('reward_collect')
- ->where('invite_id', 'eq', $this->auth->id)
- ->where('type', 'eq', '1')
- ->where('flag', 'eq', '1')
- ->where('createdate', 'eq', date('Ymd'))
- ->field('sum(reward) as reward')
- ->find();
- // Log::write(model('reward_collect')->getLastSql(),'111111');
- $this->assign('today_reward_all', $today_reward_collect['reward']??0);
- }
- return $this->view->fetch();
- }
- public function edit($ids = NULL)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
- $row->validate($validate);
- }
- if ($row['status'] == 2) {
- $this->error('已打款 请勿重复处理');
- }
- if (empty($params['status'])) {
- $this->error('请选择一种打款状态');
- }
- $result = $row->allowField(true)->save($params, ['id' => $params['id']]);
- if ($result !== false) {
- $withdraw = $this->model->get($params['id']);
- if ($params['status'] == 2) {
- //提现中的减少
- $admin_update1 = model('reward_money')->where('admin_id', $withdraw['admin_id'])->setDec('cash_money', $withdraw['money']);
- //已打款的增加
- $admin_update2 = model('reward_money')->where('admin_id', $withdraw['admin_id'])->setInc('count_cash_money', $withdraw['money']);
- //更新完成时间
- $time = time();
- $updateTime = model('reward_withdraw')->where('id', $params['id'])->update(['remit_time' => $time]);
- }
- $this->success();
- } else {
- $this->error($row->getError());
- }
- } catch (\think\exception\PDOException $e) {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $admin = model("Admin")->where('id', $row['admin_id'])->find();
- if ($admin) {
- $row['admin_nickname'] = $admin['nickname'];
- } else {
- $row['admin_nickname'] = '';
- }
- $ae = model('AdminExtend')->where('admin_id', $row['admin_id'])->find();
- $this->view->assign('ae', $ae);
- $this->view->assign("row", $row);
- $dingdan = [];
- if ($row['stime'] && $row['etime']) {
- $auth = model('AuthGroupAccess')->where('uid', $row['admin_id'])->find();
- if ($auth->group_id == 3) {
- //渠道
- $dingdan = model('Rewardcollect')
- ->where('invite_id', 'eq',$row['admin_id'])
- ->where('createtime', 'egt', $row['stime'])
- ->where('createtime', 'elt', $row['etime'])
- ->where('type', 'eq', '1')
- ->where('flag', 'eq', '1')
- ->field('id,createtime,reward,admin_id as aid')
- ->select();
- Log::write(model('Rewardcollect')->getLastSql(), '11111');
- }
- }
- // Log::write(model('Rewardcollect')->getLastSql(),'11111');
- $this->view->assign('dingdan', $dingdan);
- return $this->view->fetch();
- }
- }
|