model = new \app\admin\model\app\AppRecharge; $this->view->assign("typeList", $this->model->getTypeList()); $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 == '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_recharge aa') ->field('aa.*,u.nickname,u.mobile,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) ->count(); $list = Db::name('app_recharge aa') ->field('aa.*,u.nickname,u.mobile,e.nickname as daili_name') ->join('user u', 'aa.user_id = u.id','left') ->join('admin e', 'u.p_admin_id = e.id' , 'left') ->where($w) ->order('aa.id', 'desc') ->limit($offset, $limit) ->select(); // var_dump( Db::name('app_widthdraw aa')->getlastsql() );die; $result = array("total" => $total, "rows" => $list); 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{ // 使用充值记录中的币种ID,实现分币种存入对应账户 $recharge_curr_id = $row['curr_id'] ? $row['curr_id'] : 1; $user = Db::name('app_currency_user') ->where('user_id',$row['user_id']) ->where('curr_id',$recharge_curr_id) ->find(); // 如果该币种没有用户记录,自动创建 if(empty($user)){ $insert_data = [ 'user_id' => $row['user_id'], 'curr_id' => $recharge_curr_id, 'num' => 0, 'num_dj' => 0, 'num_fb' => 0, 'num_fb_dj' => 0, 'num_lh' => 0, 'num_lh_dj' => 0, 'regtime' => time(), 'updatetime' => time(), ]; $new_id = Db::name('app_currency_user')->insertGetId($insert_data); $user = Db::name('app_currency_user')->where('id',$new_id)->find(); } if($params['status'] == '1') { //审核通过 - 存入对应币种的现货账户 $recharge = [ 'user_id' => $row['user_id'], 'curr_id' => $recharge_curr_id, 'price' => $row['num'], 'cart' => '1', 'type' => '1', 'description' => '在线充值', 'createtime' => time(), 'hash' => $row['hash'], 'before_num' => $user['num'], 'after_num' => $user['num'] + $row['num'], 'is_outer' => '1', ]; $res = 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_recharge')->where('id', $row['id'])->update($params); } 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(); } }