LedgerTokenChange.php 2.0 KB

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