Modelx.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\common\controller\Backend;
  4. use think\Exception;
  5. /**
  6. * 内容模型表
  7. *
  8. * @icon fa fa-th
  9. */
  10. class Modelx extends Backend
  11. {
  12. /**
  13. * Model模型对象
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\cms\Modelx;
  20. }
  21. /**
  22. * 复制模型
  23. */
  24. public function duplicate($ids = "")
  25. {
  26. $row = $this->model->get($ids);
  27. if (!$row) {
  28. $this->error(__('No Results were found'));
  29. }
  30. $adminIds = $this->getDataLimitAdminIds();
  31. if (is_array($adminIds)) {
  32. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  33. $this->error(__('You have no permission'));
  34. }
  35. }
  36. if ($this->request->isPost()) {
  37. $table = $this->request->request("table");
  38. try {
  39. $data = [
  40. 'name' => $row->getData('name') . '_copy',
  41. 'table' => $table,
  42. 'fields' => $row->fields,
  43. 'channeltpl' => $row->channeltpl,
  44. 'listtpl' => $row->listtpl,
  45. 'showtpl' => $row->showtpl,
  46. 'setting' => $row->setting,
  47. ];
  48. $modelx = \app\admin\model\cms\Modelx::create($data, true);
  49. $fieldsList = \app\admin\model\cms\Fields::where('source', 'model')->where('source_id', $row['id'])->select();
  50. foreach ($fieldsList as $index => $item) {
  51. $data = $item->toArray();
  52. $data['source_id'] = $modelx->id;
  53. unset($data['id'], $data['createtime'], $data['updatetime']);
  54. \app\admin\model\cms\Fields::create($data, true);
  55. }
  56. } catch (Exception $e) {
  57. $this->error("复制失败,错误:" . $e->getMessage());
  58. }
  59. $this->success();
  60. }
  61. $this->view->assign("row", $row);
  62. return $this->view->fetch();
  63. }
  64. }