Teacs.php 2.9 KB

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