model = new \app\admin\model\OfflineRechargeRecord; } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 * * @return string|Json * @throws \think\Exception * @throws DbException */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model->alias('r') ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $k => $v) { $list[$k]['user_address'] = (new UserModel())->getById($v['user_id'])['address']; } $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } /** * 发货 * @param $ids * @return string|void * @throws \think\Exception * @throws \think\exception\DbException */ public function delivery($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } $user = (new UserModel())->getById($row['user_id']); if(empty($user)){ $this->error("用户信息不存在"); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $update = [ 'express_status' => 1, 'express_name' => $params['express_name'], 'express_num' => $params['express_num'], 'update_time' => time(), ]; // 仅处理"待处理"状态的订单,"已抢单"的暂不处理 $result = (new OfflineRechargeRecordModel())->where('id', $row['id'])->update($update); if (empty($result)) { throw new Exception("订单发货失败"); } Db::commit(); } catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 手动报单 * * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function add() { if (false === $this->request->isPost()) { return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $user_info = UserModel::where('address', $params['address'])->find(); if(empty($user_info)){ $this->error('用户钱包地址不存在'); } $insert = []; if(empty($params['date_time'])){ $this->error('报单日期不能为空'); } $insert['user_id'] = $user_info['id']; $insert['create_time'] = time(); $insert['update_time'] = strtotime($params['date_time']); $insert['order_type'] = 2;//服务器 $insert['order_no'] = 'S' . $user_info['id'] . time(); $insert['server_no'] = $params['server_no']; $insert['pro_name'] = $params['pro_name']; $insert['amount'] = $params['amount']; $insert['power'] = $params['power']; $insert['status'] = OfflineRechargeRecordModel::StatusSuccess; $insert['tx_hash'] = '手动报单_' . $user_info['id'] . '_操作员ID:' . $this->auth->id. // $pro_info = (new ServersModel()) // ->where('price', $params['price']) // ->find(); // if(empty($pro_info)){ // $this->error(__('没有对应价格的服务器', '')); // } $result = false; Db::startTrans(); try { //$order_id = (new OfflineRechargeRecordModel())->insertGetId(RechargeType::CashFromSys, '后台手动报单,admin_id:' . $this->auth->id . ',时间戳:' . time(), $user_info['id'], $params['price'], RechargeStatus::StatusAuthSuccess); $order_id = (new OfflineRechargeRecordModel())->insertGetId($insert); // 更新总算力和账变 (new LedgerWalletModel)->changeWalletAccount($user_info['id'], Asset::POWER, $insert['power'], Action::PowerRentalPower, $order_id); //(new LedgerWalletModel)->changeWalletAccount($user_info['id'], Asset::SERVER_POWER, $pro_info['power'], Action::PowerRentalPower, $order_id); // 更新服务器算力,不账变 //(new LedgerWalletModel)->changeWalletOnly($user_info['id'], Asset::SERVER_POWER, $insert['power']); // 更新自己激活时间 if($user_info['effective_time'] < 1){ (new UserModel()) ->where('id', $user_info['id']) ->update(['effective_time' => $insert['update_time']]); } // 发放服务器市场推荐相关收益 //(new LedgerWalletModel)->sendServersBonus($user_info['id'], $servers_info); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } $this->success('手动报单成功'); } }