Extendreward.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\admin\controller\agent;
  3. use app\common\controller\Backend;
  4. use Exception;
  5. use Think\Db;
  6. /**
  7. * 推广奖励
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Extendreward extends Backend
  12. {
  13. /**
  14. * Extendreward模型对象
  15. * @var \app\admin\model\agent\Extendreward
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\agent\Extendreward;
  22. }
  23. public function import()
  24. {
  25. parent::import();
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 编辑
  34. */
  35. public function edit($ids = null)
  36. {
  37. $row = $this->model->get($ids);
  38. if (!$row) {
  39. $this->error(__('No Results were found'));
  40. }
  41. $adminIds = $this->getDataLimitAdminIds();
  42. if (is_array($adminIds)) {
  43. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  44. $this->error(__('You have no permission'));
  45. }
  46. }
  47. if ($this->request->isPost()) {
  48. $params = $this->request->post("row/a");
  49. if ($params) {
  50. $params = $this->preExcludeFields($params);
  51. $result = false;
  52. $params['total_reward'] = $params['basic_reward'] + $params['extra_reward'];
  53. Db::startTrans();
  54. try {
  55. //是否采用模型验证
  56. if ($this->modelValidate) {
  57. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  58. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  59. $row->validateFailException(true)->validate($validate);
  60. }
  61. $result = $row->allowField(true)->save($params);
  62. Db::commit();
  63. } catch (ValidateException $e) {
  64. Db::rollback();
  65. $this->error($e->getMessage());
  66. } catch (PDOException $e) {
  67. Db::rollback();
  68. $this->error($e->getMessage());
  69. } catch (Exception $e) {
  70. Db::rollback();
  71. $this->error($e->getMessage());
  72. }
  73. if ($result !== false) {
  74. $this->success();
  75. } else {
  76. $this->error(__('No rows were updated'));
  77. }
  78. }
  79. $this->error(__('Parameter %s can not be empty', ''));
  80. }
  81. $this->view->assign("row", $row);
  82. return $this->view->fetch();
  83. }
  84. }