|
|
@@ -3,18 +3,6 @@
|
|
|
namespace app\admin\controller\offline;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
-use app\common\model\LedgerWalletModel;
|
|
|
-use app\common\model\OfflineRechargeRecordModel;
|
|
|
-use app\common\model\ServersModel;
|
|
|
-use app\common\model\UserModel;
|
|
|
-use fast\Action;
|
|
|
-use fast\Asset;
|
|
|
-use fast\RechargeStatus;
|
|
|
-use fast\RechargeType;
|
|
|
-use fast\WithdrawStatus;
|
|
|
-use think\exception\DbException;
|
|
|
-use think\response\Json;
|
|
|
-use think\Db;
|
|
|
|
|
|
/**
|
|
|
* 充值记录管理
|
|
|
@@ -25,15 +13,15 @@ class OfflineRecharge extends Backend
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
- * OfflineRechargeRecord模型对象
|
|
|
- * @var \app\admin\model\OfflineRechargeRecord
|
|
|
+ * Offline_recharge模型对象
|
|
|
+ * @var \app\admin\model\offline\OfflineRecharge
|
|
|
*/
|
|
|
protected $model = null;
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
- $this->model = new \app\admin\model\OfflineRechargeRecord;
|
|
|
+ $this->model = new \app\common\model\OfflineWithdrawRecordModel;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -45,178 +33,4 @@ class OfflineRecharge extends Backend
|
|
|
*/
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 查看
|
|
|
- *
|
|
|
- * @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('手动报单成功');
|
|
|
- }
|
|
|
}
|