News.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace app\home\controller;
  3. use think\Lang;
  4. class News extends AdminControl
  5. {
  6. public function _initialize()
  7. {
  8. parent::_initialize();
  9. Lang::load(APP_PATH . 'home/lang/' . config('default_lang') . '/product.lang.php');
  10. }
  11. public function index()
  12. {
  13. $model_product = Model('product');
  14. $product_keywords = input('post.product_keywords');
  15. $condition = array();
  16. $condition['product_type'] = array('eq',5);
  17. $condition['product_companyid'] = session('service_pid');
  18. $product_list = $model_product->getProductList($condition,'*',10);
  19. if($product_list){
  20. for ($i=0; $i < count($product_list); $i++) {
  21. $where['member_id'] = $product_list[$i]['product_companyid'];
  22. $gsname_list[] = model('member')->getMemberInfo($where,$field = 'member_name');
  23. }
  24. $this->assign('gsname_list',$gsname_list);
  25. for ($ie=0; $ie < count($product_list); $ie++) {
  26. $con = $product_list[$ie]['product_content'];
  27. $pattern="/<[img|IMG].*?src=[\'\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
  28. $replacement = '';
  29. $conlist[] = mb_substr(preg_replace($pattern,$replacement ,$con),0,20);
  30. }
  31. $this->assign('conlist',$conlist);
  32. }
  33. $allpower = $this->qxhans();
  34. $this->assign('allpower',$allpower);
  35. $this->assign('product_list', $product_list);
  36. $this->assign('show_page', $model_product->page_info->render());
  37. $this->setAdminCurItem('index');
  38. return $this->fetch();
  39. }
  40. public function add()
  41. {
  42. $allpower = $this->qxhans();
  43. $this->assign('allpower',$allpower);
  44. if (request()->isPost()) {
  45. $data = array(
  46. 'product_type' => 5,
  47. 'product_companyid' => session('service_pid'),
  48. 'product_title' => input('post.product_title'),
  49. 'product_ctitle' => input('post.product_ctitle'),
  50. 'product_keywords' => input('post.product_keywords'),
  51. 'product_status' => input('post.product_status'),
  52. 'product_isjump' => input('post.product_isjump'),
  53. 'product_content' => input('post.product_content'),
  54. );
  55. if (!input('param.product_addtime')) {
  56. $data['product_addtime'] = TIMESTAMP;
  57. } else {
  58. $data['product_addtime'] = strtotime(input('param.product_addtime'));
  59. }
  60. $result = model('product')->addproduct($data);
  61. if ($result){
  62. $this->success(lang('add_succ'), url('news/index'));
  63. }
  64. $this->error(lang('add_fail'));
  65. } else {
  66. $product = array(
  67. 'product_isjump' => 0,
  68. 'product_status' => 0,
  69. );
  70. $pic_list = model('pic')->getPicList(array('pic_id' => 0));
  71. $this->assign('product', $product);
  72. $this->assign('product_pic_type', ['pic_type' => 'product']);
  73. $this->assign('pic_list', $pic_list);
  74. $this->setAdminCurItem('add');
  75. return $this->fetch('form');
  76. }
  77. }
  78. public function edit()
  79. {
  80. $allpower = $this->qxhans();
  81. $this->assign('allpower',$allpower);
  82. $product_id = input('param.product_id');
  83. if ($product_id <= 0) {
  84. $this->error('系统错误');
  85. }
  86. $condition['pic_type'] = 'product';
  87. $condition['pic_type_id'] = $product_id;
  88. if (request()->isPost()) {
  89. $data = array(
  90. 'product_title' => input('post.product_title'),
  91. 'product_ctitle' => input('post.product_ctitle'),
  92. 'product_keywords' => input('post.product_keywords'),
  93. 'product_status' => input('post.product_status'),
  94. 'product_isjump' => input('post.product_isjump'),
  95. 'product_content' => input('post.product_content'),
  96. );
  97. if (!input('param.product_updatetime')) {
  98. $data['product_updatetime'] = TIMESTAMP;
  99. } else {
  100. $data['product_updatetime'] = strtotime(input('param.product_updatetime'));
  101. }
  102. $result = model('product')->editproduct(['product_id' => $product_id], $data);
  103. if ($result >= 0) {
  104. $this->success(lang('edit_succ'), 'news/index');
  105. } else {
  106. $this->error(lang('edit_fail'));
  107. }
  108. } else {
  109. $pic_list = model('pic')->getpicList($condition);
  110. $this->assign('pic_list', $pic_list);
  111. $product = model('product')->getOneProduct(['product_id' => $product_id]);
  112. $where['member_id'] = $product['product_companyid'];
  113. $this->assign('product_pic_type', ['pic_type' => 'product']);
  114. $this->assign('product', $product);
  115. $this->setAdminCurItem('edit');
  116. return $this->fetch('form');
  117. }
  118. }
  119. function del()
  120. {
  121. $product_id = intval(input('param.product_id'));
  122. if ($product_id) {
  123. $condition['product_id'] = $product_id;
  124. $result = model('product')->delproduct($condition);
  125. if ($result) {
  126. ds_json_encode(10000, lang('del_succ'));
  127. } else {
  128. ds_json_encode(10001, lang('del_fail'));
  129. }
  130. } else {
  131. ds_json_encode(10001, lang('param_error'));
  132. }
  133. }
  134. function ajax()
  135. {
  136. $branch = input('param.branch');
  137. switch ($branch) {
  138. case 'product':
  139. $product_mod = model('product');
  140. $condition = array('product_id' => intval(input('param.id')));
  141. $update[input('param.column')] = input('param.value');
  142. $product_mod->editproduct($condition, $update);
  143. echo 'true';
  144. }
  145. }
  146. function setproduct()
  147. {
  148. $product_type = input('param.product_type');
  149. $product_id = input('param.product_id');
  150. $res = model('product')->getOneProduct(['product_id' => $product_id], $product_type);
  151. $id = $res[$product_type] == 0 ? 1 : 0;
  152. $update[$product_type] = $id;
  153. $condition['product_id'] = $product_id;
  154. if (model('product')->editproduct($condition, $update)) {
  155. ds_json_encode(10000, lang('edit_succ'));
  156. } else {
  157. $this->error(lang('edit_fail'));
  158. }
  159. }
  160. protected function getAdminItemList()
  161. {
  162. $menu_array = array(
  163. array(
  164. 'name' => 'index', 'text' => '管理', 'url' => url('News/index')
  165. ), array(
  166. 'name' => 'add', 'text' => '新增', 'url' => url('News/add')
  167. ),
  168. );
  169. if (request()->action() == 'edit') {
  170. $menu_array[] = array(
  171. 'name' => 'edit', 'text' => '编辑', 'url' => url('News/edit')
  172. );
  173. }
  174. return $menu_array;
  175. }
  176. }