LedgerPowerChange.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\admin\controller\ledger;
  3. use app\common\controller\Backend;
  4. use app\common\model\UserModel;
  5. use fast\Action;
  6. use fast\RechargeStatus;
  7. use fast\RechargeType;
  8. use think\exception\DbException;
  9. use think\response\Json;
  10. /**
  11. * 算力变动明细管理
  12. *
  13. * @icon fa fa-circle-o
  14. */
  15. class LedgerPowerChange extends Backend
  16. {
  17. /**
  18. * LedgerPowerChange模型对象
  19. * @var \app\admin\model\LedgerPowerChange
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\LedgerPowerChange;
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 查看
  34. *
  35. * @return string|Json
  36. * @throws \think\Exception
  37. * @throws DbException
  38. */
  39. public function index()
  40. {
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. if (false === $this->request->isAjax()) {
  44. return $this->view->fetch();
  45. }
  46. //如果发送的来源是 Selectpage,则转发到 Selectpage
  47. if ($this->request->request('keyField')) {
  48. return $this->selectpage();
  49. }
  50. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  51. $list = $this->model->alias('r')
  52. ->join('user u','r.user_id=u.id','LEFT')
  53. ->where($where)
  54. ->field('r.*,u.address')
  55. ->order($sort, $order)
  56. ->paginate($limit);
  57. foreach ($list as $k => $v) {
  58. $list[$k]['address'] = (new UserModel())->getById($v['user_id'])['address'];
  59. }
  60. $result = ['total' => $list->total(), 'rows' => $list->items()];
  61. return json($result);
  62. }
  63. }