model = new \app\admin\model\app\AppWidthdraw; $this->view->assign("statusList", $this->model->getStatusList()); } public function import() { parent::import(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * index重写 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } // list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $offset = $this->request->get("offset", 0); $limit = $this->request->get("limit", 0); $params = json_decode(input('filter'),true); $op = json_decode(input('op'),true); // print_r($params);exit; if(count($params) > 0){ $new_params = $new_op = []; foreach ($params as $key => $value) { if ($key == 'nickname') { $new_params['u.nickname'] = $value; $new_op['u.nickname'] = $op[$key]; }elseif ($key == 'mobile') { $new_params['u.mobile'] = $value; $new_op['u.mobile'] = $op[$key]; }elseif ($key == 'curr_name') { $new_params['p.name'] = $value; $new_op['p.name'] = $op[$key]; }elseif ($key == 'daili_name') { $new_params['e.nickname'] = $value; $new_op['e.nickname'] = $op[$key]; }else { $new_params['aa.' . $key] = $value; $new_op['aa.' . $key] = $op[$key]; } } $w = $this->rewriteQuery($new_params, $new_op); }else{ $w['aa.id'] = array('>', 0); } $admin_id = $this->auth->id; if($admin_id > 1){ $user = Db::name("user")->where("admin_id",$admin_id)->find(); if($user){ $w['u.path'] = array("like",$user['path']."%"); } } $total = Db::name('app_widthdraw aa') ->field('aa.*,u.nickname,u.mobile,p.name as curr_name,e.nickname as daili_name')//bank_code ->join('user u', 'aa.user_id = u.id','left') ->join('app_currency p', 'aa.curr_id = p.id','left') // ->join('app_collection l', 'aa.card_num = l.card_num','left') ->join('admin e', 'u.p_admin_id = e.id' , 'left') ->where($w) ->count(); $list = Db::name('app_widthdraw aa') ->field('aa.*,u.nickname,u.mobile,p.name as curr_name,e.nickname as daili_name') ->join('user u', 'aa.user_id = u.id','left') ->join('app_currency p', 'aa.curr_id = p.id','left') // ->join('app_collection l', 'aa.card_num = l.card_num','left') ->join('admin e', 'u.p_admin_id = e.id' , 'left') ->where($w) ->order('aa.id', 'desc') ->limit($offset, $limit) ->select(); $count_price = Db::name('app_widthdraw aa') ->field('aa.*,u.nickname,p.name as curr_name,e.nickname as daili_name') ->join('user u', 'aa.user_id = u.id','left') ->join('app_currency p', 'aa.curr_id = p.id','left') ->join('admin e', 'u.p_admin_id = e.id' , 'left') ->where($w) ->sum("aa.num"); foreach ($list as $key => $value) { $value['bank_code'] = Db::name("app_collection")->where("user_id",$value['user_id'])->where("card_num",$value['card_num'])->value("bank_code"); $list[$key] = $value; } // var_dump( Db::name('app_widthdraw aa')->getlastsql() );die; $result = array("total" => $total, "rows" => $list,"count_price"=>$count_price); return json($result); } 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) { $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { if($row['status'] != '2') { $this->error('编辑非法,已审核记录不可重复审核'); }else{ $user = Db::name('app_currency_user') ->where('user_id',$row['user_id']) ->where('curr_id','1') ->find(); if($params['status'] == '1') { //审核通过 $params['exam_time'] = time(); $result = Db::name('app_widthdraw') ->where('id',$row['id'])->update($params); }else if($params['status'] == '0') { $recharge = [ 'user_id' => $row['user_id'], 'curr_id' => 1, 'price' => $row['num'], 'cart' => '1', 'type' => '2', 'description' => $params['description'], 'hash' => '', 'before_num' => $user['num'], 'after_num' => $user['num'] + $row['num'], 'is_outer' => '0', 'createtime' => time(), ]; Db::name('app_detailed')->insertGetId($recharge); $changeamount = $user['num'] + $row['num']; Db::name('app_currency_user')->where('id', $user['id']) ->update(['num' => $changeamount, 'updatetime' => time()]); $result = Db::name('app_widthdraw') ->where('id',$row['id'])->update(['status'=>'0','description'=>$params['description'],'exam_time'=>time()]); } else{ //审核失败 $result = Db::name('app_widthdraw') ->where('id',$row['id'])->update(['exam_time'=>time()]); } } Db::commit(); } catch (ValidateException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (PDOException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(); } else { $this->error(__('No rows were updated')); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign("row", $row); return $this->view->fetch(); } public function bc_dechex($decimal) { $result = []; while ($decimal != 0) { $mod = $decimal % 16; $decimal = floor($decimal / 16); array_push($result, dechex($mod)); } return join(array_reverse($result)); } }