DevelopmentCase.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. $data = array(
  47. 'name' => input('post.name'),
  48. 'sort' => input('post.sort'),
  49. 'type' => input('post.type'),
  50. 'add_time' => time(),
  51. 'update_time' => time(),
  52. 'status' => input('post.status'),
  53. );
  54. $imgurl = DS_THEME_STYLE_URL . 'images/team';
  55. $numurl = '/static/home/images/team';
  56. $file = request()->file('image');
  57. if($file){
  58. $imgname = time().'.jpg';
  59. $file = $file->setSaveName($imgname);//设置保存文件名
  60. $imgo = $file->move($imgurl, $savename = $imgname, $replace = true);
  61. if($imgo){
  62. $data['img_url'] =$numurl.'/'.$imgname;
  63. }
  64. }
  65. $result = model('DevelopmentCase')->addCase($data);
  66. if ($result){
  67. $this->success(lang('add_succ'), url('DevelopmentCase/index'));
  68. }
  69. $this->error(lang('add_fail'));
  70. } else {
  71. $case = array('status'=>1);
  72. $this->assign('case', $case);
  73. $this->setAdminCurItem('add');
  74. return $this->fetch('form');
  75. }
  76. }
  77. /**
  78. * 修改案例
  79. * @return mixed
  80. */
  81. public function edit()
  82. {
  83. $allpower = $this->qxhans();
  84. $this->assign('allpower',$allpower);
  85. $id = input('param.id');
  86. if ($id <= 0) {
  87. $this->error('系统错误');
  88. }
  89. $condition['id'] = $id;
  90. if (request()->isPost()) {
  91. $data = array(
  92. 'name' => input('post.name'),
  93. 'sort' => input('post.sort'),
  94. 'update_time' => time(),
  95. 'status' => input('post.status'),
  96. );
  97. $imgurl = DS_THEME_STYLE_URL . 'images/team';
  98. $numurl = '/static/home/images/team';
  99. $file = request()->file('image');
  100. if($file){
  101. $imgname = time().'.jpg';
  102. $file = $file->setSaveName($imgname);//设置保存文件名
  103. $imgo = $file->move($imgurl, $savename = $imgname, $replace = true);
  104. if($imgo){
  105. $data['img_url'] =$numurl.'/'.$imgname;
  106. }
  107. }
  108. $result = model('DevelopmentCase')->edit(['id' => $id], $data);
  109. if ($result >= 0) {
  110. $this->success(lang('edit_succ'), 'DevelopmentCase/index');
  111. } else {
  112. $this->error(lang('edit_fail'));
  113. }
  114. } else {
  115. $case = model('DevelopmentCase')->getOneCase(['id' => $id]);
  116. $this->assign('case', $case);
  117. $this->setAdminCurItem('edit');
  118. return $this->fetch('form');
  119. }
  120. }
  121. /**
  122. * 删除案例
  123. * @return mixed
  124. */
  125. function del()
  126. {
  127. $id = intval(input('param.id'));
  128. if ($id) {
  129. $condition['id'] = $id;
  130. $result = model('DevelopmentCase')->deleteCase($condition);
  131. if ($result) {
  132. ds_json_encode(10000, lang('del_succ'));
  133. } else {
  134. ds_json_encode(10001, lang('del_fail'));
  135. }
  136. } else {
  137. ds_json_encode(10001, lang('param_error'));
  138. }
  139. }
  140. }