UserMoneyLog.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\model\MoneyLog;
  5. /**
  6. * 会员余额变动管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class UserMoneyLog extends Backend
  11. {
  12. protected $noNeedLogin=['types'];
  13. protected $relationSearch=true;
  14. /**
  15. * UserMoneyLog模型对象
  16. * @var \app\admin\model\UserMoneyLog
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\UserMoneyLog;
  23. }
  24. public function import()
  25. {
  26. parent::import();
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. //当前是否为关联查询
  39. $this->relationSearch = true;
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if ($this->request->isAjax()) {
  43. //如果发送的来源是Selectpage,则转发到Selectpage
  44. if ($this->request->request('keyField')) {
  45. return $this->selectpage();
  46. }
  47. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48. $list = $this->model
  49. ->with(['user'])
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. $money=$this->model->with('user')->where($where)->sum($this->model->getTable().'.money');
  54. foreach ($list as $row) {
  55. $row->visible(['id','type','money','before','after','memo','createtime']);
  56. $row->visible(['user']);
  57. $row->getRelation('user')->visible(['nickname']);
  58. }
  59. $result = array("total" => $list->total(), "rows" => $list->items(),'money'=>$money);
  60. return json($result);
  61. }
  62. return $this->view->fetch();
  63. }
  64. public function types(){
  65. return MoneyLog::$types;
  66. }
  67. }