Order.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 报名记录
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Order extends Backend
  11. {
  12. /**
  13. * Order模型对象
  14. * @var \app\admin\model\Order
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Order;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. $this->view->assign("payTypeList", $this->model->getPayTypeList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //当前是否为关联查询
  35. $this->relationSearch = true;
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if ($this->request->isAjax()) {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $list = $this->model
  45. ->with(['active','user','student','school','grade','classes'])
  46. ->where($where)
  47. ->where('(order.pay_type = 1 and order.status = 1) or (order.pay_type = 2)')
  48. ->order($sort, $order)
  49. ->paginate($limit);
  50. foreach ($list as $row) {
  51. $row->getRelation('active')->visible(['name']);
  52. $row->getRelation('user')->visible(['username','nickname']);
  53. $row->getRelation('student')->visible(['realname']);
  54. $row->getRelation('school')->visible(['schoolname']);
  55. $row->getRelation('grade')->visible(['gradename']);
  56. $row->getRelation('classes')->visible(['classname']);
  57. }
  58. $result = array("total" => $list->total(), "rows" => $list->items());
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 审核
  65. */
  66. public function audit($ids = null)
  67. {
  68. $row = $this->model->get($ids);
  69. if (!$row) {
  70. $this->error(__('No Results were found'));
  71. }
  72. $adminIds = $this->getDataLimitAdminIds();
  73. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  74. $this->error(__('You have no permission'));
  75. }
  76. if (false === $this->request->isPost()) {
  77. $this->view->assign('row', $row);
  78. return $this->view->fetch();
  79. }
  80. $params = $this->request->post('row/a');
  81. if (empty($params)) {
  82. $this->error(__('Parameter %s can not be empty', ''));
  83. }
  84. $params = $this->preExcludeFields($params);
  85. $result = false;
  86. Db::startTrans();
  87. try {
  88. //是否采用模型验证
  89. if ($this->modelValidate) {
  90. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  91. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  92. $row->validateFailException()->validate($validate);
  93. }
  94. $result = $row->allowField(true)->save($params);
  95. Db::commit();
  96. } catch (ValidateException|PDOException|Exception $e) {
  97. Db::rollback();
  98. $this->error($e->getMessage());
  99. }
  100. if (false === $result) {
  101. $this->error(__('No rows were updated'));
  102. }
  103. $this->success();
  104. }
  105. }