Userpledge.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\model\ProductLists;
  5. use think\exception\DbException;
  6. use think\response\Json;
  7. /**
  8. * 用户存储列表 TeamRewards
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Userpledge extends Backend
  13. {
  14. /**
  15. * TeamRewards模型对象
  16. * @var \app\admin\model\TeamRewards
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\common\model\UserPledge;
  23. }
  24. /**
  25. * 查看
  26. *
  27. * @return string|Json
  28. * @throws \think\Exception
  29. * @throws DbException
  30. */
  31. public function index()
  32. {
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags', 'trim']);
  35. if (false === $this->request->isAjax()) {
  36. return $this->view->fetch();
  37. }
  38. //如果发送的来源是 Selectpage,则转发到 Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  43. $list = $this->model->with('users,pledges')
  44. ->where($where)
  45. ->order($sort, $order)
  46. ->paginate($limit);
  47. $result = ['total' => $list->total(), 'rows' => $list->items()];
  48. return json($result);
  49. }
  50. /**
  51. * 详情
  52. */
  53. public function detail($ids)
  54. {
  55. $row = $this->model->get(['id' => $ids]);
  56. if (!$row) {
  57. $this->error(__('No Results were found'));
  58. }
  59. if ($this->request->isAjax()) {
  60. $this->success("Ajax请求成功", null, ['id' => $ids]);
  61. }
  62. $product = new ProductLists();
  63. $details = json_decode($row->details, true);
  64. foreach ($details as &$detail) {
  65. $detail['name'] = $product::where('id', $detail['id'])->value('zh_name');
  66. }
  67. $this->view->assign("row", $details);
  68. return $this->view->fetch();
  69. }
  70. }