Sharedesc.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wanggb
  5. * Date: 2019/2/19
  6. * Time: 18:00
  7. */
  8. namespace app\admin\controller\manage;
  9. use app\common\controller\Backend;
  10. class Sharedesc extends Backend
  11. {
  12. /**
  13. * ManageSharedesc模型对象
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = model('ManageSharedesc');
  20. $this->view->assign("statusList", $this->model->getStatusList());
  21. $this->view->assign("sectionList", $this->model->getSectionList());
  22. }
  23. /**
  24. * 添加
  25. */
  26. public function addmany()
  27. {
  28. if ($this->request->isPost())
  29. {
  30. $time = time();
  31. $desc = $this->request->post('desc');
  32. $section = $this->request->post('section');
  33. $status = $this->request->post('status');
  34. if ($desc)
  35. {
  36. $str = str_replace(array("\r\n", "\r", "\n"), "||", $desc);
  37. $descArr = explode("||",$str);
  38. $insertList = [];
  39. foreach($descArr as $val){
  40. if ($val) {
  41. $tmp = [
  42. 'desc' => trim($val),
  43. 'status' => $status,
  44. 'createtime' => $time,
  45. 'updatetime' => $time,
  46. 'section' => $section,
  47. ];
  48. $insertList[] = $tmp;
  49. }
  50. }
  51. try
  52. {
  53. $result = $this->model->insertAll($insertList);
  54. if ($result !== false)
  55. {
  56. return json_encode(['success'=>1]);
  57. }
  58. else
  59. {
  60. $this->error($this->model->getError());
  61. }
  62. }
  63. catch (\think\exception\PDOException $e)
  64. {
  65. $this->error($e->getMessage());
  66. }
  67. }
  68. $this->error(__('Parameter %s can not be empty', ''));
  69. }
  70. return $this->view->fetch();
  71. }
  72. public function index()
  73. {
  74. //设置过滤方法
  75. $this->request->filter(['strip_tags']);
  76. if ($this->request->isAjax())
  77. {
  78. //如果发送的来源是Selectpage,则转发到Selectpage
  79. if ($this->request->request('pkey_name'))
  80. {
  81. return $this->selectpage();
  82. }
  83. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  84. $whereArr = [];
  85. if (strtolower($this->request->action()) == 'select') {
  86. $whereArr[] = ['status', '=', 'normal'];
  87. $whereArr = function($query) use ($whereArr) {
  88. foreach ($whereArr as $k => $v)
  89. {
  90. if (is_array($v))
  91. {
  92. call_user_func_array([$query, 'where'], $v);
  93. }
  94. else
  95. {
  96. $query->where($v);
  97. }
  98. }
  99. };
  100. }
  101. $total = $this->model
  102. ->where($where)
  103. ->where($whereArr)
  104. ->order($sort, $order)
  105. ->count();
  106. $list = $this->model
  107. ->where($where)
  108. ->where($whereArr)
  109. ->order($sort, $order)
  110. ->limit($offset, $limit)
  111. ->select();
  112. $result = array("total" => $total, "rows" => $list);
  113. return json($result);
  114. }
  115. return $this->view->fetch();
  116. }
  117. public function select()
  118. {
  119. return $this->index();
  120. }
  121. }