DevelopmentCase.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Lang;
  4. class DevelopmentCase extends AdminControl
  5. {
  6. public function _initialize()
  7. {
  8. parent::_initialize();
  9. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/product.lang.php');
  10. }
  11. /**
  12. * 开发案例
  13. */
  14. public function index(){
  15. $model_Case = Model('DevelopmentCase');
  16. $case_keywords = input('post.product_keywords');
  17. $case_type = input('post.product_type');
  18. $condition = array();
  19. if($case_keywords){
  20. $condition['product_keywords'] = $case_keywords;
  21. }
  22. if($case_type){
  23. $condition['product_type'] = $case_type;
  24. }
  25. $case_list = $model_Case->getDevelopmentCase($condition,'*',10);
  26. for($i=0;$i<count($case_list);$i++){
  27. $case_list[$i]['add_time'] = date("Y-m-d h:i:s",$case_list[$i]['add_time']);
  28. $case_list[$i]['update_time'] = date("Y-m-d h:i:s",$case_list[$i]['update_time']);
  29. }
  30. $allpower = $this->qxhans();
  31. $this->assign('allpower',$allpower);
  32. $this->assign('case_list', $case_list);
  33. //$this->assign('show_page', $Case_list->page_info->render());
  34. $this->setAdminCurItem('index');
  35. return $this->fetch();
  36. }
  37. /**
  38. * 添加案例
  39. * @return mixed
  40. */
  41. public function add()
  42. {
  43. $allpower = $this->qxhans();
  44. $this->assign('allpower',$allpower);
  45. if (request()->isPost()) {
  46. if(input('post.status') == ""){
  47. $data = array(
  48. 'name' => input('post.name'),
  49. 'sort' => input('post.sort'),
  50. 'type' => input('post.type'),
  51. 'add_time' => time(),
  52. 'update_time' => time(),
  53. 'status' => '0',
  54. );
  55. }else{
  56. $data = array(
  57. 'name' => input('post.name'),
  58. 'sort' => input('post.sort'),
  59. 'type' => input('post.type'),
  60. 'add_time' => time(),
  61. 'update_time' => time(),
  62. 'status' => input('post.status'),
  63. );
  64. }
  65. $imgurl = DS_THEME_STYLE_URL . 'images/team';
  66. $numurl = '/static/home/images/team';
  67. $file = request()->file('image');
  68. if($file){
  69. $imgname = time().'.jpg';
  70. $file = $file->setSaveName($imgname);//设置保存文件名
  71. $imgo = $file->move($imgurl, $savename = $imgname, $replace = true);
  72. if($imgo){
  73. $data['img_url'] =$numurl.'/'.$imgname;
  74. }
  75. }
  76. $result = model('DevelopmentCase')->addCase($data);
  77. if ($result){
  78. $this->success(lang('add_succ'), url('DevelopmentCase/index'));
  79. }
  80. $this->error(lang('add_fail'));
  81. } else {
  82. $case = array('status'=>1);
  83. $this->assign('case', $case);
  84. $this->setAdminCurItem('add');
  85. return $this->fetch('form');
  86. }
  87. }
  88. /**
  89. * 修改案例
  90. * @return mixed
  91. */
  92. public function edit()
  93. {
  94. $allpower = $this->qxhans();
  95. $this->assign('allpower',$allpower);
  96. $id = input('param.id');
  97. if ($id <= 0) {
  98. $this->error('系统错误');
  99. }
  100. $condition['id'] = $id;
  101. if (request()->isPost()) {
  102. $data = array(
  103. 'name' => input('post.name'),
  104. 'sort' => input('post.sort'),
  105. 'update_time' => time(),
  106. 'status' => input('post.status'),
  107. );
  108. $imgurl = DS_THEME_STYLE_URL . 'images/team';
  109. $numurl = '/static/home/images/team';
  110. $file = request()->file('image');
  111. if($file){
  112. $imgname = time().'.jpg';
  113. $file = $file->setSaveName($imgname);//设置保存文件名
  114. $imgo = $file->move($imgurl, $savename = $imgname, $replace = true);
  115. if($imgo){
  116. $data['img_url'] =$numurl.'/'.$imgname;
  117. }
  118. }
  119. $result = model('DevelopmentCase')->edit(['id' => $id], $data);
  120. if ($result >= 0) {
  121. $this->success(lang('edit_succ'), 'DevelopmentCase/index');
  122. } else {
  123. $this->error(lang('edit_fail'));
  124. }
  125. } else {
  126. $case = model('DevelopmentCase')->getOneCase(['id' => $id]);
  127. $this->assign('case', $case);
  128. $this->setAdminCurItem('edit');
  129. return $this->fetch('form');
  130. }
  131. }
  132. /**
  133. * 删除案例
  134. * @return mixed
  135. */
  136. function del()
  137. {
  138. $id = intval(input('param.id'));
  139. if ($id) {
  140. $condition['id'] = $id;
  141. $result = model('DevelopmentCase')->deleteCase($condition);
  142. if ($result) {
  143. ds_json_encode(10000, lang('del_succ'));
  144. } else {
  145. ds_json_encode(10001, lang('del_fail'));
  146. }
  147. } else {
  148. ds_json_encode(10001, lang('param_error'));
  149. }
  150. }
  151. }