Order.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. protected $relationSearch = true;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\common\model\Order;
  26. $this->view->assign("statusList", $this->model->getstatusList());
  27. }
  28. /**
  29. * 查看
  30. *
  31. * @return string|Json
  32. * @throws \think\Exception
  33. * @throws DbException
  34. */
  35. public function index()
  36. {
  37. //设置过滤方法
  38. $this->request->filter(['strip_tags', 'trim']);
  39. if (false === $this->request->isAjax()) {
  40. return $this->view->fetch();
  41. }
  42. //如果发送的来源是 Selectpage,则转发到 Selectpage
  43. if ($this->request->request('keyField')) {
  44. return $this->selectpage();
  45. }
  46. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  47. $list = $this->model->with('users')
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. $result = ['total' => $list->total(), 'rows' => $list->items()];
  52. return json($result);
  53. }
  54. /**
  55. * 操作
  56. * @param $ids
  57. * @return string
  58. * @throws DbException
  59. * @throws \think\Exception
  60. */
  61. public function operate($ids = null, $status = 0)
  62. {
  63. $row = $this->model->get($ids);
  64. if (!$row) {
  65. $this->error(__('No Results were found'));
  66. }
  67. $adminIds = $this->getDataLimitAdminIds();
  68. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  69. $this->error(__('You have no permission'));
  70. }
  71. if (empty($status)) {
  72. $this->error(__('Parameter %s can not be empty', ''));
  73. }
  74. $result = false;
  75. Db::startTrans();
  76. try {
  77. //是否采用模型验证
  78. if ($this->modelValidate) {
  79. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  80. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  81. $row->validateFailException()->validate($validate);
  82. }
  83. $result = $row->allowField(true)->save(['status'=>$status]);
  84. Db::commit();
  85. } catch (ValidateException|PDOException|Exception $e) {
  86. Db::rollback();
  87. $this->error($e->getMessage());
  88. }
  89. if (false === $result) {
  90. $this->error(__('No rows were updated'));
  91. }
  92. $this->success();
  93. }
  94. }