Order.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\controller\trade;
  3. use think\Db;
  4. use Exception;
  5. use think\exception\DbException;
  6. use think\exception\PDOException;
  7. use app\common\controller\Backend;
  8. use think\exception\ValidateException;
  9. /**
  10. * 充值记录管理
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class Order extends Backend
  15. {
  16. /**
  17. * Order模型对象
  18. * @var \app\admin\model\trade\Order
  19. */
  20. protected $model = null;
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new \app\common\model\Order;
  25. $this->view->assign("statusList", $this->model->getstatusList());
  26. }
  27. /**
  28. * 查看
  29. *
  30. * @return string|Json
  31. * @throws \think\Exception
  32. * @throws DbException
  33. */
  34. public function index()
  35. {
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if (false === $this->request->isAjax()) {
  39. return $this->view->fetch();
  40. }
  41. //如果发送的来源是 Selectpage,则转发到 Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  46. $list = $this->model->with('users')
  47. ->where($where)
  48. ->order($sort, $order)
  49. ->paginate($limit);
  50. $result = ['total' => $list->total(), 'rows' => $list->items()];
  51. return json($result);
  52. }
  53. /**
  54. * 操作
  55. * @param $ids
  56. * @return string
  57. * @throws DbException
  58. * @throws \think\Exception
  59. */
  60. public function operate($ids = null)
  61. {
  62. $row = $this->model->get($ids);
  63. if (!$row) {
  64. $this->error(__('No Results were found'));
  65. }
  66. $adminIds = $this->getDataLimitAdminIds();
  67. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  68. $this->error(__('You have no permission'));
  69. }
  70. if (false === $this->request->isPost()) {
  71. $this->view->assign('row', $row);
  72. return $this->view->fetch();
  73. }
  74. $params = $this->request->post('row/a');
  75. if (empty($params)) {
  76. $this->error(__('Parameter %s can not be empty', ''));
  77. }
  78. $params = $this->preExcludeFields($params);
  79. $result = false;
  80. Db::startTrans();
  81. try {
  82. //是否采用模型验证
  83. if ($this->modelValidate) {
  84. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  85. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  86. $row->validateFailException()->validate($validate);
  87. }
  88. $result = $row->allowField(true)->save($params);
  89. Db::commit();
  90. } catch (ValidateException|PDOException|Exception $e) {
  91. Db::rollback();
  92. $this->error($e->getMessage());
  93. }
  94. if (false === $result) {
  95. $this->error(__('No rows were updated'));
  96. }
  97. $this->success();
  98. }
  99. }