コード例 #1
0
ファイル: cate.php プロジェクト: lughong/shop
 public function modify($cate_id)
 {
     $msg = array();
     if (!$cate_id) {
         $msg['error'] = '-1';
         $msg['msg'] = '不存在该分类';
         echo json_encode($msg);
         throw new Exception('exit');
     }
     $cate_status = isset($_POST['cate_status']) ? htmlspecialchars($_POST['cate_status']) : 'no';
     //查询信息
     $cate_info = CateM::getCateInfoByCateId($cate_id);
     if ($cate_info) {
         if ($cate_info['cate_status'] == $cate_status) {
             $msg['error'] = '0';
             $msg['msg'] = '修改失败,状态没发生改变';
             echo json_encode($msg);
         } else {
             $data = array();
             $where = array();
             $where['cate_id'] = $cate_id;
             $data['cate_status'] = $cate_status;
             CateM::update($data, $where);
             //获取全部分类
             $cate_list = CateM::getAllCate();
             //获取有序的子孙图
             $cate_list = CateM::getSonTree($cate_list, $cate_id);
             if (!empty($cate_list)) {
                 //把子孙都修改状态
                 foreach ($cate_list as $key => $val) {
                     $data = array();
                     $where = array();
                     $where['fid'] = $cate_id;
                     $where['cate_id'] = $val['cate_id'];
                     $data['cate_status'] = $cate_status;
                     CateM::update($data, $where);
                 }
             }
             $msg['error'] = '1';
             $msg['msg'] = '修改成功';
             echo json_encode($msg);
         }
     } else {
         $msg['error'] = '-3';
         $msg['msg'] = '修改失败,不存在该分类';
         echo json_encode($msg);
     }
     throw new Exception('exit');
 }