コード例 #1
0
 /**
  * @description 批量删除产品分类
  * @author
  * @final
  * @param array $ids 产品分类id
  */
 public function batch_delete()
 {
     if (!$this->check_power_new('production_category_batch_delete')) {
         return;
     }
     $ids = $this->input->post('ids');
     if (empty($ids) or !is_array($ids)) {
         message('请选择要删除的项目!');
         return;
     }
     // 检查被关联试题
     $success = $fail = 0;
     foreach ($ids as $id) {
         $pc_id = intval($id);
         $bool = true;
         $pc_ids = CommonModel::get_product_category($pc_id);
         if (empty($pc_ids)) {
             $bool = false;
         }
         $query = array();
         $data = array();
         $query['pc_id'] = $pc_id;
         $res = CommonModel::get_list($query, 'v_trans_log', 'count(pt_id) as pt_id_count');
         $pt_id_count = $res[0]['pt_id_count'];
         if ($pt_id_count > 0) {
             $bool = false;
         }
         if (!$bool) {
             $fail++;
             continue;
         }
         $num = Fn::db()->delete('rd_product_category', "pc_id={$pc_id}");
         admin_log('delete', 'product_category', $pc_id);
         if ($num > 0) {
             $success += $num;
         } else {
             $fail++;
         }
     }
     message('批量操作完成,成功删除:' . $success . ' 个,失败:' . $fail . ' 个。', 'javascript');
 }