LedgerDeclarationChange.php 2.0 KB

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