mb_home.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * 合作伙伴管理
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class mb_homeControl extends SystemControl{
  11. public function __construct(){
  12. parent::__construct();
  13. Language::read('mobile');
  14. }
  15. /**
  16. * 列表
  17. */
  18. public function mb_home_listOp(){
  19. $model = Model('mb_home');
  20. $h_list = $model->getMbHomeList(array());
  21. Tpl::output('h_list',$h_list);
  22. //商品分类
  23. $goods_class = ($nav = F('goods_class'))? $nav :H('goods_class',true,'file');
  24. Tpl::output('goods_class',$goods_class);
  25. Tpl::showpage('mb_home.list');
  26. }
  27. /**
  28. * 编辑
  29. */
  30. public function mb_home_editOp(){
  31. $model = Model('mb_home');
  32. if ($_POST['form_submit'] == 'ok'){
  33. //验证
  34. $obj_validate = new Validator();
  35. $obj_validate->validateparam = array(
  36. array("input"=>$_POST["h_title"], "require"=>"true", "message"=>L('home_add_null')),
  37. array("input"=>$_POST["h_desc"], "require"=>"true", "message"=>L('home_add_null')),
  38. array("input"=>$_POST["h_keyword"], "require"=>"true", "message"=>L('home_add_null')),
  39. array("input"=>$_POST["h_sort"], "require"=>"true", 'validator'=>'Number', "message"=>L('home_add_sort_int')),
  40. );
  41. $error = $obj_validate->validate();
  42. if ($error != ''){
  43. showMessage($error);
  44. }else {
  45. $home_array = $model->getMbHomeInfoByID(intval($_POST['h_id']));
  46. //上传图片
  47. if ($_FILES['h_img']['name'] != ''){
  48. $upload = new UploadFile();
  49. $upload->set('default_dir',ATTACH_MOBILE.'/home');
  50. $result = $upload->upfile('h_img');
  51. if ($result){
  52. $_POST['h_img'] = $upload->file_name;
  53. }else {
  54. showMessage($upload->error);
  55. }
  56. }
  57. $update_array = array();
  58. $update_array['h_title'] = trim($_POST['h_title']);
  59. $update_array['h_desc'] = trim($_POST['h_desc']);
  60. $update_array['h_keyword'] = trim($_POST['h_keyword']);
  61. if(!empty($_POST['h_multi_keyword'])) {
  62. $update_array['h_multi_keyword'] = $_POST['h_multi_keyword'];
  63. }
  64. if ($_POST['h_img']){
  65. $update_array['h_img'] = $_POST['h_img'];
  66. }
  67. $update_array['h_sort'] = trim($_POST['h_sort']);
  68. $condition = array();
  69. $condition['h_id'] = intval($_POST['h_id']);
  70. $result = $model->editMbHome($update_array, $condition);
  71. if ($result){
  72. //除图片
  73. if (!empty($_POST['h_img']) && !empty($home_array['h_img'])){
  74. @unlink(BASE_ROOT_PATH.DS.DIR_UPLOAD.DS.ATTACH_MOBILE.'/home'.DS.$home_array['h_img']);
  75. }
  76. showMessage(L('home_edit_succ'),'index.php?act=mb_home&op=mb_home_list');
  77. }else {
  78. showMessage(L('home_edit_fail'));
  79. }
  80. }
  81. }
  82. $home_array = $model->getMbHomeInfoByID(intval($_GET['h_id']));
  83. if (empty($home_array)){
  84. showMessage(L('wrong_argument'));
  85. }
  86. Tpl::output('home_array',$home_array);
  87. Tpl::showpage('mb_home.edit');
  88. }
  89. /**
  90. * ajax操作
  91. */
  92. public function ajaxOp(){
  93. switch ($_GET['branch']){
  94. //排序
  95. case 'h_sort':
  96. $model_link = Model('mb_home');
  97. $update_array = array();
  98. $update_array[$_GET['column']] = trim($_GET['value']);
  99. $condition = array();
  100. $condition['h_id'] = intval($_GET['id']);
  101. $result = $model_link->editMbHome($update_array, $condition);
  102. echo 'true';exit;
  103. break;
  104. }
  105. }
  106. }