Order.php 2.9 KB

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