Sharetitle.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\admin\controller\manage;
  3. use app\common\controller\Backend;
  4. use think\Controller;
  5. use think\Request;
  6. /**
  7. * 运营者-分享标题
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Sharetitle extends Backend
  12. {
  13. /**
  14. * ManageSharetitle模型对象
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = model('ManageSharetitle');
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. $this->view->assign("sexList", $this->model->getSexList());
  23. }
  24. /**
  25. * 添加
  26. */
  27. public function addmany()
  28. {
  29. if ($this->request->isPost())
  30. {
  31. $time = time();
  32. $title = $this->request->post('title');
  33. $sex = $this->request->post('sex');
  34. $status = $this->request->post('status');
  35. if ($title)
  36. {
  37. $str = str_replace(array("\r\n", "\r", "\n"), "||", $title);
  38. $titleArr = explode("||",$str);
  39. $queryStr = '';
  40. foreach($titleArr as $val){
  41. $queryStr.= "('".trim($val)."','{$status}',{$time},{$time},'{$sex}'),";
  42. }
  43. $queryStr = substr($queryStr,0,-1);
  44. $sql = "insert into manage_sharetitle (title,status,createtime,updatetime,sex) values ".$queryStr;
  45. try
  46. {
  47. $result = $this->model->query($sql);
  48. if ($result !== false)
  49. {
  50. return json_encode(['success'=>1]);
  51. }
  52. else
  53. {
  54. $this->error($this->model->getError());
  55. }
  56. }
  57. catch (\think\exception\PDOException $e)
  58. {
  59. $this->error($e->getMessage());
  60. }
  61. }
  62. $this->error(__('Parameter %s can not be empty', ''));
  63. }
  64. return $this->view->fetch();
  65. }
  66. /**
  67. * 查看
  68. */
  69. public function index()
  70. {
  71. //设置过滤方法
  72. $this->request->filter(['strip_tags']);
  73. if ($this->request->isAjax())
  74. {
  75. //如果发送的来源是Selectpage,则转发到Selectpage
  76. if ($this->request->request('pkey_name'))
  77. {
  78. return $this->selectpage();
  79. }
  80. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  81. $whereArr = [];
  82. if (strtolower($this->request->action()) == 'select') {
  83. $whereArr[] = ['status', '=', 'normal'];
  84. $whereArr = function($query) use ($whereArr) {
  85. foreach ($whereArr as $k => $v)
  86. {
  87. if (is_array($v))
  88. {
  89. call_user_func_array([$query, 'where'], $v);
  90. }
  91. else
  92. {
  93. $query->where($v);
  94. }
  95. }
  96. };
  97. }
  98. $total = $this->model
  99. ->where($where)
  100. ->where($whereArr)
  101. ->order($sort, $order)
  102. ->count();
  103. $list = $this->model
  104. ->where($where)
  105. ->where($whereArr)
  106. ->order($sort, $order)
  107. ->limit($offset, $limit)
  108. ->select();
  109. $result = array("total" => $total, "rows" => $list);
  110. return json($result);
  111. }
  112. return $this->view->fetch();
  113. }
  114. /**
  115. * 选择标题
  116. */
  117. public function select()
  118. {
  119. if ($this->request->isAjax()) {
  120. return $this->index();
  121. }
  122. return $this->view->fetch();
  123. }
  124. /**
  125. * ajax方法转发index,用于渠道商/代理商API请求
  126. * @return string|\think\response\Json
  127. */
  128. public function ajax()
  129. {
  130. return $this->index();
  131. }
  132. }