OurTeam.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Lang;
  4. class OurTeam 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_ourteam = Model('OurTeam');
  16. $ourteam_keywords = input('post.product_keywords');
  17. $ourteam_type = input('post.product_type');
  18. $condition = array();
  19. if($ourteam_keywords){
  20. $condition['product_keywords'] = $ourteam_keywords;
  21. }
  22. if($ourteam_type){
  23. $condition['product_type'] = $ourteam_type;
  24. }
  25. $ourteam_list = $model_ourteam->getOurTeam($condition,'*',10);
  26. for($i=0;$i<count($ourteam_list);$i++){
  27. $ourteam_list[$i]['add_time'] = date("Y-m-d h:i:s",$ourteam_list[$i]['add_time']);
  28. $ourteam_list[$i]['update_time'] = date("Y-m-d h:i:s",$ourteam_list[$i]['update_time']);
  29. }
  30. $allpower = $this->qxhans();
  31. $this->assign('allpower',$allpower);
  32. $this->assign('ourteam_list', $ourteam_list);
  33. $this->assign('show_page', $model_ourteam->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. 'info' => input('post.info'),
  49. 'add_time' => time(),
  50. 'update_time' => time(),
  51. );
  52. $imgurl = DS_THEME_STYLE_URL . 'images/team';
  53. $numurl = '/static/home/images/team';
  54. $file = request()->file('image');
  55. if($file){
  56. $imgname = time().'.jpg';
  57. $file = $file->setSaveName($imgname);//设置保存文件名
  58. $imgo = $file->move($imgurl, $savename = $imgname, $replace = true);
  59. if($imgo){
  60. $data['img_url'] =$numurl.'/'.$imgname;
  61. }
  62. }
  63. $result = model('OurTeam')->add($data);
  64. if ($result){
  65. $this->success(lang('add_succ'), url('OurTeam/index'));
  66. }
  67. $this->error(lang('add_fail'));
  68. } else {
  69. $this->setAdminCurItem('add');
  70. return $this->fetch('form');
  71. }
  72. }
  73. /**
  74. * 修改我们的团队
  75. * @return mixed
  76. */
  77. public function edit()
  78. {
  79. $allpower = $this->qxhans();
  80. $this->assign('allpower',$allpower);
  81. $id = input('param.id');
  82. if ($id <= 0) {
  83. $this->error('系统错误');
  84. }
  85. $condition['id'] = $id;
  86. if (request()->isPost()) {
  87. $data = array(
  88. 'name' => input('post.name'),
  89. 'info' => input('post.info'),
  90. 'update_time' => time(),
  91. );
  92. $imgurl = DS_THEME_STYLE_URL . 'images/team';
  93. $numurl = '/static/home/images/team';
  94. $file = request()->file('image');
  95. if($file){
  96. $imgname = time().'.jpg';
  97. $file = $file->setSaveName($imgname);//设置保存文件名
  98. $imgo = $file->move($imgurl, $savename = $imgname, $replace = true);
  99. if($imgo){
  100. $data['img_url'] =$numurl.'/'.$imgname;
  101. }
  102. }
  103. $result = model('OurTeam')->edit(['id' => $id], $data);
  104. if ($result >= 0) {
  105. $this->success(lang('edit_succ'), 'OurTeam/index');
  106. } else {
  107. $this->error(lang('edit_fail'));
  108. }
  109. } else {
  110. $ourteam = model('OurTeam')->getOneOurteam(['id' => $id]);
  111. $this->assign('ourteam', $ourteam);
  112. $this->setAdminCurItem('edit');
  113. return $this->fetch('form');
  114. }
  115. }
  116. /**
  117. * 删除团队
  118. * @return mixed
  119. */
  120. function del()
  121. {
  122. $id = intval(input('param.id'));
  123. if ($id) {
  124. $condition['id'] = $id;
  125. $result = model('OurTeam')->deleteOurTeam($condition);
  126. if ($result) {
  127. ds_json_encode(10000, lang('del_succ'));
  128. } else {
  129. ds_json_encode(10001, lang('del_fail'));
  130. }
  131. } else {
  132. ds_json_encode(10001, lang('param_error'));
  133. }
  134. }
  135. }