OrderLog.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. /**
  5. * 订单日志
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class OrderLog extends Backend
  10. {
  11. /**
  12. * @var \app\admin\model\OrderLog
  13. */
  14. protected $model = null;
  15. protected $childrenGroupIds = [];
  16. protected $childrenAdminIds = [];
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = model('OrderLog');
  21. $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
  22. $this->childrenGroupIds = $this->auth->getChildrenGroupIds(true);
  23. // $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds)
  24. // ->column('id,name');
  25. // $this->view->assign('groupdata', $groupName);
  26. }
  27. /**
  28. * 查看
  29. */
  30. public function index()
  31. {
  32. // halt();
  33. //当前是否为关联查询
  34. $this->relationSearch = true;
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags', 'trim']);
  37. if ($this->request->isAjax()) {
  38. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  39. $list = $this->model
  40. ->where($where)
  41. ->with(['order'])
  42. // ->where('admin_id', 'in', $this->childrenAdminIds)
  43. ->order($sort, $order)
  44. ->paginate($limit);
  45. foreach ($list as $row) {
  46. $row->visible(['id','username','updatetime','field','type']);
  47. $row->visible(['order']);
  48. $row->getRelation('order')->visible(['no']);
  49. }
  50. $result = array("total" => $list->total(), "rows" => $list->items());
  51. return json($result);
  52. }
  53. return $this->view->fetch();
  54. }
  55. /**
  56. * 详情
  57. */
  58. public function detail($ids)
  59. {
  60. $row = $this->model->get(['id' => $ids]);
  61. if (!$row) {
  62. $this->error(__('No Results were found'));
  63. }
  64. if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
  65. $this->error(__('You have no permission'));
  66. }
  67. $this->view->assign("row", $row->toArray());
  68. return $this->view->fetch();
  69. }
  70. /**
  71. * 添加
  72. * @internal
  73. */
  74. public function add()
  75. {
  76. $this->error();
  77. }
  78. /**
  79. * 编辑
  80. * @internal
  81. */
  82. public function edit($ids = null)
  83. {
  84. $this->error();
  85. }
  86. /**
  87. * 删除
  88. */
  89. public function del($ids = "")
  90. {
  91. if (!$this->request->isPost()) {
  92. $this->error(__("Invalid parameters"));
  93. }
  94. $ids = $ids ? $ids : $this->request->post("ids");
  95. if ($ids) {
  96. $adminList = $this->model->where('id', 'in', $ids)->where('admin_id', 'in', $this->childrenAdminIds)->select();
  97. if ($adminList) {
  98. $deleteIds = [];
  99. foreach ($adminList as $k => $v) {
  100. $deleteIds[] = $v->id;
  101. }
  102. if ($deleteIds) {
  103. $this->model->destroy($deleteIds);
  104. $this->success();
  105. }
  106. }
  107. }
  108. $this->error();
  109. }
  110. /**
  111. * 批量更新
  112. * @internal
  113. */
  114. public function multi($ids = "")
  115. {
  116. // 管理员禁止批量操作
  117. $this->error();
  118. }
  119. public function selectpage()
  120. {
  121. return parent::selectpage();
  122. }
  123. }