Orderinvoice.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\admin\controller\pricing;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\DbException;
  6. use think\exception\PDOException;
  7. use think\exception\ValidateException;
  8. /**
  9. * 开票管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Orderinvoice extends Backend
  14. {
  15. /**
  16. * OrderInvoice模型对象
  17. * @var \app\common\model\OrderInvoice
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\common\model\OrderInvoice;
  24. }
  25. /**
  26. * 编辑
  27. *
  28. * @param $ids
  29. * @return string
  30. * @throws DbException
  31. * @throws \think\Exception
  32. */
  33. public function edit($ids = null)
  34. {
  35. $row = $this->model->get($ids);
  36. if (!$row) {
  37. $this->error(__('No Results were found'));
  38. }
  39. $adminIds = $this->getDataLimitAdminIds();
  40. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  41. $this->error(__('You have no permission'));
  42. }
  43. if (false === $this->request->isPost()) {
  44. $this->view->assign('row', $row);
  45. return $this->view->fetch();
  46. }
  47. $params = $this->request->post('row/a');
  48. if (empty($params)) {
  49. $this->error(__('Parameter %s can not be empty', ''));
  50. }
  51. $params = $this->preExcludeFields($params);
  52. $result = false;
  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()->validate($validate);
  60. }
  61. $result = $row->allowField(true)->save($params);
  62. Db::commit();
  63. } catch (ValidateException|PDOException|Exception $e) {
  64. Db::rollback();
  65. $this->error($e->getMessage());
  66. }
  67. if (false === $result) {
  68. $this->error(__('No rows were updated'));
  69. }
  70. $this->success();
  71. }
  72. }