Image.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\admin\controller\massager;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. use think\exception\ValidateException;
  7. /**
  8. * 照片审核
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Image extends Backend
  13. {
  14. /**
  15. * Image模型对象
  16. * @var \app\admin\model\massager\Image
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\massager\Image;
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. //当前是否为关联查询
  36. $this->relationSearch = true;
  37. //设置过滤方法
  38. $this->request->filter(['strip_tags', 'trim']);
  39. if ($this->request->isAjax()) {
  40. //如果发送的来源是Selectpage,则转发到Selectpage
  41. if ($this->request->request('keyField')) {
  42. return $this->selectpage();
  43. }
  44. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  45. $list = $this->model
  46. ->with(['massager'])
  47. ->where($where)
  48. ->order($sort, $order)
  49. ->paginate($limit);
  50. foreach ($list as $row) {
  51. $row->visible(['id', 'massager_id', 'photo_images', 'info_video_file', 'certification_image', 'license_image', 'id_card_images', 'health_image', 'police_certificate_image', 'status', 'updatetime']);
  52. $row->visible(['massager']);
  53. $row->getRelation('massager')->visible(['name']);
  54. }
  55. $result = array("total" => $list->total(), "rows" => $list->items());
  56. return json($result);
  57. }
  58. return $this->view->fetch();
  59. }
  60. public function edit($ids = null)
  61. {
  62. $row = $this->model->get($ids);
  63. if (!$row) {
  64. $this->error(__('No Results were found'));
  65. }
  66. $adminIds = $this->getDataLimitAdminIds();
  67. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  68. $this->error(__('You have no permission'));
  69. }
  70. if (false === $this->request->isPost()) {
  71. $this->view->assign('row', $row);
  72. return $this->view->fetch();
  73. }
  74. $params = $this->request->post('row/a');
  75. if (empty($params)) {
  76. $this->error(__('Parameter %s can not be empty', ''));
  77. }
  78. $params = $this->preExcludeFields($params);
  79. $result = false;
  80. Db::startTrans();
  81. try {
  82. //是否采用模型验证
  83. if ($this->modelValidate) {
  84. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  85. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  86. $row->validateFailException()->validate($validate);
  87. }
  88. $massager = (new \app\admin\model\massager\Massager())->get($params["massager_id"]);
  89. if ($params["status"] === "pass") {
  90. (new \app\admin\model\massager\Massager())->update([
  91. "photo_images" => !(mb_strlen($params["photo_images"]) > 10) ? $massager['photo_images'] : $params['photo_images'],
  92. "info_video_file" => !(mb_strlen($params["info_video_file"]) > 10) ? $massager['info_video_file'] : $params["info_video_file"],
  93. "license_image" => !(mb_strlen($params["license_image"]) > 10) ? $massager["license_image"] : $params["license_image"],
  94. "id_card_images" => !(mb_strlen($params["id_card_images"]) > 10) ? $massager["id_card_images"] : $params["id_card_images"],
  95. "health_image" => !(mb_strlen($params["health_image"]) > 10) ? $massager["health_image"] : $params["health_image"],
  96. "police_certificate_image" => !(mb_strlen($params["police_certificate_image"]) > 10) ? $massager["police_certificate_image"] : $params["police_certificate_image"],
  97. "certification_image" => !(mb_strlen($params["certification_image"]) > 10) ? $massager["certification_image"] : $params["certification_image"]
  98. ], ["id" => $params["massager_id"]]);
  99. }
  100. $result = $row->allowField(true)->save($params);
  101. Db::commit();
  102. } catch (ValidateException | PDOException | Exception $e) {
  103. Db::rollback();
  104. $this->error($e->getMessage());
  105. }
  106. if (false === $result) {
  107. $this->error(__('No rows were updated'));
  108. }
  109. $this->success();
  110. }
  111. }